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

AddDataSeries not working as I expect.

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

    AddDataSeries not working as I expect.

    Hello all,

    The indicator I programed works perfect with the the default dataseies instrument. Based on the default instrument, Volume variable works as a trigger to make all the extra calculations.

    The problem I have is if I add an extra instrument dataseries to calculate only the Volume variable, reamaining the default instrument for the extra calculations.

    I added in bold this lines to the code:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    ...
    ...
    ...

    else if (State == State.Configure)
    {
    AddDataSeries("NAME OF ADDITIONAL INSTRUMENT", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
    }

    else if (State == State.Historical)
    {
    if (Calculate == Calculate.OnPriceChange)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", string.Format(Custom.Resource.NinjaScriptOnPriceCh angeError, Name), TextPosition.BottomRight);
    Log(string.Format(Custom.Resource.NinjaScriptOnPri ceChangeError, Name), LogLevel.Error);
    }
    }
    }

    protected override void OnBarUpdate()
    {
    //this is the default value for Vlolume calculation with default instrument
    Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];


    In the example below in the condition if (Value[1] >= VolRelev1) // "Value[1] is the "defalult instrument" volume and if condition is true then wil draw a fibo based on "defalult instrument" data.


    if (Value[1] >= VolRelev1)
    {
    Draw.FibonacciRetracements(this, "FiboUp", true, 10, Low[Math.Max(0, Swing(SwingVRUp).SwingLowBar(0, 1, 100))], -10, High[1]);

    }



    But the problen is in the exmple below. If the condition if (Volumes[1][1] >= VolRelev1) // Volumes[1][1] is the "added instrument" volume and I expect that if condition is true then will draw a fibo based in "default intrument" data. But it is drawing the fibo based in the added instrument too, and I do not want that.


    if (Volumes[1][1] >= VolRelev1)
    {
    Draw.FibonacciRetracements(this, "FiboUp", true, 10, Low[Math.Max(0, Swing(SwingVRUp).SwingLowBar(0, 1, 100))], -10, High[1]);


    }



    Please could you help me?

    Kind regards,

    Marcos L.



    #2
    Hi Marcos; Thank you for your post.

    In this statement:

    Code:
    if (Volumes[1][1] >= VolRelev1)
    {
    Draw.FibonacciRetracements(this, "FiboUp", true, 10, Low[Math.Max(0, Swing(SwingVRUp).SwingLowBar(0, 1, 100))], -10, High[1]);
    }
    You reference the Volumes[][] array and properly target the secondary series, but the Low[] series used in the Draw statement could be either in the context of the primary series or the secondary series. Use the Lows[][] series to target your primary series when needed e.g. Lows[0][Math.Max(0, Swing(SwingVRUp).SwingLowBar(0, 1, 100))].

    To reference the correct series for the Swing indicator, use this override: Swing(ISeries<double> input, int strength) e.g. Swing(BarsArray[0], SwingVRUp)

    Please let me know if this does not resolve your inquiry.
    Last edited by NinjaTrader_ChrisL; 05-27-2019, 08:53 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello ChrisL,

      Your solution worked perfect.

      Thank you for your assistance.

      Kind Regards,

      Marcos L.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CortexZenUSA, Today, 12:53 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Started by CortexZenUSA, Today, 12:46 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Started by usazencortex, Today, 12:43 AM
      0 responses
      5 views
      0 likes
      Last Post usazencortex  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      168 responses
      2,266 views
      0 likes
      Last Post sidlercom80  
      Started by Barry Milan, Yesterday, 10:35 PM
      3 responses
      13 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X