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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    144 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    71 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    125 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X