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

open position after n bars close above average

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

    open position after n bars close above average

    Hello,

    I am trying to create a strategy through the Strategy Builder where a long position is initiated after 2 consecutive price bars close above the SMA. To achieve this I tried adding two conditions in Conditions and Actions as follows;

    IF ALL of the following conditions are met:
    1st condition:
    Price --> Close --> Bars Ago (0)
    Cross Above --> Look back period (1)
    Indicator --> SMA --> Bars Ago (0)

    2nd condition:
    Price --> Close --> Bars Ago (1)
    Cross Above --> Look back period (1)
    Indicator --> SMA --> Bars Ago (1)

    Do the following:
    EnterLong(DefaultQuantity,"");

    And I tried various combinations but its not giving the desired results.

    Thank you,
    Remo

    #2
    Bool saves the day!

    I had been searching the forums but didn't find the answer so after posting above I decided to browse the forums to learn new things and found the bool example at the thread https://ninjatrader.com/support/foru...dicator-does-y

    Replicated it and worked like a charm.

    Thanks.

    Comment


      #3
      This is a brilliant solution that you have found.

      Comment


        #4
        Hello remorim,

        You would not want to use CrossAbove as the operator in the center.

        You would want two conditions in the same condition set. The first is Price > Close > Bars Ago 0, is greater than, Indicators > SMA > Period. The second is Price > Close > Bars Ago 1, is greater than, Indicators > SMA > Period.

        The solution you have linked would not be looking for two consecutive bar closes above the sma. Instead, this would be creating a trigger with a bool after one action, and then triggering another action after a certain amount of bars, basically using each condition set as a wait for a new bar..
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          Your suggestion worked as well. It's much simpler than using the bool's.

          Many thanks.

          Comment


            #6
            Is there a way to make this approach more dynamic and allows for optimization with arbitrary number of bars closing above the SMA? Thanks again.

            Comment


              #7
              Hello mgalal,

              You are wanting to increment a counter each time a condition is true (when Close is above SMA)?

              The only math possible is with offsets on Series. Below is a link to an example of a counter using Series and offsets with the Strategy Builder.
              with regard to the attached image: Line A is an indicator Line B is the m period MAX of line A Line C is an average of this indicator A Line D is another average of this indicator A is it possible, possibly using the strategy builder, but without adding a temporary variable, to set on the condition: line C crosses below line D
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by GwFutures1988, Today, 02:48 PM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by ScottWalsh, 04-16-2024, 04:29 PM
              6 responses
              27 views
              0 likes
              Last Post ScottWalsh  
              Started by frankthearm, Today, 09:08 AM
              10 responses
              35 views
              0 likes
              Last Post frankthearm  
              Started by mmenigma, Today, 02:22 PM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by NRITV, Today, 01:15 PM
              2 responses
              9 views
              0 likes
              Last Post NRITV
              by NRITV
               
              Working...
              X