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

multiple time frames for one buy signal

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

    multiple time frames for one buy signal

    Hi,

    How can I code this strategy:

    Buy when price crosses below 10ma on a 30 minute chart?

    Thanks!
    Last edited by TradeYa; 04-26-2015, 10:19 PM.

    #2
    Hello TradeYa,

    Thank you for your post.

    The additional bars objects would need to be added to the code: http://www.ninjatrader.com/support/h...s/nt7/add3.htm

    Then you would need to use BarsArray for the Indicator methods, for example:
    Code:
    if(CrossBelow(Close, SMA(BarsArray[0], 10), 1)
    || CrossBelow(Close, SMA(BarsArray[0], 15), 1)
    || CrossBelow(Close, SMA(BarsArray[1], 10), 1)
    || CrossBelow(Close, SMA(BarsArray[1], 15), 1))
    {
    // do something
    }
    For information on multiple series in your code please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

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

    Comment


      #3
      Hi Patrick,

      Thank you very much!

      I checked out the link about multiple time periods, is this how to code it in?

      Add(string instrumentName, PeriodType periodType, int period)

      Add("AAPL", PeriodType.Minute, 20)
      Add("AAPL", PeriodType.Minute, 30)

      If that's correct - where does it belong in the code for multiple indicators? Should it look like this:

      if(CrossBelow(Close, SMA(BarsArray[0], 10), 1)
      || CrossBelow(Close, SMA(BarsArray[0], 15), 1)
      || CrossBelow(Close, SMA(BarsArray[1], 10), 1)
      || CrossBelow(Close, SMA(BarsArray[1], 15), 1))
      || Add("AAPL", PeriodType.Minute, 20)
      || Add("AAPL", PeriodType.Minute, 30)
      {
      // do something

      Thanks!

      Comment


        #4
        Hello TradeYa,

        You just use Add() in Initialize(), then pass BarsArray[1] and BarsArray[2] to the indicator methods as their input in the OnBarUpdate():
        Code:
        if(CrossBelow(Close, SMA(BarsArray[2], 10), 1)
        || CrossBelow(Close, SMA(BarsArray[2], 15), 1)
        || CrossBelow(Close, SMA(BarsArray[1], 10), 1)
        || CrossBelow(Close, SMA(BarsArray[1], 15), 1))
        {
        // do something
        }

        Comment


          #5
          Hi Patrick,

          I'm very inexperienced at coding & need a little more description and background on all the technical terms.

          When you say "use Add() in Initialize()" - where's initialize?

          And for the following instructions I'm a deer in the headlights and you've completely lost me.
          then pass BarsArray[1] and BarsArray[2] to the indicator methods as their input in the OnBarUpdate():

          An example would be great, I'm trying my best to understand and become self-sufficient.

          Comment


            #6
            Hello TradeYa,

            Thank you for your response.

            Below is an example:
            Code:
                    /// This method is used to configure the indicator and is called once before any bar data is loaded.
                    /// </summary>
                    protected override void Initialize()
                    {
                        Add("AAPL", PeriodType.Minute, 20);
            			Add("AAPL", PeriodType.Minute, 30);
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                        if(CrossBelow(Close, SMA(BarsArray[2], 10), 1)
            			|| CrossBelow(Close, SMA(BarsArray[2], 15), 1)
            			|| CrossBelow(Close, SMA(BarsArray[1], 10), 1)
            			|| CrossBelow(Close, SMA(BarsArray[1], 15), 1))
            			{
            				// do something
            			}
                    }

            Comment


              #7
              Thanks Patrick that helped a lot, but I have a few questions:

              1. What do the “||” characters stand for? Is it the same as using “&&”?

              2. What does [2] and [1] refer to in:
              ||CrossBelow(Close, SMA(BarsArray[2],15), 1)
              ||CrossBelow(Close, SMA(BarsArray[1],10), 1)

              3. Is there a limit on the amount of rules to use in the
              Initialize() method?

              4. How can I specify the amount entries to make after getting stopped out? Or does that occur on its own, so long as this strategy is running?

              Comment


                #8
                Hello TradeYa,

                Thanks for your reply and questions.

                The "||" represent "OR" whereas "&&" represents "AND". In the example code you can read as, If price crosses below the SMA on one timeframe OR if the price crosses below the SMA of another timeframe, etc.

                In the BarsArray the [1] and [2] refer to the different dataseries (time frames) that were added. [0] refers to that charts data series, [1] refers to the first listed ADD data series, [2] refers to the 2nd ADD data series. Please do read all the linked help guide section as it will save you a lot of time in the complex area of multi-time frame: http://www.ninjatrader.com/support/h...nstruments.htm

                The purpose of the initialize section is to configure the indicator and strategies. Please read: http://www.ninjatrader.com/support/h...initialize.htm

                Regarding the amount of entries to make after getting stopped out, that would depend on what you would like the strategy to do.

                Please let me know if I can be of further assistance.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Paul!

                  As far as coding the amount of entries - I'd like to do a few things. First, I'd like to specify the amount of entry attempts, let's say the max amount of times getting stopped out is 3. Second, can I limit the amount of entries/stop outs to a maximum loss in terms of dollars or percent?

                  Do I have to subscribe to kinetick to test this strategy? Does the free kinetick feed only provide end of day data for daily candles and not for intraday data?

                  What are the rules for the “{ }” characters?

                  Should I create a second condition set for the time of day when this strategy is active? My earlier condition set for numerous chart time frames is considered the first condition set - will my code have errors if I just add this time of day code directly onto my first condition?

                  Thank you very much in advance

                  Comment


                    #10
                    Hello TradeYa,

                    Thanks for your reply and questions.

                    You can access a number of items about your trading through trades performance. Here is a link to the helpguide section that includes an example of consecutive losing tradings: http://www.ninjatrader.com/support/h...erformance.htm

                    Here is a link to tradesperformance showing an example of logic to check the current PnL: http://www.ninjatrader.com/support/h...ancevalues.htm

                    The Kinetic End Of Data (free) can only provide daily and higher bars and would not be suitable for testing your intraday MTF strategy. Alternatives are to download Market Replay data (assuming you are testing on Futures instruments) and run your strategy in Market replay or acquire a live data demo feed. If you can access historical data then you would also be able to use the strategy analyzer to test your strategy.

                    Ninjascript is based on C# programming language. The "{ }" are used to associate a block of code together. For example:
                    without braces:
                    if (condition)
                    do this action only;

                    with braces:
                    if (condition)
                    {
                    do this action;
                    and this action;
                    and this action;
                    etc;
                    }

                    Regarding the time of day. You can create the time set condition and using the { } enclose the condition set previously created so that the condition set is only executed at the time range you have selected.

                    Please let me know if I can be of further assistance.
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kujista, Today, 06:23 AM
                    3 responses
                    6 views
                    0 likes
                    Last Post kujista
                    by kujista
                     
                    Started by Mindset, Yesterday, 02:04 AM
                    2 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_RyanS  
                    Started by f.saeidi, Today, 08:03 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by samish18, 04-17-2024, 08:57 AM
                    15 responses
                    52 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by f.saeidi, Today, 08:13 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post f.saeidi  
                    Working...
                    X