i am creating a strategy that receives a signal from HalfTrind indicator to buy or sell
when i receive a signal, i check if there is any other position is open, then i close it and open the new one.
currently, when i try to open a new order, i got this error message
Buy stop or buy stop limit orders can't be placed below the market. affected order: BuyToCover 1 stopMarket @1234.00
i debug the code, and this was the value when i get the erro
Short High[0]: 4138.25 currentATR: 3.0280371924987 newStop: 4141.2780371925 _stop: 4141.2780371925
if (Position.MarketPosition == MarketPosition.Flat)
{
EnterShort("ShortOrder");
var newStop = High[0] + currentATR;
_shortStop = _shortStop == 0 ? newStop : _shortStop;
_shortStop = Math.Min(_shortStop, newStop);
Print("3 " + ShortOrder + " High[0]: " + High[0] + " currentATR: " + currentATR + " newStop: " + newStop + " _stop: " + _shortStop);
ExitShortStopMarket(_shortStop, "Trail Short", ShortOrder);
//SetStopLoss(CalculationMode.Price, _shortStop);
}
else if (Position.MarketPosition == MarketPosition.Long)
{
ExitLong("LongOrder");
if (Low[0] < Position.AveragePrice)
{
EnterShort("ShortOrder");
var newStop = High[0] + currentATR;
_shortStop = _shortStop == 0 ? newStop : _shortStop;
_shortStop = Math.Min(_shortStop, newStop);
Print("4 " + ShortOrder + " High[0]: " + High[0] + " currentATR: " + currentATR + " newStop: " + newStop + " _stop: " + _shortStop);
ExitShortStopMarket(_shortStop, "Trail Short", ShortOrder);
//SetStopLoss(CalculationMode.Price, _shortStop);
}
}
Thanks

Comment