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 never entering the extra dataseries

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

    MTF never entering the extra dataseries

    Hi
    I have created the simple pivot indicator below. The calculations and everything work fine but there is one issue, which is that the script never seems to enter the
    Code:
    if(BarsInProfgress ==1 )
    block especially historical. I have read the section on MTH indicators in the help guides / references but do not seem to be able to figure out why that black is not called historically.

    Code:
    public class CarterPivot : Indicator
    {
    double r1, r2, r3;
    double s1, s2, s3;
    double pivot;
    
    double high, low, close;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "CarterPivot";
    Calculate = Calculate.OnBarClose;
    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;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    }
    else if(State == State.DataLoaded)
    {
    high = BarsArray[1].GetHigh(BarsArray[1].Count - 2);
    low = BarsArray[1].GetLow(BarsArray[1].Count - 2);
    close = BarsArray[1].GetClose(BarsArray[1].Count - 2);
    }
    
    }
    
    protected override void OnBarUpdate()
    {
    if(CurrentBar<3)
    return;
    
    if (BarsInProgress == 0)
    {
    pivot = (high + low + close) / 3;
    r1 = 2 * pivot - low;
    s1 = 2 * pivot - high;
    
    r2 = pivot + (high - low);
    s2 = pivot - (high - low);
    
    r3 = r1 + (high- low);
    s3 = s1 - (high - low);
    
    int barsSince = Bars.BarsSinceNewTradingDay;
    
    Draw.Line(this, CurrentBar+"r1", barsSince, r1, 0, r1, Brushes.Yellow);
    Draw.Line(this, CurrentBar+"s1", barsSince, s1, 0, s1, Brushes.Yellow);
    
    Draw.Line(this, CurrentBar+"r2", barsSince, r2, 0, r2, Brushes.Orange);
    Draw.Line(this, CurrentBar+"s2", barsSince, s2, 0, s2, Brushes.Orange);
    
    Draw.Line(this, CurrentBar+"pivot", barsSince, pivot, 0, pivot, Brushes.White);
    }
    
    if (BarsInProgress == 1)//Day
    {
    high = BarsArray[1].GetHigh(BarsArray[1].Count - 2);
    low = BarsArray[1].GetLow(BarsArray[1].Count - 2);
    close = BarsArray[1].GetClose(BarsArray[1].Count - 2);
    
    
    }
    
    Print(high+" "+low+" " +close);
    //Print(BarsArray[1].GetHigh(BarsArray[1].Count - 1) + " "+BarsArray[1].GetHigh(BarsArray[1].Count - 2));
    
    }
    }

    #2
    Hello SuneSorgenfrei,

    Thank you for the post.

    From the given code I don't see anything that looks specifically wrong. For this type of a concern I would suggest to do a few simple tests to see where the problem starts.

    First open a chart with daily bars and load a month or however much data your item would generally require, verify the data is present.

    Try commenting out the prints you have now and add the following as the first line of OnBarUpdate:

    Code:
    protected override void OnBarUpdate()
    {
        Print(BarsInProgress);
    You should see 0's and 1's in the output if BIP 1 is getting called. I don't see a print in your condition now to verify its being called so this would be the easiest way to confirm its being called or not.

    If you see its not being called check how many days to load you are using and try using more, for example if you were using 5 days try using 30 or more.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse
      I have tried to put the
      Code:
      Print(BarsInProgress);
      in the OnBarUpdate method but only BarsInProgress == 0 is printed. I have also loaded 30 days of data instead of 5, but no change.
      I have added the indicator to an 60 minute chart (just for info)

      Best Regards,
      Sune

      Comment


        #4
        Hello SuneSorgenfrei,

        Were you able to verify the daily data is present by opening a daily chart for that time period? You may want to try doing a reload historical data from the daily chart to refresh the local cache before retesting the print.

        And to confirm, you placed the print as the first line in OnBarUpdate before your other conditions correct?


        I don't see anything specific which would prevent the secondary series from being called. You could additionally try removing the DataLoaded logic, DataLoaded is not a suggested location to work with price data. The code you have there could be placed in OnBarUpdate in the BarsInProgress 1 condition and within another condition checking if CurrentBar == 0. For testing you could simply remove that logic, compile and then remove/reapply the indicator.

        I look forward to being of further assistance.


        JesseNinjaTrader Customer Service

        Comment


          #5
          HI
          It works now, I am not totally sure why it all the sudden works, but I ended up closing the chart and creating a new one and adding the indicator and then it worked.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AdamDJ8, Today, 09:18 PM
          0 responses
          2 views
          0 likes
          Last Post AdamDJ8
          by AdamDJ8
           
          Started by knowmad, Today, 03:52 AM
          2 responses
          26 views
          0 likes
          Last Post knowmad
          by knowmad
           
          Started by ETFVoyageur, Today, 07:05 PM
          0 responses
          9 views
          0 likes
          Last Post ETFVoyageur  
          Started by Orion815, 05-02-2024, 08:39 AM
          2 responses
          18 views
          0 likes
          Last Post Orion815  
          Started by suroot, 02-25-2017, 04:43 AM
          11 responses
          2,554 views
          0 likes
          Last Post Zilvercat  
          Working...
          X