New ninja dev here. I'm having some issues with what should be very basic functionality. First, I'd like to be able to move my stop to either break even or profit after going into profit by x number of ticks. Second, I'd like to plot the stop loss. The code I'm using is as follows in the onBarUpdate() method.
if (Position.MarketPosition == MarketPosition.Short) { OrderCoord = Math.Round(Position.AveragePrice - (LongStopTicks * TickSize),2); Draw.Line(this, "LPT-"+CurrentBar, true, CurrentBar - OrderSBar, OrderCoord, -1, OrderCoord, Brushes.Red, DashStyleHelper.Solid, 1); Print("Short stop loss should be " + OrderCoord); } else if (Position.MarketPosition == MarketPosition.Long) { OrderLCoord = Math.Round(Position.AveragePrice - (LongStopTicks * TickSize),2); Print("Long stop loss should be " + OrderLCoord); Draw.Line(this, "LPT-"+CurrentBar, true, CurrentBar - OrderLBar, OrderLCoord, -1, OrderLCoord, Brushes.Red, DashStyleHelper.Solid, 1); } if (Position.MarketPosition == MarketPosition.Long) if (Close[0] >= Position.AveragePrice + BreakEvenAfter * TickSize) // BreakEvenAfter is set to 10 ExitLongStopMarket(Position.Quantity, Position.AveragePrice); OrderLCoord = Position.AveragePrice; if (Position.MarketPosition == MarketPosition.Short) if (Close[0] <= Position.AveragePrice - BreakEvenAfter * TickSize) ExitShortStopMarket(Position.Quantity, Position.AveragePrice); OrderCoord = Position.AveragePrice;
As you can see from the screenshot above, the stop is not being moved to BE after going 10 ticks into profit and the stop loss is never in the correct spot.
Thanks.
Comment