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 Indicator based on Range

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

    Multi Time Frame Indicator based on Range

    I have simple MTF Indicators (SMA and EMA) based on Range. How it is possible that sometimes when I use data from 15 days my Indicators are in a chart (for example GC , 12 Better Renko chart), but when I give some other value for example 30 days of data they disappear from a chart L.
    Maybe somebody who develops indicators knows how to fix it?
    My code for EMAclose based on Range is:
    PHP Code:
    protected override void Initialize()
    {
    Add(new Plot(Color.GreenPlotStyle.Line"Plot0"));
    Add(PeriodType.Rangerange); 
    Overlay true;
    PriceTypeSupported true;
    //AutoScale = false;
    BarsRequired 20;


    }
     
     
    protected 
    override void OnBarUpdate()
    {
    Value.Set(CurrentBar == Input[0] : Input[0] * (2.0 / (Period)) + (- (2.0 / (Period))) * Value[1]);

     
    if(
    CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
    return; 

     
    Plot0.Set(Closes[1][0]);

    Thanks in advance

    #2
    Hello,

    Thanks for the note.

    You need to make sure you are loading enough data for the indicator to be able to function.

    In this case it most likely is more then 30 bars, try increasing this to see if you can get it to replot.

    Finally, what is the error in the log tab in the Control Center.

    -Brett

    Comment


      #3
      MTF Indic based on Range

      I don't have any errors now when I load, before I was had this error:
      Error on calling 'OnBarUpdate' method for indicator 'EMAmtfRangeClose' on bar 1: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      I change the value for Bars Required to 50, but I don’t think that is the problem, because 30 days are more data than 15 days – more bars.

      Any other idea ?

      Comment


        #4
        Hello,

        What type of Range and Renko bars are you using what periods?

        Also since you are not getting the log error anymore is it now plotting?

        -Brett

        Comment


          #5
          mtf indiactors

          Indicators are based on Range 13, chart is GC 04-12, BetterRenko 12.
          I don't have any error when I'm adding indicators to a chart.
          Like before I don't have plots on 30 days chart, but I have it on 15 days.

          Comment


            #6
            Hello,

            Can you please post full code as a .cs file from the MyDocuments->NinjaTrader7->bin->custom->indicators->InidcatorName.cs so that I can give this a quick run on my side. Normally we do not debug for clients however I will take a quick run to see if I can see anything obvious.

            -Brett

            Comment


              #7
              mtf indicators

              I put does indicators as attachments, but if you prefer code directly, you have it below:

              publicclassEMAmtfRangeClose : Indicator
              {
              #region Variables
              privateint period = 13;
              privateint range = 13;
              #endregion
              ///<summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              ///</summary>
              protectedoverridevoid Initialize()
              {
              Add(
              new Plot(Color.Green, PlotStyle.Line, "Plot0"));
              Add(PeriodType.Range, range);
              Overlay =
              true;
              PriceTypeSupported =
              true;
              //AutoScale = false;//
              BarsRequired = 50;//


              }

              ///<summary>
              /// Called on each bar update event (incoming tick)
              ///</summary>
              protectedoverridevoid OnBarUpdate()
              {
              Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);

              if(CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
              return;

              Plot0.Set(Closes[1][0]);
              }
              Attached Files

              Comment


                #8
                Hello wlodi,
                Thanks for the code and I am replying for Brett.

                Unfortunately I couldn’t replicate the issue, but you can have an situation where the secondary bar series is yet to form (though the primary series might have more bars that BarsRequired) and if you call the Closes[1][0] then you will get an index out of range error.

                The issue may vary depending on how the bars are made, and not how much data is being loaded.

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

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                40 views
                0 likes
                Last Post jeronymite  
                Started by bill2023, Today, 08:51 AM
                2 responses
                16 views
                0 likes
                Last Post bill2023  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                167 responses
                2,260 views
                0 likes
                Last Post jeronymite  
                Started by warreng86, 11-10-2020, 02:04 PM
                7 responses
                1,362 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Perr0Grande, Today, 08:16 PM
                0 responses
                5 views
                0 likes
                Last Post Perr0Grande  
                Working...
                X