Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why Doesn't This Work?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Why Doesn't This Work?

    I can't seem to make what seems to be a logical construct actually work. I am trying to move a stop to breakeven after a certain amount of unrealized profit has been achieved. That level of profit is contained in the double variable "BE_Move". Prior to moving the stop to a breakeven price level, the stop was a tick based stop whose value was defined by the variable "stop", and implemented in a command in the initialize section of the code. Also when flat, the stop is re-initialized to the original tick-based stop.

    When I test this, I never see a trade which closes at a small stop loss meaning the BE Move threshold was achieved, the stop was moved to BE, and price eventually bounced back to the BE price level.

    I must be missing something obvious, I just can't see what it is.

    Thanks for your help.

    DaveN



    Code:
    			if (Position.MarketPosition != MarketPosition.Flat)
    					{
    					if (Position.MarketPosition == MarketPosition.Long
    						&& Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > BE_Move)
    						{
    						SetStopLoss("GM_LL", CalculationMode.Price, Position.AvgPrice, false);
    //						DrawText("BarCount" + CurrentBar, BarsSinceEntry().ToString(), 0, Low[0] - 15 * TickSize, Color.Cyan);
    						}
    					else if (Position.MarketPosition == MarketPosition.Short
    						&& Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > BE_Move)
    						{
    						SetStopLoss("GM_LS", CalculationMode.Price, Position.AvgPrice, false);
    //						DrawText("BarCount" + CurrentBar, BarsSinceEntry().ToString(), 0, High[0] + 15 * TickSize, Color.Magenta);
    						}
    					}

    #2
    Hi DaveN,

    Thanks for your post.

    I think you should add TraceOrders = true; to the Initialize() method. This will print when the SetStopLoss is called so that you can see that the stop has been moved.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    23 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    115 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    222 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    406 views
    0 likes
    Last Post CaptainJack  
    Working...
    X