using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
if( Bars.IsIntraday )
{
SetScaleDaily();
var dailyClose = Bars.Close;
var limitPrice = dailyClose - 0.60;
RestoreScale();
dailyClose = Synchronize(dailyClose);
limitPrice = Synchronize(limitPrice);
PlotSeries(PricePane,limitPrice,Color.Maroon,WealthLab.LineStyle.Solid,1,"Previous day's close - $0.60");
int todayClose = 1600;
int nextToLastBarTime = AddIntegerTime( todayClose, -Bars.BarInterval );
var okToReenter = true;
for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
Position p = LastPosition;
double amount = p.MFEAsOfBar(bar) / p.Shares + p.EntryPrice - 0.20;
if( (GetTime(bar) >= nextToLastBarTime) )
if( SellAtMarket(bar+1, p, "EOD") )
okToReenter = true;
if( SellAtTrailingStop(bar+1, p, amount, "Trailing exit") )
okToReenter = false;
}
else
{
if( Date[bar].Date > Date[bar-1].Date )
okToReenter = true;
if( !Bars.IsLastBarOfDay(bar) && okToReenter )
if( BuyAtLimit(bar+1,limitPrice[bar]) != null )
okToReenter = false;
}
}
}
else
DrawLabel(PricePane, "Switch to intraday data");
}
public int GetTime(int bar)
{
return Date[bar].Hour * 100 + Date[bar].Minute;
}
public int AddIntegerTime( int t, int minutes )
{
int res = 60 * ( t / 100 ) + ( t % 100 ); // minutes past midnight
int res1 = res + minutes;
res1 = res1 / 60 * 100 + ( res1 % 60 );
if( res1 >= 2400 )
return (res1 % 2400 );
else if( res1 < 0 )
return AddIntegerTime( AddIntegerTime( 2400, minutes ), res );
else
return res1;
}
}
}
No comments:
Post a Comment