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

Define Exit Name from a variable

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

    Define Exit Name from a variable

    Hello, I want to define Exit Nme from a variable, but there's an error somewhere.

    When I used fixed text, like: ExitLong(Qty, "ADX_XLM_Stop No New High", "ADX_ELS_Strong Uptrend");
    where "ADX_XLM_Stop No New High" is Exit Name and "ADX_ELS_Strong Uptrend" is Entry Name.

    However, if I change it to: ExitLong(Qty, NameXL, "ADX_ELS_Strong Uptrend"), it doesn't give me correct Exit name, and Exit name is "Close position"

    NameXLCond = (MAXLCond == true ? "MAEXit" : STickXLCond == true ? "StopTick" : "");
    NameXL = "ADX_XLM_" + NameXLCond

    Both of the latter values are defined as string.

    So, the result I want to achieve is this: If NameXLCond = "MAExit", then Exit name (from NameXL variable) should be "ADX_XLM_MAExit".

    How can this be done?

    #2
    Hello UltraNIX,

    Thanks for your post.

    The "Close Position" is a name provided to an exit when an Entry method in the opposite direction has placed an order. All entry methods will automatically issue a market order called "Close Position" if there is an open position in the opposite direction.

    The entry/exit methods should be able to handle a string variable.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello UltraNIX,

      Thanks for your post.

      The "Close Position" is a name provided to an exit when an Entry method in the opposite direction has placed an order. All entry methods will automatically issue a market order called "Close Position" if there is an open position in the opposite direction.

      The entry/exit methods should be able to handle a string variable.
      All trades had order names (i.e. not Close position, but some specific name), when I set those "manually", without variable. So maybe there is something wrong with the formula?

      Comment


        #4
        Hello UltraNIX,

        Thanks for your reply.

        You can debug this by printing out the code determined names.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Sad true is that Print gives correct answers, but this does not help getting correct Exit names values. Maybe syntax is incorrect?

          Comment


            #6
            Hello UltraNIX,

            Thanks for your reply.

            I've created a simple example along the lines of what you are working with:

            private int entryBar;

            protected override void OnBarUpdate()
            {
            if (CurrentBar < 20) return;

            if (Position.MarketPosition == MarketPosition.Flat && Close[0] > Open[0])
            {
            EnterLong("Test");
            entryBar = CurrentBar;
            }
            if (Position.MarketPosition == MarketPosition.Long)
            {
            if (CurrentBar - entryBar == 5)
            {
            string exitname = Close[0]>Open[0] ? "Upbar":"downBar";
            ExitLong(1,exitname,"Test");
            }
            }
            }

            Please advise if you see the same issue when you test with this example.

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Interestingly enough, it started working. When I created this topic, I edited code in multiple places, so not sure which part made it work, but now it works as it is supposed to, thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Working...
              X