I'm still trying understand why I received such error " An order has been ignored since the stop price ‘3979.75’ near the bar stamped ‘16.11.2022 18:48:06’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored." for ES instrument.
Look at the log:
ESOpenV3 is ONLINE 16.11.2022 18:30:30
ESOpenV3 is ONLINE 16.11.2022 18:30:30
Time[0].Date 16.11.2022 0:00:00
Time[0] 16.11.2022 18:30:30
HighO 3984,5
LowO 3980,25
RangeO 4,25
TargetProfit 18,0625
StopLong 3979,75
StopShort 3985
ESOpenV3
Long !!
CurrentBar 12147
SignalBar 12147
16.11.2022 18:30:44
-----------------------------
GetCurrentBid()3985,25
GetCurrentAsk()3985,25
StopLong3979,75
ESOpenV3 [ES]
[ES] Long 3985
16.11.2022 18:30:44
-----------------------------
GetCurrentBid()3980,25
GetCurrentAsk()3980,25
StopLong3979,75
ESOpenV3 [ES]
[ES] Long 3985
16.11.2022 18:48:06
-----------------------------
GetCurrentBid()3980,25
GetCurrentAsk()3980,25
StopLong3979,75
Strategy 'ESOpenV3/-1': An order has been ignored since the stop price ‘3979.75’ near the bar stamped ‘16.11.2022 18:48:06’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
ESOpenV3 [ES]
[ES] Long 3985
16.11.2022 18:48:06
My code:
OnBarUpdate:
if (Position.MarketPosition == MarketPosition.Flat) {
if (PositionAccount.Quantity == 0) {
SignalBar = 0;
if (Signal_Long && count == 0) {
EnterLong (0, ContractQty, "entry");
SignalBar = CurrentBar;
Print (this.Name);
Print ("Long !!");
Print ("CurrentBar " + CurrentBar);
Print ("SignalBar " + SignalBar);
Print (Time[0].ToString ());
Print ("-----------------------------");
BackBrush = Brushes.Green;
BarBrush = Brushes.White;
count += 1;
}
else if (Signal_Short && count == 0) {
EnterShort (0, ContractQty, "entry");
SignalBar = CurrentBar;
Print (this.Name);
Print ("Short !!");
Print ("CurrentBar " + CurrentBar);
Print ("SignalBar " + SignalBar);
Print (Time[0].ToString ());
Print ("-----------------------------");
BackBrush = Brushes.Red;
BarBrush = Brushes.White;
count += 1;
}
}
}
OnPositionUpdate:
if (Position.MarketPosition == MarketPosition.Long) {
// +------------------------------------------------------------+
// | Set Long Target and Stop loss |
// +------------------------------------------------------------+
var target = Position.AveragePrice + TargetProfit;
Print("GetCurrentBid()" + GetCurrentBid());
Print("GetCurrentAsk()" + GetCurrentAsk());
Print("StopLong" + StopLong);
ExitLongStopMarket (0, true, 1, StopLong, "initialStop", "entry");
Print (this.Name + " [" + instrument + "]");
Print ("[" + instrument + "] Long " + Position.AveragePrice);
Print (Time[0].ToString ());
Print ("-----------------------------");
Dot stopDot = Draw.Dot (this, "initialStop" + CurrentBar, true, 0, StopLong, Brushes.WhiteSmoke);
// +------------------------------------------------------------+
// | Set TakeProfit |
// +------------------------------------------------------------+
ExitLongLimit (0, true, 1, target, "exit", "entry");
Square targetSquare = Draw.Square (this, "initialTarget" + CurrentBar, true, 0, target, Brushes.White);
}
if (Position.MarketPosition == MarketPosition.Short) {
// +------------------------------------------------------------+
// | Set Short Target and Stop loss |
// +------------------------------------------------------------+
var target = Position.AveragePrice - TargetProfit;
ExitShortStopMarket (0, true, 1, StopShort, "initialStop", "entry");
Print (this.Name + " [" + instrument + "]");
Print ("[" + instrument + "] Short " + Position.AveragePrice);
Print (Time[0].ToString ());
Print ("-----------------------------");
Dot stopDot = Draw.Dot (this, "initialStop" + CurrentBar, true, 0, StopShort, Brushes.WhiteSmoke);
// +------------------------------------------------------------+
// | Set TakeProfit |
// +------------------------------------------------------------+
ExitShortLimit (0, true, 1, target, "exit", "entry");
Square targetSquare = Draw.Square (this, "initialTarget" + CurrentBar, true, 0, target, Brushes.White);
}
}

Comment