What i itend to do is:
today (Day 0) at 9:31: if Open on Day -1 > High on Day -2
and ((Open on Day -1 minus Close on Day -2)/ Close on Day -2) > 2%
then Enter Long Position at 09:32 on Day 0
and Exit Long Position at 15:00 on Day 0
My Code is the following:
public class XY : Strategy
{
#region Variables
private TimeSpan _StartTime = new TimeSpan(9,31,0);
private TimeSpan _ExitTime = new TimeSpan(15,0,0);
#endregion
protected override void Initialize()
{
Add(PeriodType.Day, 1);
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
if(Time[0].TimeOfDay == _StartTime
&& Opens[1][1]>Highs[1][2])
&& ((Opens[1][1]-Closes[1][2])/Closes[1][2])>0.02))
{
EnterLong(0, 1, "Long");
}
if(Time[0].TimeOfDay == _ExitTime)
{
ExitLong("Exit Long", "Long");
}
}
When i check the orders manually it shows that the condition of 2% change does not hold, but the Long Position is entered.
I have no clue where exactly the fault is.
Is my time structure totally wrong and i do not use the bars i itend to?
Any hint what to modify would be a big present.

Comment