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

Double timeframe strategy indicator of indicator condition

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

    Double timeframe strategy indicator of indicator condition

    Hello, I am trying to code a strategy that develops in daily timeframe, but checks one condition in weekly frame.

    This is an example when I want to check if the ADX (of ADXp periods) has CrossedAbove its own moving average (of ADXma periods) in weekly timeframe, to enter long if the daily moving average is above a slower one.


    // Condition set 1
    if (CrossAbove(ADX(BarsArray[1],(ADXp)), SMA((ADX(BarsArray[1],(ADXp))), ADXma), 1)
    && EMA(EMAfast)[0] > EMA(EMAslow)[0])

    This is another example, but the crossover given by daily moving averages.

    // Condition set 2
    if (ADX(ADXp)[1] >= SMA(ADX(ADXp), ADXma)[1]
    && CrossAbove(EMA(EMAfast), EMA(EMAslow), 1))

    I cannot seem to make it work, the strategy compiles and runs, but everything seems to still happen in Daily frame.

    Thanks a lot for any help!

    #2
    Hello user1986,

    Thank you for writing in.

    You'll want to place logic that you want to run only in a specific timeframe to a BarsInProgress check to that corresponding timeframe.

    For example, if you wanted logic to run only if your secondary series has called OnBarUpdate(), you'll want to do:

    Code:
    if (BarsInProgress == 1)
    {
         // do something
    }
    More information about BarsInProgress can be found here: https://ninjatrader.com/support/help...inprogress.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      So I should make a conditional of the following type?


      if (BarsInProgress == 1)
      {
      if (ADX(ADXp) >= SMA(ADX(ADXp), ADXma)
      && CrossAbove(EMA[0](EMAfast), EMA[0](EMAslow), 1))
      }

      I'm sorry but I just can't get how to make the 2 comparations in different timeframes and cross check them....

      Comment


        #4
        Hello user1986,

        I would highly suggest taking a look at the Multi-Time Frame & Instruments section of the help guide for additional information on how to utilize multiple time frames in a script: https://ninjatrader.com/support/help...nstruments.htm

        The "Using Bars Objects as Input to Indicator Methods" section will be of great use of how to utilize multiple time frames within one conditional.

        The BarsInProgress check I have provided in my previous post is there if you wish for certain logic to only run when a specific time frame has called OnBarUpdate().
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Thanks Zachary, I had read that but misunderstood how the Arrays were being managed.

          I think I am close to getting it done now.

          Is there a way to see the weekly timeframe indicators in the chart that is produced at the strategy testing? For debugging purposes it would help a lot.

          Comment


            #6
            Hello user1986,

            When adding indicators with the Add() method in Initialize(), these indicators will plot based on the primary time series.

            However, what you can do is Add() a dummy indicator that doesn't have logic inside of it. Instead, you'll have your strategy pass values to the indicator to plot. We have a reference sample on our support forum detailing how you can do this: http://ninjatrader.com/support/forum...ead.php?t=6651

            So, for example, if I wanted to plot the indicator in the reference sample based on the SMA of the secondary series:

            Code:
            StrategyPlot(0).Value.Set(SMA(BarsArray[1], 14)[0]);
            Please, let us know if we may be fo further assistance.
            Zachary G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Max238, Today, 01:28 AM
            2 responses
            26 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by Shansen, 08-30-2019, 10:18 PM
            25 responses
            949 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            8 responses
            41 views
            0 likes
            Last Post JonesJoker  
            Started by timko, Today, 06:45 AM
            0 responses
            3 views
            0 likes
            Last Post timko
            by timko
             
            Started by Waxavi, 04-19-2024, 02:10 AM
            2 responses
            39 views
            0 likes
            Last Post poeds
            by poeds
             
            Working...
            X