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

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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Brevo, Today, 01:45 AM
    0 responses
    6 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    3 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    384 views
    1 like
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    6 views
    0 likes
    Last Post oviejo
    by oviejo
     
    Working...
    X