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

Multiple Time frame Indicator

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

    Multiple Time frame Indicator

    Good evening all,

    I am trying to develop an indicator on a 60min chart with some additional criteria on the daily chart. With the current code I am able to get it to plot and though a signal on the daily chart but not on a 60min chart which is what I am looking for. Any help would be greatly appreciated. Thanks so much, Ryan.


    ​protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "GapDown2percent";
    Calculate = Calculate.OnEachTick;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    AddPlot(Brushes.Blue, "Signal");
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    {
    if (CurrentBar < 5)
    return;

    if (

    //Gap down 2%
    Opens[1][1] < (Closes[1][2] * .98) &&

    //Gap down clearing yesterdays Low
    Opens[1][1] < Lows[1][2] &&
    Closes[0][0] < Highs[1][1]

    )

    {
    Draw.ArrowUp(this, "MyArrow" + CurrentBars[0], true, 0, Lows[0][0] - (2 * TickSize), Brushes.RoyalBlue);
    Value[0] = 1;
    }

    else
    {
    Value[0] = 0;
    }
    }
    }​

    #2
    Hello Tonkingrf1551,

    With the code you provided you would need the primary to be the 60 minute series so using a 60 minute chart is where you would be plotting.

    You used AddDataSeries to add a daily series which you are using from OnBarUpdate Opens[1][1].

    This code is currently being executed for both the daily and 60 minute series. To make sure the plot matches the primary series slots you can use

    Code:
    if (BarsInProgress > 0) return;
    That will stop the OnBarUpdate from being called for the daily series to limit plotting/drawing to the 60 minute series.

    Last edited by NinjaTrader_Jesse; 09-28-2022, 07:47 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for the response, It seems have to same issue but it will plot on the 60min chart and the daily chart not with the code: if (BarsInProgress == 0) return; but not with ">"

      When looking up BarsInProgess in the help guide it gives an example separating action by different bar periods. I am looking to have only one action based on both time periods

      Sorry if this doesn't make a lot of sense I am still trying to figure this out.

      How would I code an action based on if statements for both index 0 and 1?

      Would the code if (BarsInProgress == 0) return; be correct then?

      Thank you again for all the help

      Comment


        #4
        Hello Tonkingrf1551

        Using if (BarsInProgress == 0) return; means that OnBarUpdate won't be called for the primary series. I had suggested to try plotting only during the primary series OnBarUpdate calls to see if that helps.

        Are you otherwise seeing an error in the log tab or in the NinjaScript output window?

        JesseNinjaTrader Customer Service

        Comment


          #5
          When I added the line of code you suggest nothing changed, the indicator was still printing on the daily and not on the 60min chart. Thanks Ryan

          Comment


            #6
            Hello Tonkingrf1551,

            Are you seeing an error when you use it on the 60 minute chart? If not you will need to add Prints into your script to see if the logic is being run or what else may be happening.

            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            19 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            45 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            180 views
            0 likes
            Last Post jeronymite  
            Working...
            X