Announcement

Collapse
No announcement yet.

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.

    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.

        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.

            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 Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X