Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong with parameters gives error

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

    ExitLong with parameters gives error

    Hello,

    When I put this code to exit trades:

    if (CrossBelow(Close, SMA(Close, Mab), 1))
    ExitLong(Qty, "R2S_XLM_MA", "R2S_ELS_Strong Uptrend");
    ExitLong(Qty, "R2S_XLM_MA", "R2S_ELM_Strong Uptrend");
    Where "R2S_XLM_MA" is Exit name, and "R2S_ELS_Strong Uptrend" is entry name.

    It gives me an error while backtesting. However, if I only put it like this:
    if (CrossBelow(Close, SMA(Close, Mab), 1))
    ExitLong();
    It works. What I mean by "works" and "doesn't work". I am trying to test a boolean to enter 1) EnterLong or 2) EnterLongStopMarket. So I have original variation of strategy, which uses only EnterLong option, and when I run optimization, my edited strategy should post 2 results, when running optimization on StopMarketEntry (custom boolean) - 1) If False, it should return the exact results of original strategy, which uses EnterLong, 2) If True - it should return results, if EnterLongStopMarket is used.

    I could leave only 1 ExitLong line, but doing this I would lose Exit name and I don't want to do it. And the 2nd line of ExitLong with parameters differentiates with only one letter, but it defines, whether it was StopMarket (S) or Market (M) order initially.

    #2
    Hello UltraNIX,

    Thank you for your note.

    What is the error you receive during your backtesting? Please include the full text of the error.

    Is this a strategy you've created using the Strategy Builder or manually coded in the NinjaScript Editor?

    If in the editor, are you using curly brackets to group both exits under the condition for exit like this?:


    if (CrossBelow(Close, SMA(Close, Mab), 1))
    {
    ExitLong(Qty, "R2S_XLM_MA", "R2S_ELS_Strong Uptrend");
    ExitLong(Qty, "R2S_XLM_MA", "R2S_ELM_Strong Uptrend");
    }

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Yes, thank you, those curly bracket solved the issue!

      Originally posted by NinjaTrader_Kate View Post
      Hello UltraNIX,

      Thank you for your note.

      What is the error you receive during your backtesting? Please include the full text of the error.

      Is this a strategy you've created using the Strategy Builder or manually coded in the NinjaScript Editor?

      If in the editor, are you using curly brackets to group both exits under the condition for exit like this?:


      if (CrossBelow(Close, SMA(Close, Mab), 1))
      {
      ExitLong(Qty, "R2S_XLM_MA", "R2S_ELS_Strong Uptrend");
      ExitLong(Qty, "R2S_XLM_MA", "R2S_ELM_Strong Uptrend");
      }

      Thanks in advance; I look forward to assisting you further.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X