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

Plotting Multiple Timeframes

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

    Plotting Multiple Timeframes

    I can not get the code below to work. I am trying to load it on a 1 minute chart. I get an "Index was outside the bounds of the array" error. If I comment out the line:

    Plot2.Set(dateTime2[0])

    the momentum for the first BarsArray plots correctly. If I then change

    Plot1.Set(dateTime1[0]) to Plot1.Set(dateTime2[0])

    it plots out the second BarsArray.

    Why does Plot2.Set cause an error? I'm sure there is something simple I am missing.... Thanks

    PHP Code:
    public class MutliTimeframePlot Indicator
    {
      
    #region Variables
      
    private DataSeries dataTime1;
      private 
    DataSeries dataTime2;
      
    #endregion
    protected override void Initialize()
    {
      
    Add(PeriodType.Minute5);
      
    Add(PeriodType.Minute15);
     
      
    dataTime1 = new DataSeries(this);
      
    dataTime2 = new DataSeries(this);
     
      
    CalculateOnBarClose true;
      
    Overlay false;
    }
    protected 
    override void OnBarUpdate()
    {
      if (
    BarsInProgress == 0)
      {
        if (
    CurrentBar 100) return;
        
    dataTime1[0] = Momentum(BarsArray[1], 14)[0];
        
    dataTime2[0] = Momentum(BarsArray[2], 14)[0];
        
    Plot1.Set(dataTime1[0]);
        
    Plot2.Set(dataTime2[0]);
    }
    if (
    BarsInProgress == 1)
    {
    }
    if (
    BarsInProgress == 2)
    {
    }
    }
    #region Properties
    [Browsable(false)]
    [
    XmlIgnore()] 
    public 
    DataSeries Plot1
    {
      
    get { return Values[0]; }
    }
     
    [
    Browsable(false)]
    [
    XmlIgnore()] 
    public 
    DataSeries Plot2
    {
      
    get { return Values[1]; }
    }
    #endregion

    The Trading Mantis
    NinjaTrader Ecosystem Vendor - The Trading Mantis

    #2
    Greg, Plot1 would always relate normally to the primary indicator value series...I didn't see you defining any Plots in the Intialize() of your code, please add those for Plot1 and 2 and then retry.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      That was it, thanks Bertrand.

      Just curious, why does Plot1 still plot on the chart without any Plot statements in Initialize()?
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment


        #4
        Great, this is 'linked' to your Value series, hence this will always be defined per default - http://www.ninjatrader-support.com/H...AndValues.html
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        2 responses
        21 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by DayTradingDEMON, Today, 09:28 AM
        0 responses
        1 view
        0 likes
        Last Post DayTradingDEMON  
        Started by navyguy06, Today, 09:28 AM
        0 responses
        1 view
        0 likes
        Last Post navyguy06  
        Started by rjbtrade1, 11-30-2023, 04:38 PM
        2 responses
        77 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        7 responses
        31 views
        0 likes
        Last Post cmtjoancolmenero  
        Working...
        X