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

Problems with multi time frames

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

    Problems with multi time frames

    Hello, I am trying to programm an Indicator with ES 03-11 3minutes as the main Instrument and ^COMP 5 minute as secondary instrument. The problem that I have is that when I include a condition of second instrument the indicator is not displayed on the panel on instrument 1. The code is the following:

    Any idea about what I am doing wrong?

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Up"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Gray), PlotStyle.Line, "Down"));
    Add(new Line(Color.FromKnownColor(KnownColor.Red), 2, "Superior"));
    Add(new Line(Color.FromKnownColor(KnownColor.Red), 0.5, "Inferior"));
    Overlay = false;


    Plots[0].Max = 2;
    Plots[0].Min = 0.5;
    Plots[1].Min = 2;
    Plots[2].Max = 0.5;

    Add("^COMP",PeriodType.Minute,5);

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (BarsInProgress==1) return;
    if (CurrentBar<14) return;

    double value = ATR(13)[0];
    Plot0.Set(value);
    Up.Set(value);
    Down.Set(value);


    if(Closes[1][0]>SMA(BarsArray[1],5)[0] && Closes[1][1]<=SMA(BarsArray[1],5)[1] && Closes[1][0]>Opens[1][0])
    {
    DrawArrowUp("UP"+i,0,Low[0]-5*TickSize,Color.Orange);
    i++;
    }
    }

    #2
    Hi again,

    I worked it out . The problem was that I forgot to include:

    if (CurrentBars[1]<5) return; in order to assure that there are enough bars for the calculations on Instrument 1 (COMP).

    I leave the post open just in case it is useful for anyone...

    Comment


      #3
      Hello,

      Thanks for posting solution for everyone to benifit! and glad you where able to figure out.

      Let me know if I can be of further assistance.

      Comment


        #4
        Originally posted by Sangui View Post
        Hi again,

        I worked it out . The problem was that I forgot to include:

        if (CurrentBars[1]<5) return; in order to assure that there are enough bars for the calculations on Instrument 1 (COMP).

        I leave the post open just in case it is useful for anyone...
        F...ing A! You just fixed my problem. I was testing for CurrentBars only but not for CurrentBars[1] for instance - which I do have as I am building a multi instrument indicator. Thanks for pointing me in the right direction, mate! :-)

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jclose, Today, 09:37 PM
        0 responses
        5 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,414 views
        0 likes
        Last Post Traderontheroad  
        Started by firefoxforum12, Today, 08:53 PM
        0 responses
        11 views
        0 likes
        Last Post firefoxforum12  
        Started by stafe, Today, 08:34 PM
        0 responses
        11 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by sastrades, 01-31-2024, 10:19 PM
        11 responses
        169 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X