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 (MTF) Indicator

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

    Multi Time Frame (MTF) Indicator

    Hello,
    I would like to display intra-day calculation results on daily chart.

    There are 2 data series:
    PRIMARY -> Daily bars (chart resolution)
    SECONDARY -> 60min bars using ADD() function

    Let's say the indicator calculation is now on daily bar 1.1.2014. How can I check all 60min opens against 100 on this date? Because this condition checks only the latest one 60min open...???

    if (Opens[1][0] > 100)
    do something on daily chart....

    Thanks for hints
    Peter

    #2
    Hi Peter,

    Are you wanting to check the open of all 60 minute bar opens being higher than 100 back to the beginning of the data or just for the current day?

    You will need to use a loop to find this information.

    Below is a link to the help guide on Basic Programming Concepts -> Looping Commands.
    http://www.ninjatrader.com/support/h...g_commands.htm

    For all bars on chart, run on every bar:
    Code:
    for (var i=0; i<CurrentBars[1]; i++)
    {
    if (Opens[1][i] > 100)
    {
    // execute code
    Print(Opens[1][i]);
    }
    }
    For all bars within today's bar, run once on the last historical bar (you can have other code for each live bar):
    Code:
    if (Historical && CurrentBars[1] == BarsArray[1].Count-2)
    {		
    for (var i=CurrentBars[1]; i>=BarsArray[1].GetBar(Times[0][0].AddMinutes(1)); i--)
    {
    if (Opens[1][CurrentBars[1]-i] > 100)
    {
    // execute your code
    Print(Times[1][CurrentBars[1]-i] + " - Open: " + Opens[1][CurrentBars[1]-i]);
    }
    }
    }
    I would also make sure that you are running this on one BarsInProgress.

    As far as if this is run on each bar or on the last historical bar, you can use either. I just wanted to demonstrate both.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      what about to run the calculation directly on SECONDARY 60-min bar time series (within BarsInProgress == 1 block? No loops needed.

      PROBLEM 1:
      I don't know how to display result on PRIMARY plot.
      My drawing buffers are inserted like this:
      Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Dot, "DailyPlot"));

      So again (now running on secondary 60-min series using BarsInProgress == 1 block)
      if (Opens[1][0] > 100) DailyPlot[0] = 1; Is it possible?

      PROBLEM 2:
      The same for Dataseries added like this:
      private DataSeries Trend;

      It contains the same number of elements as bars in a chart, but I need number of elements equal to SECONDARY bars!

      Thanks for help
      Peter
      Last edited by Peter Cherry; 04-14-2014, 09:24 AM.

      Comment


        #4
        Hello Peter,

        It depends on what you are trying to do.

        You can choose to have the code run on the 60 minute BarsInProgress. It would then run once per 60 minute bar.

        You could then change a variable if a value over 100 is detected and then use this variable in the BarsInProgress for the daily bar.

        For example:

        in #region Variables:
        private bool over100 = false;

        if (BarsInProgress == 1)
        {
        if (Open[0] > 100)
        {
        over100 = true;
        }
        }

        if (BarsInProgress == 0)
        {
        if (over100 == true)
        {
        // execute code
        }
        }

        Also, yes it is possible synchronize an added custom data series to a secondary instrument by using the BarsArray with the proper index. You would probably want to do this in OnStartup with BarsArray[1].

        Below is a link to a reference sample that demonstrates this.
        http://www.ninjatrader.com/support/forum/showthread.php?t=3572
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,
          now I experience strange behavior. I wrote the following test within BarsInProgress == 1 (60-min block):

          if (Opens[1][0] > 1845) //any 60-min open during the day
          {
          Print(Times[0][0]); //Primary 1day bar
          Print(Times[1][0]); //Secondary 60min bar
          }

          Look at the screenshot. It is not true, that any price open was higher than 1845 on 21.2.2014 (see the screenshot).

          Peter
          Attached Files

          Comment


            #6
            Hi Peter Cherry,

            Try the following print:


            Print("\r\nOpen BIP1: "+Opens[1][0]+" > "+1845);
            if (Opens[1][0] > 1845) //any 60-min open during the day
            {
            Print(Times[0][0]); //Primary 1day bar
            Print(Times[1][0]); //Secondary 60min bar
            }

            Please let me know what prints.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello ChelseaB,
              it prints the following (run on Daily ES 06-14 chart):
              I agree 1848,50 > 1845 on 24.2.214 but why Times[0][0] prints 21.2.2014 Daily bar?
              .
              .
              .
              Open BIP1: 1831 > 1845
              Open BIP1: 1841,25 > 1845
              Open BIP1: 1843,5 > 1845

              Open BIP1: 1848,5 > 1845
              21.2.2014 23:15:00
              24.2.2014 19:00:00

              Open BIP1: 1847,25 > 1845
              21.2.2014 23:15:00
              24.2.2014 20:00:00

              Open BIP1: 1845,25 > 1845
              21.2.2014 23:15:00
              24.2.2014 21:00:00

              Open BIP1: 1845,25 > 1845
              21.2.2014 23:15:00
              24.2.2014 22:00:00

              Open BIP1: 1837,5 > 1845
              Open BIP1: 1837,5 > 1845
              .
              .
              .
              Attached Files

              Comment


                #8
                Hi Peter Cherry,

                With Calculate on bar close set to True, Times[0][0] references the most completed daily bar.

                On February 24th (a Monday) the most completed daily bar is from the previous Friday (Feb 21st).

                (edit)
                If you are wanting to use the open, high, or low of the current day use the CurrentDayOHL() indicator.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ChelseaB,
                  clear, but I have CalculateOnBarClose = false !

                  The practical consequence of this problem is color line change (from blue to yellow) one day ahead of the actual condition (see the screenshot). This is part of the code (within BarsInProgress = 1 section):

                  if (Opens[1][0] > 1845)
                  {
                  Print(Times[0][0]);
                  Print(Times[1][0]);

                  BlueTmp[0]=0;
                  YellowTmp[0]=1845;

                  }
                  Line[0]= YellowTmp[0]; //Plot on the chart created by Add(new Plot......)
                  Attached Files

                  Comment


                    #10
                    Hi Peter Cherry,

                    Are you backtesting this or running it through the Market Replay?

                    Calculate on bar close is always true in historical data.

                    This is mentioned in the help guide under CalculateOnBarClose.
                    http://www.ninjatrader.com/support/h...onbarclose.htm


                    As I mentioned before, if you want the current day's OHL use the CurrentDayOHL indicator with the bar data of the secondary series.

                    For example:

                    if (CurrentDayOHL(BarsArray[1]).CurrentOpen[0] > Opens[0][0])
                    {
                    // execute code
                    }
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi,
                      you are right, I am running the chart script on historical data.

                      I don't want to access current day's OHLC (it was just demonstrative example).
                      What I want is to display yellow line starting from proper day and not a day before as you can see on MTF problem III.jpg

                      Why this line from code above draw the yellow chart a one day before the actual condition?
                      Line[0]= YellowTmp[0]; //Plot on the daily chart created by Add(new Plot......)

                      Comment


                        #12
                        Hi Peter Cherry,

                        I'm not really able to discern anything from this screenshot.

                        What day does the print show that its triggered on?

                        What day does the color change on the chart (there are no dates in the screenshot).

                        What bars in progress is the plot being set on?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi ChelseaB,
                          but it is still the same, the whole problem is described again and again within this thread and documented on all 3 screenshots!

                          if (BarsInProgress == 1)
                          {
                          if (Opens[1][0] > 1845)
                          {
                          Print(Times[0][0]);
                          Print(Times[1][0]);
                          YellowTmp[0] = 1845;
                          }
                          }

                          Open BIP1: 1848,5 > 1845
                          21.2.2014 23:15:00
                          24.2.2014 19:00:00

                          As you wrote: "On February 24th (a Monday) the most completed daily bar is from the previous Friday (Feb 21st)."

                          Is this reason, why the yellow line starts one day before the actual condition is met?

                          if (BarsInProgress == 0)
                          Line[0]= YellowTmp[0]; //Plot on the daily chart created by Add(new Plot......)

                          Thanks
                          Peter
                          Attached Files

                          Comment


                            #14
                            Hello Peter Cherry,

                            May I have an export of your script so that I may test this on my end?

                            To export your script do the following:
                            1. Click File -> Utilities -> Export NinjaScript
                            2. Enter a unique name for the file in the value for 'File name:'
                            3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                            4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                            By default your exported file will be in the following location:
                            • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                            Below is a link to the help guide on Exporting NinjaScripts.
                            http://www.ninjatrader.com/support/h...nt7/export.htm

                            Are you testing this on the ES?

                            What time zone are you in? (I ask because the ES starts trading on Sunday at 5:00 Central in the US meaning you should be getting a yellow print on Sunday)
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi,
                              here you have exported example. Chart script run on ES. My timezone is Europe.
                              Thanks
                              Peter
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X