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 halgo_boulder, 04-20-2024, 08:44 AM
              2 responses
              21 views
              0 likes
              Last Post halgo_boulder  
              Started by mishhh, 05-25-2010, 08:54 AM
              19 responses
              6,189 views
              0 likes
              Last Post rene69851  
              Started by gwenael, Today, 09:29 AM
              0 responses
              5 views
              0 likes
              Last Post gwenael
              by gwenael
               
              Started by Karado58, 11-26-2012, 02:57 PM
              8 responses
              14,830 views
              0 likes
              Last Post Option Whisperer  
              Started by Option Whisperer, Today, 09:05 AM
              0 responses
              2 views
              0 likes
              Last Post Option Whisperer  
              Working...
              X