Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Time Frame with some parameters

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

    Multi-Time Frame with some parameters

    Hello again, guys!

    I have some problems with understanding some things about using Multi-Time frame.
    I want to use 2 time-frames for my strategy: 1st will be main for entering positions (f.e. 1 min chart), and the 2nd will be for analizing some data with indicator (f.e. on 5 min chart).

    In this indicator I have value that changes (f.e. it calls WhatToTrade).

    Exactly what I need is to get this value from Indicator (it's custom, not standart indicator) and change one variable in my Strategy (f.e. it calls IsTradeLong).
    Can somebody give me help with how to code this?

    Thanks!

    #2
    Hello YevhenShynkarenko,

    Thank you for your post.

    Your indicators can be called like any of the pre-installed indicators in NinjaTrader. For example, if I wanted to call a custom indicator it would look similar to the following:
    Code:
    MyIndicator(int myInput, double myValue)
    While the above is a generailiziation you can find more examples at the following link: http://www.ninjatrader.com/support/h...indicators.htm
    For details on passing input please visit the following link: http://www.ninjatrader.com/support/h..._indicator.htm

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello YevhenShynkarenko,

      Thank you for your post.

      Your indicators can be called like any of the pre-installed indicators in NinjaTrader. For example, if I wanted to call a custom indicator it would look similar to the following:
      Code:
      MyIndicator(int myInput, double myValue)
      While the above is a generailiziation you can find more examples at the following link: http://www.ninjatrader.com/support/h...indicators.htm
      For details on passing input please visit the following link: http://www.ninjatrader.com/support/h..._indicator.htm

      Please let me know if you have any questions.
      Thanks for answer.
      For example I have an indicator called TREND. And I want for working it on 5 Minute TimeFrame.
      But at that time my Strategy will work on 1 minute TimeFrame. What do I need to write in my code? And what code do I need to "catch" variable from that TREND indicator and put it in my Strategy.
      I'll be very greatful if you can write me code example with my "names of indicator"!
      Regards!

      Comment


        #4
        Hello YevhenShynkarenko,

        Thank you for your response.

        Run the strategy on the 1 Minute chart but use Add(PeriodType.Minute, 5); in the Initialize() method of your strategy. Then when you call you indicator, pass the bar series for 5 Minutes as the Input Series:
        Code:
        TREND(BarsArray[1], myParameters)
        For information on using 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


          #5
          Ok, thanks!
          And one more question.
          As I find the example on forum

          protected override void Initialize()
          {
          myDataSeries = new DataSeries(this); // "this" refers to the indicator, or strategy
          // itself. This syncs the DataSeries object
          // to historical data bars
          }

          On what value do I need to change "this" to give me 5 minute timeframe prices? Thanks!

          Comment


            #6
            This is detailed at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3572

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              This is detailed at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3572
              I saw that example. Can you give me example code for GC instrument and 5 min timeframe when my primary timeframe will be 1 min?
              Big Thanks!

              Comment


                #8
                Hello YevhenShynkarenko,

                Thank you for your response.

                The code would resemble the following. I would ask why you are looking to do this though.
                Code:
                        #region Variables
                		// Declare two DataSeries objects
                		private DataSeries primarySeries;
                		private DataSeries secondarySeries;
                        #endregion
                
                        /// <summary>
                        /// This method is used to configure the strategy and is called once before any strategy method is called.
                        /// </summary>
                        protected override void Initialize()
                        {
                			// Adds a secondary bar object to the strategy.
                			Add(PeriodType.Minute, 5);
                			
                			// Syncs a DataSeries object to the primary bar object
                			primarySeries = new DataSeries(this);
                			
                        }
                
                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                			/* Only need to sync DataSeries objects once. We couldn't do this sync in the Initialize() method because we
                			cannot access the BarsArray property there. */
                			if (secondarySeries == null)
                			{
                				/* Syncs another DataSeries object to the secondary bar object.
                				We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
                				The indicator can be any indicator. The DataSeries will be synced to whatever the
                				BarsArray[] is provided.*/
                				secondarySeries = new DataSeries(SMA(BarsArray[1], 1));
                			}

                Comment


                  #9
                  That's right example, but I can't understand how I can get variable from custom indicator? (AutoTrendH)

                  Now I added the indicator inside my strategy. It works and changes one of my variable, but it works only on the same timeframe as I putting when I'm adding strategy. And that's the question - can I limit my first part of the code which enters positions to use current dataseries and the second part of code with this indicator method to use 5 min period? If yes , how?

                  Comment


                    #10
                    Hello YevhenShynkarenko,

                    I would just call the indicator's method and pass the secondary series to it. Can you provide the .cs file for your indicator and I can provide an example on how to call this with the secondary series in a strategy?

                    Comment


                      #11
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello YevhenShynkarenko,

                      I would just call the indicator's method and pass the secondary series to it. Can you provide the .cs file for your indicator and I can provide an example on how to call this with the secondary series in a strategy?
                      Sure. That's the the indicator which I want to use on any other timeframe in my strategy.
                      But I want to have possibility to change.

                      In my version I have my own variable that I need to get in my Strategy after:

                      if (upTrendStartBarsAgo > 0 && upTrendEndBarsAgo > 0 && upTrendStartBarsAgo < downTrendStartBarsAgo)

                      and

                      if (downTrendStartBarsAgo > 0 && downTrendEndBarsAgo > 0 && upTrendStartBarsAgo > downTrendStartBarsAgo)
                      Attached Files

                      Comment


                        #12
                        Hello YevhenShynkarenko,

                        Are you exposing the variable?
                        For more information please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=4991

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello YevhenShynkarenko,

                          Are you exposing the variable?
                          For more information please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=4991

                          I have one variable in strategy, and one in indicator. I need:
                          - indicator works on another timeframe then strategy
                          - get variable from indicator and put it in my strategy

                          F.e. After code from my below post i will have Variable in indicator:
                          LongTrend = True

                          And if it's so, I need to strategy will change my Variable in Strategy that called IsTrendLong to true.

                          I can't understand how it get all together.

                          Comment


                            #14
                            Hello YevhenShynkarenko,

                            Thank you for your response.

                            Can you provide the strategy and the indicator you are using (not the one you based it on)? If you prefer you can send it to platformsupport[at]ninjatrader[dot]com with this thread in the body of the e-mail: "http://www.ninjatrader.com/support/forum/showthread.php?t=72777"

                            Comment


                              #15
                              Originally posted by NinjaTrader_PatrickH View Post
                              Hello YevhenShynkarenko,

                              Thank you for your response.

                              Can you provide the strategy and the indicator you are using (not the one you based it on)? If you prefer you can send it to platformsupport[at]ninjatrader[dot]com with this thread in the body of the e-mail: "http://www.ninjatrader.com/support/forum/showthread.php?t=72777"
                              Sorry, but I cant send all my strategy.
                              I can give some code from it that I need to work only with 5 min timeframe... I've already put this in my Strategy, so I don't need to use additional indicators to strategy. Maybe it would be easier? All this code must be using another Period... How can I get this?

                              Uptade: I want to this part of code will calculate on 5 min period (timeframe). And another one will work by its default value of dataseries.

                              PHP Code:
                                      private void GetTrend(){
                                      
                                          //DETERMINE LOCATION OF LAST UP/DOWN TREND LINES    
                                          signal = 0;
                                          int upTrendOccurence         = 1;    int upTrendStartBarsAgo        = 0;    int upTrendEndBarsAgo         = 0;
                                          int downTrendOccurence         = 1;    int    downTrendStartBarsAgo    = 0;    int    downTrendEndBarsAgo     = 0;
                                      // Only calculate new autotrend line if ray hasent been put into manual mode by unlocking current ray
                                      if ( ((DrawObjects["UpTrendRay"] ==null) || (DrawObjects["UpTrendRay"].Locked)) && ((DrawObjects["DownTrendRay"] ==null) || (DrawObjects["DownTrendRay"].Locked)) ) 
                              //        if (  (DrawObjects["UpTrendRay"].Locked) || (DrawObjects["DowntrendTrendRay"].Locked) ) 
                                      {//Only do the following if existing ray is in auto mode    
                                      // Calculate up trend line
                                          upTrendOccurence         = 1;    
                                          while (Low[upTrendEndBarsAgo] <= Low[upTrendStartBarsAgo])
                                          {    upTrendStartBarsAgo     = Swing(strength).SwingLowBar(0, upTrendOccurence + 1, CurrentBar);
                                              upTrendEndBarsAgo     = Swing(strength).SwingLowBar(0, upTrendOccurence, CurrentBar);
                                              if (upTrendStartBarsAgo < 0 || upTrendEndBarsAgo < 0)
                                                  break;
                                              upTrendOccurence++;
                                          }
                                      // Calculate down trend line    
                                          downTrendOccurence         = 1;
                                          while (High[downTrendEndBarsAgo] >= High[downTrendStartBarsAgo])
                                          {    downTrendStartBarsAgo         = Swing(strength).SwingHighBar(0, downTrendOccurence + 1, CurrentBar);
                                              downTrendEndBarsAgo         = Swing(strength).SwingHighBar(0, downTrendOccurence, CurrentBar);
                                              if (downTrendStartBarsAgo < 0 || downTrendEndBarsAgo < 0)
                                                  break;
                                              downTrendOccurence++;
                                          }
                                       }    
                                      // Clear out arrows that mark trend line breaks unless ShowHistory flag is true
                                          if (!showHistory) RemoveDrawObject("DownTrendBreak");                            
                                          if (!showHistory) RemoveDrawObject("UpTrendBreak");
                                          
                                  //PROCESS UPTREND LINE IF CURRENT
                                          if (upTrendStartBarsAgo > 0 && upTrendEndBarsAgo > 0 && upTrendStartBarsAgo < downTrendStartBarsAgo)
                                          {    
                                              RemoveDrawObject("DownTrendRay");
                                              double startBarPrice     = Low[upTrendStartBarsAgo];
                                              double endBarPrice         = Low[upTrendEndBarsAgo];
                                              double changePerBar     = (endBarPrice - startBarPrice) / (Math.Abs(upTrendEndBarsAgo - upTrendStartBarsAgo));
                                          //Test to see if this is a new trendline and increment lineCounter if so.
                                              if (startBarPrice!=startBarPriceOld)    
                                              {    direction=1;  //Signal that we have a new uptrend and put dot on trendline where new trend detected
                                                  DrawDot(CurrentBar.ToString(), true, 0, startBarPrice+(upTrendStartBarsAgo*changePerBar), UpTrendColor);
                                                  lineCount=lineCount+1;    
                                                  triggerBarIndex = 0;
                                                  ResetAlert("Alert");
                                              }
                                              startBarPriceOld=startBarPrice;
                                              //
                                          // Draw the up trend line
                                          // If user has unlocked the ray use manual rays position instead of auto generated positions to track ray position
                                              if ( (DrawObjects["UpTrendRay"] !=null) && (!DrawObjects["UpTrendRay"].Locked) )
                                              {    IRay upTrendRay        = (IRay) DrawObjects["UpTrendRay"];    
                                                  //startBarPrice         = upTrendRay.Anchor1Y;
                                                  //endBarPrice         = upTrendRay.Anchor2Y;
                                                  upTrendStartBarsAgo = upTrendRay.Anchor1BarsAgo;
                                                  upTrendEndBarsAgo   = upTrendRay.Anchor2BarsAgo;
                                                  //changePerBar         = (endBarPrice - startBarPrice)/(Math.Abs(upTrendRay.Anchor2BarsAgo-upTrendRay.Anchor1BarsAgo));
                                                  //upTrendRay.Pen.DashStyle=DashStyle.Dash;
                                                  //upTrendRay.Pen.Color=Color.Blue;
                                              }
                                              //else
                                              //{    DrawRay("UpTrendRay", false, upTrendStartBarsAgo, startBarPrice, upTrendEndBarsAgo, endBarPrice, UpTrendColor, DashStyle.Solid, lineWidth);
                                              //}
                                          //Draw the history line that will stay persistent on chart using lineCounter to establish a unique name
                                              
                                              //if (showHistory) DrawLine("HistoryLine"+lineCount.ToString(), false, upTrendStartBarsAgo, startBarPrice, 0, startBarPrice+(upTrendStartBarsAgo*changePerBar), UpHistColor, DashStyle.Solid, lineWidth);
                                      
                                              //SET RETURN VALUES FOR INDICATOR
                                          // Check for an uptrend line break
                                              
                                              /*trendPrice=(startBarPrice+(upTrendStartBarsAgo*changePerBar));
                                              for (int barsAgo = upTrendEndBarsAgo - 1; barsAgo >= 0; barsAgo--) 
                                              {    if (Close[barsAgo] < endBarPrice + (Math.Abs(upTrendEndBarsAgo - barsAgo) * changePerBar))
                                                  {    if (showHistory) 
                                                      {    DrawArrowDown("UpTrendBreak"+lineCount.ToString(), barsAgo, High[barsAgo] + TickSize, downTrendColor); }
                                                      else
                                                      {    DrawArrowDown("UpTrendBreak", barsAgo, High[barsAgo] + TickSize, downTrendColor); }
                                          // Set the break signal only if the break is on the right most bar
                                                      if (barsAgo == 0)
                                                          signal = -1;
                                          // Alert will only trigger in real-time
                                                      if (AlertOnBreak && triggerBarIndex == 0)
                                                      {    triggerBarIndex = CurrentBar - upTrendEndBarsAgo;
                                                          Alert("Alert", Priority.High, "Up trend line broken", "Alert2.wav", 100000, Color.Black, Color.Red);
                                                      }
                                                      break;
                                                  }    
                                              }
                                              */
                                          }
                              
                              
                                          else 
                                  //DETECT AND PROCESS DOWNTREND LINE    IF CURRENT    
                                          if (downTrendStartBarsAgo > 0 && downTrendEndBarsAgo > 0  && upTrendStartBarsAgo > downTrendStartBarsAgo)
                                          {    
                                              RemoveDrawObject("UpTrendRay");
                                              double startBarPrice     = High[downTrendStartBarsAgo];
                                              double endBarPrice         = High[downTrendEndBarsAgo];
                                              double changePerBar     = (endBarPrice - startBarPrice) / (Math.Abs(downTrendEndBarsAgo - downTrendStartBarsAgo));
                                          //Test to see if this is a new trendline and increment lineCount if so.
                                              if (startBarPrice!=startBarPriceOld)    
                                              {    direction=-1;        //signl that we have a new downtrend
                                                  DrawDot(CurrentBar.ToString(), true, 0, startBarPrice+(downTrendStartBarsAgo*changePerBar), DownTrendColor);
                                                  lineCount=lineCount+1;    
                                                  triggerBarIndex = 0;
                                                  ResetAlert("Alert");
                                              }
                                              startBarPriceOld=startBarPrice;
                                              //
                                          // Draw the down trend line
                                              // If user has unlocked the ray use manual rays position instead
                                              if ( (DrawObjects["DownTrendRay"] !=null) && (!DrawObjects["DownTrendRay"].Locked) )
                                              {    IRay downTrendRay    = (IRay) DrawObjects["DownTrendRay"];    
                                              //    startBarPrice         = downTrendRay.Anchor1Y;
                                              //    endBarPrice         = downTrendRay.Anchor2Y;;
                                                  downTrendStartBarsAgo = downTrendRay.Anchor1BarsAgo;
                                                  downTrendEndBarsAgo   = downTrendRay.Anchor2BarsAgo;
                                              //    changePerBar         = (endBarPrice - startBarPrice)/(Math.Abs(downTrendRay.Anchor2BarsAgo-downTrendRay.Anchor1BarsAgo));
                                              //    downTrendRay.Pen.DashStyle=DashStyle.Dash;
                                              //    downTrendRay.Pen.Color=Color.Blue;
                              
                                              }
                                              //else            
                                              //{    DrawRay("DownTrendRay", false, downTrendStartBarsAgo, startBarPrice, downTrendEndBarsAgo, endBarPrice, DownTrendColor, DashStyle.Solid, lineWidth);
                                              //}
                                              //if (showHistory) DrawLine("HistoryLine"+lineCount.ToString(), false, downTrendStartBarsAgo, startBarPrice, 0, startBarPrice+(downTrendStartBarsAgo*changePerBar), downHistColor, DashStyle.Solid, lineWidth);
                                      //SET RETURN VALUES FOR INDICATOR
                                          // Check for a down trend line break
                                              /*
                                              trendPrice=(startBarPrice+(downTrendStartBarsAgo*changePerBar));
                                              for (int barsAgo = downTrendEndBarsAgo - 1; barsAgo >= 0; barsAgo--) 
                                              {//    direction=-1;
                                                  if (Close[barsAgo] > endBarPrice + (Math.Abs(downTrendEndBarsAgo - barsAgo) * changePerBar))
                                                  {    if (showHistory) 
                                                      {    DrawArrowUp("DownTrendBreak"+lineCount.ToString(), barsAgo, Low[barsAgo] - TickSize, upTrendColor); }
                                                      else
                                                      {    DrawArrowUp("DownTrendBreak", barsAgo, Low[barsAgo] - TickSize, upTrendColor); }
                                                  // Set the break signal only if the break is on the right most bar
                                                      if (barsAgo == 0)
                                                          signal = 1;
                                                  // Alert will only trigger in real-time
                                                      if (AlertOnBreak && triggerBarIndex == 0)
                                                      {    triggerBarIndex = CurrentBar - downTrendEndBarsAgo;
                                                          Alert("Alert", Priority.High, "Down trend line broken", "Alert2.wav", 100000, Color.Black, Color.Green);
                                                      }
                                                      break;
                                                  }
                                              }*/
                                          }        
                                      } 
                              
                              Last edited by YevhenShynkarenko; 03-23-2015, 05:31 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              646 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              367 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X