• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current price < Previous bar's low = exit position

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

    Current price < Previous bar's low = exit position

    Good day.

    This is my first time visiting this forum, and my first time posting. I'm really sorry if I didn't take the time to look for similar threads since my problem seems really common. It might not be a valid reason, but my head already hurts from trying to figure out this simple problem.

    How do I make a ninja script strategy that exits all position when the current price is lower than the previous bar's low?

    I would have easily done this, but simply using the strategy wizard, and put: close < low(1) or low < low(1) or ask < low(1) or bid < low(1), then put an exit long or exit short -doesn't seem to work. I'm totally not into scripting, though I was able to manually modify a script after unlocking the code from the wizard, I'm still a dummy with scripts.

    I hope anyone can help me. Thank you so much.
    Last edited by Jebelle; 01-22-2012, 03:37 AM. Reason: typo

    #2
    Jebelle,

    I am happy to assist you.

    This is dependent upon the way you enter orders, i.e. how many, the signal names, etc. If you could post your strategy I would be happy to explain it a little more in depth.

    There is a reference sample on this : http://www.ninjatrader.com/support/f...ad.php?t=18890

    I look forward to helping you resolve your issue.
    Last edited by NinjaTrader_AdamP; 01-22-2012, 07:47 PM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the support and the fast response.

      Talk about signal names, there's a lot in that strategy I made. I can't come up with any other method so please bare with me.

      There was another thing which I can't solve. I hope you don't mind if I ask another question. I thought of putting a profit target of "x" pips/dollars per day, where, if the 1st trade didn't reach all of it, the next trade would go for the remaining. If there was a loss, the next trade would go for the remaining + the loss. And no more positions would be entered when that target is reached.

      I thought of putting the Realized PnL < target on each set of condition which enters a position, so it would only enter a position when the target isn't reached yet. It worked. But I was never successful with the former

      Thank you.
      Attached Files

      Comment


        #4
        Jebelle,

        One way to make this strategy exit when Close[0] < Low[1] is to use your conditions :

        Code:
        if (ToTime(Time[0]) == ToTime(23, 30, 0))
        {
                        ExitLong("EXIT", "62");
                        ExitShort("EXIT", "62");
        }
        And change to :

        Code:
        if (ToTime(Time[0]) == ToTime(23, 30, 0)  ||  Close[0] < Low[1])
        {
                        ExitLong("EXIT", "62");
                        ExitShort("EXIT", "62");
        }
        As far as your second question, this is definitely possible. You would need to keep track of realized profit in pips. You can use OnExecution() to track when orders are executed and then update your realized PnL calculation.

        For more information, please see the following link :

        http://www.ninjatrader.com/support/h...nexecution.htm

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thank you, but it doesn't work. I tried it on that strategy, and a new strategy, both on calculate on bar close - true and false, yet it's not working. I doubt it, but I hope I'm not doing anything wrong. Is there any other way to exit when the current price is lower than the previous bar's low?

          Comment


            #6
            Jebelle,

            Are you making sure the "62", etc. is being reset appropriately for each segment?

            ExitLong("EXIT", "62"); <----- 62 is the entrance signal name
            ExitShort("EXIT", "62"); <------ 62 is the entrance signal name

            There is no other way that doesn't use an incredibly similar method to exit when close is less than the previous low.

            I would suggest posting your code again and I can take a look.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Please do.
              Attached Files

              Comment


                #8
                Jebelle,

                It looks like its working as expected. Please see the attached screenshot.

                I just attached it to a chart by right clicking the chart > going to strategies.

                Please let me know if I may assist further.
                Attached Files
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  The strategy did work, but not as I expected it - exit when current price is lower than previous bar's low. I also made that strategy to exit every 15 minutes, like every end/start of bar, so I don't quite understand how the strategy worked on your chart.

                  I attached a picture on how it works on my PC. The strategy works but not as how I'm expecting it to. I think I'm missing something. I'm going to study this more for now. I also found an idea from that chart you showed me.

                  It's hard being a newbie. I'm really sorry for giving you such trouble Adam. This would be all.

                  Thank you so much.
                  Attached Files

                  Comment


                    #10
                    Originally posted by Jebelle View Post
                    The strategy did work, but not as I expected it - exit when current price is lower than previous bar's low. I also made that strategy to exit every 15 minutes, like every end/start of bar, so I don't quite understand how the strategy worked on your chart.

                    I attached a picture on how it works on my PC. The strategy works but not as how I'm expecting it to. I think I'm missing something. I'm going to study this more for now. I also found an idea from that chart you showed me.

                    It's hard being a newbie. I'm really sorry for giving you such trouble Adam. This would be all.

                    Thank you so much.
                    Is your picture from a Backtest or from live trading?

                    Comment


                      #11
                      Jebelle, the question if this was generated by backtesting or realtime / market replay testing would be very important - in backtesting you would move from left to right bar - by - bar, so the test knows only the OHLCV info of each bar, it could not look inside a bar here. So the first time your condition becomes true in backtesting is when the bar that breached the previous bar low is true and then the code exits, all working ok from what I can see. If you tested realtime / market replay with CalculateOnBarClose set to 'false' you exit on the first tick that triggered your exit conditon.

                      http://www.ninjatrader.com/support/h...onbarclose.htm
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Yes it was generated from a backtest. Can't go live yet.

                        I see, so it was impossible for the trade to exit exactly when the "current" price is lower than the previous bar's low- in a backtest. Sorry for not knowing about the part that backtesting only knows the OHLCV of each bar. Which is why it never worked the way I was expecting it to. If I went live then, would it surely exit the moment it passes the the previous bar's low? Like where I pointed it out on the picture? And if I do use this strategy, will it really be too heavy for the computer? Cause it's necessary for me to set CalculateOnBarClose to false right...

                        Comment


                          #13
                          Hi Jebelle,

                          Yes, exactly. A real time strategy with CalcualteOnBarClose = false will be evaluated with every tick. If the conditions for your order are true, then it's submitted right away without waiting for the bar to complete.
                          Ryan MNinjaTrader Customer Service

                          Comment


                            #14
                            Finally. Thank you. I'm so glad to know that.

                            Thanks to Koganam for bringing up the question. Thank you so much to Adam P, to Bertrand, and to RyanM.

                            Comment


                              #15
                              Progress is good, and we're happy you're making it. Please let us know if you have any additional questions.
                              Ryan MNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Steve L, Today, 05:01 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Steve L
                              by Steve L
                               
                              Started by Trader-Joe, Today, 04:06 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by vantojo, Today, 04:06 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post vantojo
                              by vantojo
                               
                              Started by tonynt, Today, 02:39 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post tonynt
                              by tonynt
                               
                              Started by StevenNelson, Today, 12:23 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_PatrickG  
                              Working...
                              X