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

How do you check for the FirstTickOfBar of a higher time frame indicator?

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

    How do you check for the FirstTickOfBar of a higher time frame indicator?

    I'm Trying to create a higher time frame indicator (20 SMA 8-Range) on a lower time frame chart (4-Range)...

    My Question is...

    I want the 20 SMA 8-Range indicator to plot on the 4-Range chart after the FirstTickOfBar from the 8-Range chart is "True", How would I code this IF Statement to check for the FirstTickOfBar of the higher time indicator (20 SMA 8-Range) from a lower time frame chart indicator (20 SMA 8-Range on a 4-Range Chart)?

    Thank You in advance....

    #2
    Hello jcma2000,

    Thanks for your post and questions.

    For the custom indicator you would be adding the 8 range dataseries and this would become the second dataseries (4 range chart would be the base data series). With multiple data series you would differentiate processing them by using BarsInProgress. BarsInProgress = 0 refers to the base chart. BarsInProgress = 1 will refer to the added data series (in this case an 8 range).

    In your code of the indicator you would use BarsInProgress like this:

    Code:
    OnBarUpdate 
    {
        if (BarsInProgress == 0)
        {
          Execute 4 range code (base chart) in here
        }
    
        if (BarsInProgress == 1)
        {
          Execute 8 range code here, like
             if (FirstTickOFBar)  // Execute code on first tick of 8 range bar only
             {
                Execute first tick of 8 range bar code here
             }
         }
    }
    Here is a link that discusses BarsInProgress: http://www.ninjatrader.com/support/h...inprogress.htm

    If you haven't already, please review http://www.ninjatrader.com/support/h...nstruments.htm as this gives a great direction on the considerations for programming MTF type indicators.

    Please let me know if you have further questions.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      1 of 2

      Code:
      [COLOR=blue][FONT=Courier New]protectedoverridevoid[COLOR=black][FONT=Courier New] OnBarUpdate()Thanks Paul for your quick response.... 
      
      The Indicator worked before I made theBarsInProgress changes. I made the following changes and neither MA plots. Could you PLEASE look at my code and tell me what I’m doing wrong? Thanks in advance....
      
      [COLOR=green][FONT=Courier New]
      [/FONT][COLOR=black][FONT=Courier New]{[/FONT][/COLOR][COLOR=green][FONT=Courier New]
      [/FONT][/COLOR][COLOR=blue][FONT=Courier New]if[/FONT][/COLOR][COLOR=black][FONT=Courier New] (CurrentBars[[/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New]] <= BarsRequired || CurrentBars[[/FONT][/COLOR][COLOR=purple][FONT=Courier New]1[/FONT][/COLOR][COLOR=black][FONT=Courier New]] <= BarsRequired || BarsInProgress != [/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New]) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]return[/FONT][/COLOR][COLOR=black][FONT=Courier New];[/FONT][/COLOR]
      [/COLOR][/FONT]

      [/FONT][/COLOR][/COLOR]
      Last edited by jmca2000; 08-15-2014, 06:35 PM.

      Comment


        #4
        2 of 2

        Thanks Paul for your quick response....

        The Indicator worked before I made theBarsInProgress changes. I made the following changes and neither MA plots. Could you PLEASE look at my code and tell me what I’m doing wrong? Thanks in advance....


        Code:
        [COLOR=blue][FONT=Courier New]protectedoverridevoid[COLOR=black][FONT=Courier New] OnBarUpdate()[/FONT][/COLOR][COLOR=green][FONT=Courier New]
        [/FONT][/COLOR][COLOR=black][FONT=Courier New]{[/FONT][/COLOR][COLOR=green][FONT=Courier New]
        [/FONT][/COLOR][COLOR=blue][FONT=Courier New]if[/FONT][/COLOR][COLOR=black][FONT=Courier New] (CurrentBars[[/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New]] <= BarsRequired || CurrentBars[[/FONT][/COLOR][COLOR=purple][FONT=Courier New]1[/FONT][/COLOR][COLOR=black][FONT=Courier New]] <= BarsRequired || BarsInProgress != [/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New]) [/FONT][/COLOR][COLOR=blue][FONT=Courier New]return[/FONT][/COLOR][COLOR=black][FONT=Courier New];[/FONT][/COLOR]
        [/COLOR][/FONT]

        Last edited by jmca2000; 08-15-2014, 06:34 PM.

        Comment


          #5
          Hello jmca2000,

          Thanks for posting your code. To make that process easier for you, when you want to post code segments use the "Go Advanced" option, paste in your code then select the code and click on the "#" icon above the reply box and that action will put [code] labels before and after your text and anything in between will be in a scrolling window (which you can look at in in preview post). You will also see other options as well.

          In this section of code:

          Code:
          protectedoverridevoid OnBarUpdate()
          {
          if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || BarsInProgress != 0) return;
          The last check say "if BarsInProgress is not equal to zero - return". So this line will effectively ignores any BarsInprogress ==1 onbarupdate.

          There could be other errors as well but I'm not sure with the text in green usually means it is commented out.

          Please adjust your code and recompile and continue the debugging process.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Just one more question

            Paul, Thank You, that was the problem...BarsInprogress ==1 onbarupdate

            I have just one more question... I wrote a little program that takes a screenshot of my monitor every time the First Tic of a New Bar is started. I want to modify this program to just take a screenshot whenever I Enter, Cancel, Close, change the stop Loss of an order using Chart Trader...etc...So I have a record of my Trades and can review them.

            Could you Please tell me the "IF" Test Function I should use to accomplish this...

            if(---?????????---)
            {Take Snapshot of Monitor}


            and any special considerations I should be aware of...

            Thank You once again in advance....

            Comment


              #7
              Hello jmca2000,

              Thanks for the update and glad to hear your indicator is working.

              For the screenshot question, that would be in an unsupported area.

              If you use indicators as potential triggers for entry or exit, those could be used.

              Please let me know if you have further questions.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Paul,

                Could you PLEASE just tell me if this would acomplish the task of testing whenever an order is filled, and that it will print to a string?

                // Generic execution logic not specific to a particular IOrder object
                protected override void OnExecution(IExecution execution)
                {

                // Remember to check the underlying IOrder object for null before trying to access its properties
                if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
                Print(execution.ToString());


                Then all I would have to do, is modify this:
                From: Print (execution.ToString ( ) ) ;

                To: Something like... Take... (Screen Shot of Monitor Screen....) ;
                ... Which I already know how to do...

                Thank You Again...
                Last edited by jmca2000; 08-15-2014, 08:52 PM.

                Comment


                  #9
                  Hello jcma2000,

                  Please see this thread http://www.ninjatrader.com/support/f...ad.php?t=68029 which I think gets you a complete answer.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    THANK YOU VERY MUCH PAUL FOR THE INFORMATION...

                    I think your right and this will do the trick, but im not sure what I shoud change some of the example code to.

                    Could you PLEASE give me some insight on how to go about changing the code regarding my Account information as it applies to the account and account name?

                    Thank You Again in Advance.

                    Code:
                     [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] accountName = [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Sim101"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000];[/COLOR]
                     Account account = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
                      
                    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (a.Name == accountName)[/COLOR]
                     {
                     account = a;
                     account.Execution += [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ExecutionUpdateEventHandler(OnExecution);
                     account.OrderStatus += [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OrderStatusEventHandler(OnOrderStatus);
                     account.PositionUpdate += [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PositionUpdateEventHandler(OnPosition);
                     account.Connection.ConnectionStatus += [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ConnectionStatusEventHandler(OnConnection);
                     [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
                      
                    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (account == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]null)[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
                      
                    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (account != [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR]
                     {
                     account.Execution -= [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ExecutionUpdateEventHandler(OnExecution);
                     account.OrderStatus -= [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OrderStatusEventHandler(OnOrderStatus);
                     account.PositionUpdate -= [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PositionUpdateEventHandler(OnPosition);
                     account.Connection.ConnectionStatus -= [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ConnectionStatusEventHandler(OnConnection); 
                     }
                    [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
                    [/SIZE][/FONT][/SIZE][/FONT] 
                     [/SIZE][/FONT][/SIZE][/FONT]

                    Comment


                      #11
                      Hello jcma2000,

                      Thank-you for your post.

                      FYI - If you use CAPS it is the same as yelling at someone.

                      To change the account please change the text in the string "Sim101" to your account name exactly as it shows in your accounts tab in the control center.

                      If you haven't already, compile and run the sample code to see how it operates.

                      Please let me know if you have further questions.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Paul,

                        Thank You also for the Forum educate lesson.

                        I meant nothing by the CAPS, other than to point out gratitude and appreciation for help.

                        Does it mean something when you use Bold Highlighting of words (I use this to highlight my requests and also Thanks)?

                        Thank You for your support, this works exactly the way I wanted it to.

                        Just to let you know, the Attached File “SampleAccountAccess.cs” at the thread you referred me to http://www.ninjatrader.com/support/f...ad.php?t=68029 it downloads as a “attachment.php”, not as a .cs file. So I had to open it up in Notepad++ and save it as a C# .cs extension, then copy and paste it into the NT7 Indicator folder, compile and run it (all this JFYI).

                        I have one last thing to resolve and figure out; I use the following code to take a Snapshot of the primary monitor screen:

                        Image bit = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);

                        Graphics gs = Graphics.FromImage(bit);

                        gs.CopyFromScreen(new Point(0, 0), new Point(0, 0), bit.Size);

                        bit.Save(@"c:\MyOrders_ChartImages\" + imageName + ".jpg");

                        Paul, I need to modify the above code so that it will take a Snapshot of the Active Window or Preferably the Active Monitor so I can use the code to handle multi-Monitor displays with different instrument charts on them.

                        Could you Please, Please give me some insight and or direct me to a thread that would show me how this code should be modified to handle multi-Monitor displays?

                        Thank You In Advance Again….Joe

                        Comment


                          #13
                          Hello Joe,

                          Thanks for your reply and understanding.

                          Thanks for your feedback about the downloads. I use Chrome and it downloads the files directly as .CS type, I don't know why yours would not.

                          The screenshot question is in an unsupported area. Here are a couple links that may be helpful:




                          I will leave this open for others to contribute.
                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by RookieTrader, Today, 09:37 AM
                          3 responses
                          15 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by kulwinder73, Today, 10:31 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post kulwinder73  
                          Started by terofs, Yesterday, 04:18 PM
                          1 response
                          23 views
                          0 likes
                          Last Post terofs
                          by terofs
                           
                          Started by CommonWhale, Today, 09:55 AM
                          1 response
                          4 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Started by Gerik, Today, 09:40 AM
                          2 responses
                          7 views
                          0 likes
                          Last Post Gerik
                          by Gerik
                           
                          Working...
                          X