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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    65 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    41 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    23 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    26 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    52 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X