Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    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 mmckinnm, Today, 01:34 PM
      3 responses
      5 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by f.saeidi, Today, 01:32 PM
      2 responses
      4 views
      0 likes
      Last Post f.saeidi  
      Started by alifarahani, 04-19-2024, 09:40 AM
      9 responses
      55 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Conceptzx, 10-11-2022, 06:38 AM
      3 responses
      60 views
      0 likes
      Last Post NinjaTrader_SeanH  
      Started by traderqz, Today, 12:06 AM
      9 responses
      16 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X