Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting trades

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

    Exiting trades

    I am wondering if it is possible to enter a trade as a result of a series of conditions and then exit the trade as a result of a set of conditions, with a SetStopLoss placed initially to protect the trade?
    I have in the Initialize section:

    SetStopLoss("Short", CalculationMode.Ticks, 10, false);

    In the OnBar Update section after the Condition set:

    { EnterShort(DefaultQuantity, "Short");
    if CrossBelow(xxx(8, 14, 0), 90, 1) ExitShort("")
    }

    I am wanting to exit the short when the line indicator crosses from high to low the line value of 90. (The indicator ranges from 0-100 vertically)
    The exit trigger is not working.
    Regards

    #2
    vast524, yes you can have a stoploss working and then exiting the position by other signals, if this happens the stop loss is cancelled. Perhaps it would be good to add a drawing on your exit condition to doublecheck it triggers as you would expect.

    Comment


      #3
      Unfortunately the trigger for the exit is not working.
      The trade ends up exiting as a result of the stop rather than the target
      I thought that I had written the conditions incorrectly.
      I am running trace orders and print. But it doesn't explain why the trigger to sell was not met once the condition was met.
      Regards

      Comment


        #4
        vast524, then it seems you would need to debug your condition to ExitShort - easiest is to add drawing an arrow or dot so you can visually see if the order should get triggered or not.

        Comment


          #5
          Thanks.
          Have done that. Some times it prints the arrows, yet does not exit the trade.
          Is it possible to enter with a SetStopLoss and then exit either by that filling or a conditional exit filling?

          Comment


            #6
            Hi there, you may want to try matching your signal names.

            In the little snippet you posted,
            Code:
            {
                 EnterShort(DefaultQuantity, "Short");     
                 if CrossBelow(xxx(8, 14, 0), 90, 1)
                       ExitShort("")
            }
            the entry name is "Short", but the ExitShort("") specifies a blank from entry signal. You can try matching these up and see if that makes a difference.

            Maybe something like:
            Code:
            EnterShort(DefaultQuantity, "Short entry");
            ExitShort("Short entry");
            AustinNinjaTrader Customer Service

            Comment


              #7
              I had done this in the real code. Had accidentally ommitted it when pasting it in the in chat.
              EnterLong(DefaultQuantity, "Long");
              if (jWilliams2(8, 14, 0)[0] <= jWilliams2(8, 14, 0)[3])
              DrawVerticalLine("tag1"+CurrentBar,0,Color.Blue,Da shStyle.Dot,3);
              ExitLong("Long");

              Comment


                #8
                Vast, are you including everything you want executed in brackets? If you just have one command after an if-statment, you don't need brackets. If there are more commands, brackets would be needed, like this:
                Code:
                if (jWilliams2(8, 14, 0)[0] <= jWilliams2(8, 14, 0)[3])
                {
                     DrawVerticalLine("tag1"+CurrentBar,0,Color.Blue,DashStyle.Dot,3);
                     ExitLong("Long");
                }
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  This is what I have:

                  {
                  Print("condition set 1 being executed...");

                  EnterLong(DefaultQuantity, "Long");

                  if (jWilliams2(8, 14, 0)[0] <= jWilliams2(8, 14, 0)[3])
                  DrawVerticalLine("tag1"+CurrentBar,0,Color.Blue,Da shStyle.Dot,3);
                  ExitLong("Long");

                  }

                  Comment


                    #10
                    Vast, the code you posted reads like this:
                    • EnterLong()
                    • if(jWilliams stuff is true) then draw vertical line
                    • ExitLong() - this is seperate from the if(jWilliams) stuff because it isn't enclosed with brackets.
                    keep in mind the above only happens if the conditions for set 1 are true.

                    Brackets are very important, and you need to pay special attention to where the brackets are located, and what the brackets enclose.

                    Now I'm not sure exactly what you're looking to do in your strategy, but maybe try this and see if you get the expected results:
                    Code:
                    {
                         Print("condition set 1 being executed...");
                    
                         EnterLong(DefaultQuantity, "Long");
                    
                         if (jWilliams2(8, 14, 0)[0] <= jWilliams2(8, 14, 0)[3])
                             {
                                DrawVerticalLine("tag1"+CurrentBar,0,Color.Blue,DashStyle.Dot,3);
                                ExitLong("Long");
                             }
                    }
                    Keep in mind if all the above is true, NinjaTrader will enter long and exit long immediately after--thus paying the spread and commissions and leaving you with a flat position.

                    If you post the full code we could see what you're trying to do and be able to help you better.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      You are correct with the flatten straight away. I am wanting to enter the trade and stay in it till the trend expires. Once the JWilliams starts to tren down it exits the trade.
                      So it seems that I have not placed the {} in the correct place. Do I need to separate the Enter and Exit conditions ie. They are not enclosed in the same set of {}

                      This is the Set1:
                      // Condition set 1
                      if (CrossBelow(xxx(30, 5, 30).Signal, xxx(30, 5, 30).Main, 3)
                      && Rising(jWilliams2(6, 10, 0)) == true
                      && jWilliams2(6, 10, 0)[0] <= 50
                      && yyy(3, 14, 3).K[0] < 40)
                      {
                      Print("condition set 1 being executed...");


                      EnterLong(DefaultQuantity, "JW Long");
                      if (jWilliams2(8, 14, 0)[0] <= jWilliams2(8, 14, 0)[3])
                      DrawVerticalLine("tag1"+CurrentBar,0,Color.Blue,Da shStyle.Dot,3);
                      ExitLong("JW Long");

                      }

                      Comment


                        #12
                        Yes, please separate the entry and the exit.

                        if (my conditions A)
                        {
                        then enter
                        }

                        if (my conditions B)
                        {
                        then exit
                        }

                        Comment


                          #13
                          VAST524,

                          The jwilliams2 indicator has worked well for me. However, I am not a programmer, but I am interested in the additional coding work that you have done on this indicator.

                          Would you mind sharing a chart or two?

                          Thank you,

                          GarryM

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          647 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          368 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          108 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          571 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          573 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X