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

CrossAbove()

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

    CrossAbove()

    Hello,

    I'm missing a concept. If I'm looking for a condition, for example where a Stochastic 'K' goes above 40. I understand that the first time 'K' crosses above 40, the CrossAbove() function will return true. My question is if the next bar still has the Stochastic 'K' calculated above 40, will CrossAbove(), when called in OnBarUpdate, still return a true or does it only do it for the first time that it crosses 40?

    Thank you,
    Ken

    #2
    Hello Ken,

    Thank you for your post.

    The CrossAbove() method will return true only if the cross above condition occurs within your lookBackPeriod. If the lookBackPeriod is set to 1 and the CrossAbove() was true on the previous bar and on the current bar (the next time OnBarUpdate() is called) the Stochastic 'K' is still above 40 then the CrossAbove() method would return as false as the cross above condition is not true within the lookBackPeriod.

    The lookBackPeriod is the key here as you could set the lookBackPeriod for more bars such as 2, which would return true on the current bar if CrossAbove() was true on the previous bar.

    For information on CrossAbove() please visit the following link: http://www.ninjatrader.com/support/h...crossabove.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Patrick,

      Thank you for the very clear and quick response!!!

      Best Wishes,
      Ken

      Comment


        #4
        multiple profit target or stoploss

        Hi,
        I want to divise my profit target/stoploss on small profit targets like I can do by the wizzard. I don't know how to do it by a script using limit orders because if I can't have positions in the two directions,

        Thank you in advance,
        R.E.

        Comment


          #5
          Hello R.E.

          First, I want to mention that within a single strategy on a single account and instrument would not be able to have positions in opposite directions.

          There is one position for the strategy.

          You can multiple trades into that position. Each trade can be separated by using signal names on the entry orders and matching from entry signals on the exit order.

          To set a profit target call SetProfitTarget anywhere in the code when you would like to set this.

          SetProfitTarget("entryOrderSignalName", CalculationMode.Ticks, 10);

          http://ninjatrader.com/support/helpG...ofittarget.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi Chelsea,
            Thank you for your answer and sorry for not, and sorry for using an old post. I thought it is a new one.

            My situation is for example that I buy a quantity of 100. Now I hit my first profit target, I want then to sell 50 contracts and when I will hit the second target to sell the 50 that remains. The stop loss have to be associated to the 100 contracts. I really don't know how to deal with that without divising my operation in two other ones and got two stop loss and two targets, but it seems more expensive regarding comissions.

            Thank you in advance,
            R.E.

            Comment


              #7
              Hi R.E.,

              Yes, this would be more expensive with commissions but is what it would take if you want to use SetProfitTarget().

              SetProfitTarget does not allow you to set a quantity. If it exits the trade it exits the entire trade. So you would need to use separate trades.

              If you want to be able to send one entry order and two exit orders for that one entry, you would need to write this customized logic into an unlocked script and you would not be able to use SetProfitTarget(). It would be best to do this with the unmanaged approach, however, by using quantities and logic you should be able to code this in the managed approach as well.
              Last edited by NinjaTrader_ChelseaB; 08-13-2015, 07:46 AM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi,

                I don't want (if possible) to use the unmanaged approach. With the managed approach and don't know how to do it. I mean we can't have orders in different directions. So without separating trades and paying more comissions I have no idea of how to do it.

                Thank you in advance,
                R.E.

                Comment


                  #9
                  Hello,

                  Try using ExitLongLimit. This does allow you to set the quantity for the exit.

                  For example:
                  ExitLongLimit(2, High[0] + 20 * TickSize, "longExit1", "longEntry");
                  ExitLongLimit(int quantity, double limitPrice, string signalName, string fromEntrySignal)

                  http://ninjatrader.com/support/helpG...tlonglimit.htm
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi,
                    Thank you chelsea for your answer but according to NT, I am violating one of the "internal Order Handling Rules that Reduce Unwanted Position". I understand that it is due to the stopLoss I use, but how to fix this. Should I use the same method to create an other "stop loss" ? Is it safe to do so? I mean, the actual price is higher than the limit price, and I think I shouldn't do this, but I see no other way.

                    Thank you in advance,
                    R.E.

                    Comment


                      #11
                      Hi R.E.,

                      I am suggesting you use exit orders instead of using SetStopLoss or SetProfitTarget.

                      Yes, make your stop loss and exit order as well.

                      From the help guide:
                      Methods that generate orders to exit a position will be ignored if:
                      A position is open and an order submitted by a set method (SetStopLoss() for example) is active.

                      Also, this won't work if you have an active entry limit, stop, or stop limit that goes in the opposite direction.

                      From the help guide:
                      Methods that generate orders to exit a position will be ignored if:
                      A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction.

                      http://ninjatrader.com/support/helpG...d_approach.htm
                      Last edited by NinjaTrader_ChelseaB; 08-18-2015, 12:33 PM.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by samish18, Today, 01:01 PM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by WHICKED, Today, 12:56 PM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by cre8able, Today, 01:16 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post cre8able  
                      Started by chbruno, 04-24-2024, 04:10 PM
                      2 responses
                      47 views
                      0 likes
                      Last Post chbruno
                      by chbruno
                       
                      Started by WHICKED, Today, 12:45 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Working...
                      X