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

Multi-Time Frame & Instruments being Equal

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

    Multi-Time Frame & Instruments being Equal

    Hi there

    I have begun to use Multi-Time Frame & Instruments with the Add and BarsInProgress commands. So far so good...

    Is there a way to compare if different conditions on different timeframe are equal?

    That is, if a method is true on 5 min and another (or the same method) is true on 10 min, that I could print out/drawdot that they are both equal at the same time?

    Say a strong close on 5 min and at the same time a strong close on 10 min ... that would give user information that staying long is a good idea...

    At the present time, my only applications are keeping both separate like the examples with

    if (BarsInProgress == 0) and if (BarsInProgress == 1)

    Thx
    Irvin

    #2
    This may work no?

    public bool AboveMethod()
    if (BarsInProgress == 0)
    if MyMethod() == true
    return true

    if (BarsInProgress == 1)
    if MyMethod() == true && AboveMethod()== true
    DrawDot

    Comment


      #3
      Hi ij001,

      This is accomplished by accessing the Opens, Highs, Lows, Closes, Volumes, Medians, Typicals and Times series by index value. These properties hold collections (containers) that hold their named values for all Bars objects in a script. Please see this page for more information on this:


      Code:
      if (BarsInProgress == 0)
      {
      	if (Close[0] > Open[0]) 
      	{
      	//Condition is checked on these values for BIP = 0. These should be the same as if you used Closes[0][0] and Opens[0][0]. 		
      	}
      	
      	if (Closes[1][0] > Opens[1][0])
      	{
      	//Same condition is checked on secondary time frame. 	
      	}
      	
      	if (Closes[1][0] > SMA(Closes[1], 14)[0])
      	{
      	//to use these as input for an indicator only use one bracket [ ] 	
      	}
      }
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_RyanM View Post
        Hi ij001,

        This is accomplished by accessing the Opens, Highs, Lows, Closes, Volumes, Medians, Typicals and Times series by index value. These properties hold collections (containers) that hold their named values for all Bars objects in a script. Please see this page for more information on this:


        Code:
        if (BarsInProgress == 0)
        {
            if (Close[0] > Open[0]) 
            {
            //Condition is checked on these values for BIP = 0. These should be the same as if you used Closes[0][0] and Opens[0][0].         
            }
         
            if (Closes[1][0] > Opens[1][0])
            {
            //Same condition is checked on secondary time frame.     
            }
         
            if (Closes[1][0] > SMA(Closes[1], 14)[0])
            {
            //to use these as input for an indicator only use one bracket [ ]     
            }
        }
        Can my way below or another way with existing code without [1][0] for a secondary timeframe work?

        I have tons of methods already coded that I would like to use and compare and like to avoid recopying code with Closes[1][0]...

        Comment


          #5
          There's always more than one way to do things in programming. If that works for you, then there's no reason not to use it. One concern is that yours will require bar updates from both BIP 0 and 1 before the entire condition would be true. The implementation I posted can all be checked within a single BIP = 0 update.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Yes, thanks.

            If you add in a boolean condition such as ImTrue below it will work. In my case I can reuse all the existing code which was critical since I have so many useful methods.

            // Checks if OnBarUpdate() is called from an update on the primary Bars
            if (BarsInProgress == 0)
            {
            if (Close[0] > Open[0])
            ImTrue =
            true;
            else
            ImTrue = false;

            }
            // Checks if OnBarUpdate() is called from an update on MSFT 3 minute Bars
            if (BarsInProgress == 1)
            {
            if (Close[0] > Open[0] && ImTrue == true)
            DrawArrowUp(
            "A" + CurrentBar, true, 0, Low[0], Color.Lime);
            }

            Comment


              #7
              Originally posted by ij001 View Post
              Yes, thanks.

              If you add in a boolean condition such as ImTrue below it will work. In my case I can reuse all the existing code which was critical since I have so many useful methods.

              // Checks if OnBarUpdate() is called from an update on the primary Bars
              if (BarsInProgress == 0)
              {
              if (Close[0] > Open[0])
              ImTrue =
              true;
              else
              ImTrue = false;

              }
              // Checks if OnBarUpdate() is called from an update on MSFT 3 minute Bars
              if (BarsInProgress == 1)
              {
              if (Close[0] > Open[0] && ImTrue == true)
              DrawArrowUp(
              "A" + CurrentBar, true, 0, Low[0], Color.Lime);
              }
              I want to draw a region once the condition inside BIP == 1 is true. My understanding is it will be drawn on the primary chart/timeframe which in my case is 5 min.

              However when I use

              DrawRegion("Region1"+ CurrentBar, 3, 0, Low, High, Color.White, Color.Purple, 2);

              It doesn't work correctly.

              I need BIP == 0 and BIP ==1 separately because of the boolean check so there must be something that I am missing in this case.

              I have a CurrentBar <6 return statement at the beginning so its not that...

              Comment


                #8
                Hello ij001,
                Thanks for your post and I am replying for Ryan.

                Please use the below codes to do it
                Code:
                if (BarsInProgress == 1)
                	 if (CurrentBars[0] > 3)	DrawRegion("Region1", 3, 0, Lows[0], Highs[0], Color.White, Color.Purple, 2);


                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Thanks Joydeep that was helpful.

                  Now if you have added a 10 minute timeframe

                  Add(PeriodType.Minute, 10);

                  and use BIP == 0 and BIP == 1 to calculate your logic (like I did below) and happen to toggle to the 10 minute timeframe its actually a duplicate because its all the same timeframe.
                  So if your drawing or shading regions all the drawings will show up etc..

                  Now I was thinking of removing this occurence with a Return statement:

                  if (CurrentBars[0] == CurrentBars[1])
                  return;

                  That is, if the CurrentBars happen to the be same they have to be equal, because other timeframe don't have the same number of bars.

                  I believe it works because my 5 min is fine but 10 min as if nothing happened.

                  Others agree?

                  Comment


                    #10
                    Hello ij001,
                    If you are comparing 5 minute and 10 minute bar series then CurrentBars[0] == CurrentBars[1] wont match except for the first bar (which is 0 in both the case.

                    I would suggest to use the Print function and get the prints of the values which will give you more idea on it.

                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      My multi charts are working and displaying the information I need.

                      One issue I'm having is displaying the DrawArrow on the bar I want.

                      When BIP == 1 I use DrawArrow at Lows[0][0] and it displays the arrow one back from [0] because CBOC = false.

                      So I set CBOC = true and it appears to display the arrow in real time at [0].

                      The problem is my conditions are now being evaulated at every tick which I can not have. Any ideas to a possible work around?

                      Comment


                        #12
                        Hello ij001,
                        To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                        Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                        I look forward to assisting you further.

                        *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Joydeep View Post
                          Hello ij001,
                          To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                          Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                          I look forward to assisting you further.

                          *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                          Done. Thx IJ

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by DJ888, Today, 10:57 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by MacDad, 02-25-2024, 11:48 PM
                          7 responses
                          158 views
                          0 likes
                          Last Post loganjarosz123  
                          Started by Belfortbucks, Today, 09:29 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post Belfortbucks  
                          Started by zstheorist, Today, 07:52 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post zstheorist  
                          Started by pmachiraju, 11-01-2023, 04:46 AM
                          8 responses
                          151 views
                          0 likes
                          Last Post rehmans
                          by rehmans
                           
                          Working...
                          X