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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    68 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    39 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X