Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Take Profit condition not executed

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

    Take Profit condition not executed

    Hello everyone

    I developed a strategy with signals "LONG" and "SHORT".

    I want to take profit if the system is long and it's making money but the last two bars closed lower.

    I wrote the following code, which is not working:

    // Condition set Long Take Profit
    if (Close[0] > (Position.AvgPrice)
    && Position.MarketPosition == MarketPosition.Long
    && Close[0] < Close[1]
    && Close[1] < Close[2])


    {
    ExitLong("TAKEPROFIT", " LONG");
    }

    Why it doesn't work?

    Thank you

    #2
    Likely the conditions are not being met?

    In any case, you will have to debug this to determine what is happening. You have likely seen this before but I am posting this link in case you have not.

    RayNinjaTrader Customer Service

    Comment


      #3
      The conditions are met many times (I could see it on the charts), so I was wondering if the code was wrong.

      Originally posted by NinjaTrader_Ray View Post
      Likely the conditions are not being met?

      In any case, you will have to debug this to determine what is happening. You have likely seen this before but I am posting this link in case you have not.

      http://www.ninjatrader-support.com/v...ead.php?t=3418

      Comment


        #4
        Enable TraceOrders and see what the output window tells you about this order.
        RayNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 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