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 kevinenergy, 02-17-2023, 12:42 PM
    116 responses
    2,757 views
    1 like
    Last Post kevinenergy  
    Started by franatas, 12-04-2023, 03:43 AM
    7 responses
    106 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by jpapa, Today, 07:22 AM
    0 responses
    2 views
    0 likes
    Last Post jpapa
    by jpapa
     
    Started by Jltarrau, Today, 05:57 AM
    3 responses
    8 views
    0 likes
    Last Post Jltarrau  
    Started by f.saeidi, Today, 05:56 AM
    2 responses
    8 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X