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

Loading days in the indicator regardless of the chart

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

    Loading days in the indicator regardless of the chart

    Loading days in the indicator regardless of the chart

    Hello everyone, there was a task to implement loading of days in the indicator regardless of the chart

    Using an additional data series with a time pattern (I added data series)

    Code:
    AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, "Forex");
    Indicated that the code is being executed for the second data series

    Code:
    if (BarsInProgress == 1)
    in order to avoid drawing breaks on timeframes like tick and range, indicated that we are drawing on the first data series (chart data series)

    Code:
    if (BarsInProgress == 0)
    {
    
    Values[0][0] = (iCumTypicalVolume / iCumVolume);
    }
    }
    Please tell me what's next? how I can implement this task?

    Thanks in advance.

    Here is my indicator code

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class VWAP8 : Indicator
    {
    double iCumVolume = 0;
    double iCumTypicalVolume = 0;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Volume Weighted Average Price";
    Name = "VWAP8";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = false;
    DrawOnPricePanel = false;
    DrawHorizontalGridLines = false;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = false;
    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(new Stroke(Brushes.SpringGreen, DashStyleHelper.Solid, 5), PlotStyle.Line, "VWAP");
    
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, "Forex");
    }
    
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1)
    {
    
    if (Bars.IsFirstBarOfSession)
    {
    iCumVolume = VOL()[0];
    iCumTypicalVolume = VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3);
    }
    else
    {
    iCumVolume = iCumVolume + VOL()[0];
    iCumTypicalVolume = iCumTypicalVolume + (VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3));
    }
    }
    
    if (BarsInProgress == 0)
    {
    
    Values[0][0] = (iCumTypicalVolume / iCumVolume);
    }
    }
    
    #region Properties
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> PlotVWAP
    {
    get { return Values[0]; }
    }
    #endregion
    
    }
    }
    Last edited by memonolog; 11-29-2020, 02:48 AM.

    #2
    Hello memonolog,

    Use the int barsToLoad overload with AddDataSeries() and custom calculate a number of bars for the number of days you would like.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello memonolog,
      custom calculate a number of bars for the number of days you would like
      I added a series of data with the number of bars, I need help further, I don't quite understand how to find out the number of bars per day

      Code:
       AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, 100, "Forex", true);
      Don't know how to implement this, there is an example where it is implemented?
      Last edited by memonolog; 11-30-2020, 12:43 AM.

      Comment


        #4
        Hello memonolog,

        A day has 1440 minutes in it. You could try using multiples of 1440 as the barsToLoad.

        AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, 2880, "Forex", true);

        This will depend on how many bars you want to load.

        Also, it is not supported to use Instrument.FullName in State.Configure. Use null instead as directed in the help guide Tip #4.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello memonolog,

          A day has 1440 minutes in it. You could try using multiples of 1440 as the barsToLoad.

          AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }, 2880, "Forex", true);

          This will depend on how many bars you want to load.

          Also, it is not supported to use Instrument.FullName in State.Configure. Use null instead as directed in the help guide Tip #4.
          Thanks, for a minute is clear, but if it is range bars or Tick. how then to solve the Task?

          Comment


            #6
            Hello memonolog,

            The amount of ticks in a day will vary. I would recommend trying a high number, and then check the date of Times[1][0] on the first bar, and adjust accordingly.

            I will also add your vote to feature request SFT-4583, 'Way to specify the amount of days to load for AddDataSeries'.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GussJ, 03-04-2020, 03:11 PM
            12 responses
            3,239 views
            0 likes
            Last Post Leafcutter  
            Started by AveryFlynn, Today, 04:57 AM
            0 responses
            5 views
            0 likes
            Last Post AveryFlynn  
            Started by RubenCazorla, 08-30-2022, 06:36 AM
            3 responses
            79 views
            0 likes
            Last Post PaulMohn  
            Started by f.saeidi, Yesterday, 12:14 PM
            9 responses
            25 views
            0 likes
            Last Post f.saeidi  
            Started by Tim-c, Today, 03:54 AM
            0 responses
            5 views
            0 likes
            Last Post Tim-c
            by Tim-c
             
            Working...
            X