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

MTF Ploting

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

    MTF Ploting

    Hi all,

    Im trying to develop a MTF indicator that plots data from higher timeframes.
    I wanted to start simple to test MTF functionality but Im lost.

    I already searched and read here and bigmike forums but cannot find the path.

    I have the following code, but I cannot see any line ploted:

    Code:
    protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.AppWorkspace), PlotStyle.Line, "M15"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "H1"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "H4"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "D1"));
    			
    			Add(PeriodType.Minute, 60);
    			Add(PeriodType.Minute, 240);
    			Add(PeriodType.Day, 1);
                Overlay				= true;
            }
    
         
            protected override void OnBarUpdate()
            {
                
            M15.Set(SMA(BarsArray[0],20)[0]);
    		H1.Set(SMA(BarsArray[1],20)[0]);
            H4.Set(SMA(BarsArray[2],20)[0]);
            D1.Set(SMA(BarsArray[3],20)[0]);
            }
    Thanks in advance

    #2
    P.D. I loaded 90 days of data, so the needed bars are there

    Comment


      #3
      Hello dotnetfreak,

      Thank you for your post and welcome to the NinjaTrader Support Forum!

      You will need to add a check for the bars needed, in this case 20 as the SMA is using a 20 period. The code at the beginning of your OnBarUpdate() needs to reflect the following:
      Code:
      if(CurrentBars[0] <= 20 || CurrentBars[1] <= 20 || CurrentBars[2] < = 20)
      return;
      For information on CurrentBars please visit the following link: http://www.ninjatrader.com/support/h...urrentbars.htm

      And for information on ensuring you have enough data before accessing it please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

      Please let me know if you have any questions.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by trilliantrader, Yesterday, 03:01 PM
      3 responses
      29 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      4 responses
      25 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Brevo, Today, 01:45 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rjbtrade1, 11-30-2023, 04:38 PM
      2 responses
      74 views
      0 likes
      Last Post DavidHP
      by DavidHP
       
      Started by suroot, 04-10-2017, 02:18 AM
      5 responses
      3,022 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X