Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

spread

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

    spread

    Hello i havet this and is working but i need to do the natural logarithm to the two series and i cant because the graph do not work. Can anybody help me?


    public class SpreadOscillator : Indicator
    {
    private string firstInstrument = @"ES 12-15";
    private string secondInstrument = @"NQ 12-15";
    private int maPeriod = 100;
    private int devMult = 3;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Shows the current spread between two symbols and its deviation channel. TASC October 2013";
    Name = "SpreadOscillator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    AddPlot(new Gui.Stroke (Brushes.DimGray, Gui.DashStyleHelper.Solid, 2), PlotStyle.Line, "Spread");
    AddPlot(new Gui.Stroke (Brushes.DarkOrange, Gui.DashStyleHelper.Solid, 2), PlotStyle.Line,"SMAMid");
    AddPlot(new Gui.Stroke (Brushes.DarkBlue, Gui.DashStyleHelper.DashDotDot, 2), PlotStyle.Line,"Upper");
    AddPlot(new Gui.Stroke (Brushes.DarkBlue, Gui.DashStyleHelper.DashDotDot, 2), PlotStyle.Line,"Lower");
    }
    else if (State == State.Configure)
    {
    AddDataSeries(FirstInstrument, Data.BarsPeriodType.Minute, BarsPeriod.Value, Data.MarketDataType.Last);
    AddDataSeries(SecondInstrument, Data.BarsPeriodType.Minute, BarsPeriod.Value, Data.MarketDataType.Last);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot || CurrentBars[2] < BarsRequiredToPlot)
    return;

    double FirstValue = (Closes[1][0] * Instruments[1].MasterInstrument.PointValue)-(Closes[1][1] * Instruments[1].MasterInstrument.PointValue);
    double SecondValue = (Closes[2][0] * Instruments[2].MasterInstrument.PointValue)-(Closes[2][1] * Instruments[2].MasterInstrument.PointValue);
    Spread[0] = (FirstValue)-(SecondValue) ;
    SMAMid[0] = (SMA(Spread, MAPeriod)[0]);
    Upper[0] = (SMAMid[0] + DevMult * StdDev(Spread, MAPeriod)[0]);
    Lower[0] = (SMAMid[0] - DevMult * StdDev(Spread, MAPeriod)[0]);

    }

    #2
    Hello Auxtin Maquieyra,

    Thanks for opening the thread.

    I noticed that you are adding additional DataSeries using input parameters. This is not advised as Instrument and Input parameters may not be guaranteed in State.Configure. This can have particular issues when a strategy adds the indicator as the hosting strategy will also have to add those data series and there are further issues with optimization backtests. Because of such issues, we would not support adding data series' dynamically. Other indicators have been made using this approach, so you may be able to find a solution that works enough for your needs. Please see documentation on AddDataSeries() for more information.

    Keep in mind that any existing implementations are provided as-is, and we would not be able to provide support for encountering the mentioned limitations in the help guide.

    We are tracking interest to support adding data series dynamically like you could do in NinjaTrader 7. I will submit a vote for the feature request on your behalf. This feature request has ticket ID SFT-882. Feature requests are fulfilled based on our development team's schedule and priorities and we cannot provide a time frame for it to become available.

    We could support an implementation that has these additional DataSeries hardcoded. If you would like to see if the indicator will work well enough with a parameter for each data series, I would recommend adding parameters for the AddDataSeries() after you have gotten the indicator working following supported approaches.

    After hard coding the DataSeries as suggested in the help guide, can you confirm that you are receiving data to perform the calculation?

    Natural logarithms can be applied with Math.Log().

    After these steps are you still encountering issue? Could you elaborate on what you mean exactly by "because the graph do not work?"

    Publicly available reference for AddDataSeries() can be found here: https://ninjatrader.com/support/help...dataseries.htm

    I look forward to being of any further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    81 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    149 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    79 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    52 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    59 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X