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 plot two time frames of an indicator?

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

    How do you plot two time frames of an indicator?

    Hi,
    I am trying to plot the 10 period SMA on a 50 tick chart along with the 10 period SMA for 150 tick bars on the same chart. I would like to see two SMA lines on the 50 tick chart. One line representing a 50 tick SMA and the other line representing the 150 tick SMA. I plan on adding more to this indicator once it is working so I need to create a multi-time frame indicator.

    Here is my code which DOES plot the first dataseries correctly on the 50 tick chart. But the second dataseries (BarsInProgress == 1), does not plot.

    I get a CS0103 error on the last line of code below:

    "The name 'Plot1' does not exist in the current context"


    Thanks in Advance for your help!

    protectedoverridevoid Initialize()
    {
    // CHART TIME FRAME IS 50 TICKS

    // ADD SECOND TIMEFRAME
    Add(PeriodType.Tick, 150);


    // ADD PLOTS FOR SMA LINES
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "Plot0"));
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Magenta), PlotStyle.Line, "Plot1"));


    CalculateOnBarClose = true;
    Overlay =
    true;
    }

    protectedoverridevoid OnBarUpdate()
    {

    // Checks to ensure all Bars objects contain enough bars before beginning
    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired)
    return;


    // Checks if OnBarUpdate() is called from an update on the chart's 50 tick dataseries
    if (BarsInProgress == 0)
    {
    double val_SMA = SMA(Close, r)[0];

    Plot0.Set(SMA(Close,
    10)[0]);
    }

    // Checks if OnBarUpdate() is called from an update on the second set of Bars (150 TICK)
    if (BarsInProgress == 1)
    {

    double val_SMA = SMA(Close, r)[0];

    Plot1.Set(SMA(Close,
    10)[0]);
    }
    }

    #2
    Welcome to our forums, please expand the 'Properties' section of the indicator - is the Plot1 public property added there as well or do you only see Plot0 defined?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      WhiteRhino,
      I have an indicator that does what you want.....
      (it also does a few other things as well)

      Let me 'clean up' the code and remove the other processes, and I will post it on the Ninja Forum.

      Comment


        #4
        Thanks I look forward to it any help you can offer. I edited and attached my simple SMA script here. Hopefully the error is easy for you to see. Right now, the indicator does not show up on the chart in any time frame.
        Attached Files
        Last edited by whiterhino; 02-20-2011, 01:02 AM.

        Comment


          #5
          Originally posted by whiterhino View Post
          Thanks I look forward to it any help you can offer. I edited and attached my simple SMA script here. Hopefully the error is easy for you to see. Right now, the indicator does not show up on the chart in any time frame.
          For one thing, you are not correctly accessing the price data of your series. To set Plot1, for example, instead of:

          Plot1.Set(SMA(Close, sMAperiod)[0]);

          You should be using:

          Code:
          Plot1.Set(SMA(Closes[1], sMAperiod)[0]);
          and so on, so that you are accessing the correct Bar series. This should be plotted on the primary series if you want it to show on the chart.

          Comment


            #6
            whiterhino, I cleaned the indicator up a bit, should work for you now - plotting from BIP0 only.
            Attached Files
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks Bertrand and Koganam. I loaded the file provided from Bertrand and it works fine. Curious though as to when the BarsinProgress property should be used as it is not used in Bertrand's version of my cs?

              Comment


                #8
                Uploaded the indicator into Ninja Indicators section.... called xcMovAvg.
                Selectable by moving average type...(SMA,EMA, HMA, WMA) as well as selectable alternate chart time frames (Minute, Tick, Range). Plots are configurable (color, line width, dashstyle, etc.) You can select the desired input period (Open, High, Low, Close, Median, etc. in the indicator properties).

                Comment


                  #9
                  Thanks photog53, I look forward to checking it out. Sounds good!

                  Comment


                    #10
                    Thank you so much for xcMovAvg.

                    When I apply 60 minutes 20 EMA on 5 minutes chart, the moving average line only goes to 15:35 bar, not all the way to 16:00 bar, I set the Calculate on bar close: False. Could you please advise to correct this on my chart?

                    Happy New Year!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by GussJ, 03-04-2020, 03:11 PM
                    15 responses
                    3,271 views
                    0 likes
                    Last Post xiinteractive  
                    Started by Tim-c, Today, 02:10 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Taddypole, Today, 02:47 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Taddypole  
                    Started by chbruno, 04-24-2024, 04:10 PM
                    4 responses
                    51 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by TraderG23, 12-08-2023, 07:56 AM
                    10 responses
                    403 views
                    1 like
                    Last Post beobast
                    by beobast
                     
                    Working...
                    X