All I want to do is: at 10am define the highest high of the last 8 bars and place a buy stop to enter at that price and define the lowest low of the last 8 bars and place a sell stop to enter at that low. I would like the orders to persist till 3pm then cancel.
Using the following code, either the Long Entry Stop works or the Short Entry Stop works but not both. Whichever EnterStop statement is second in the code, does not work. I've tried giving then unique string names but that has no effect.
What fundamental concept am I missing? Some hand holding would be appreciated
.thanks,
shawnj
public class BO : Strategy
{
private double _rangeHigh = Double.MaxValue;
private double _rangeLow = 0;
protected override void Initialize()
{
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
if( CurrentBar < 10 ) return;
//===Define breakout high and low prices.===
if( Time[0].TimeOfDay == DateTime.Parse("10:00").TimeOfDay )
{
_rangeHigh = High[ HighestBar(High, 8) ];
_rangeLow = Low[ LowestBar(Low, 8) ];
}
//===Place breakout orders each bar.===
if( (Time[0].TimeOfDay >= DateTime.Parse("10:00").TimeOfDay) && (Time[0].TimeOfDay <= DateTime.Parse("15:00").TimeOfDay) )
{
EnterLongStop(_rangeHigh + 1*TickSize);
EnterShortStop(_rangeLow - 1*TickSize); //Here the Short Entry Stop never fills.
//EnterShortStop(_rangeLow - 1*TickSize);
//EnterLongStop(_rangeHigh + 1*TickSize); //Here the Long Entry Stop never fills.
}
}
}

Comment