Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tuned volume indicator only works on some instruments

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

    Tuned volume indicator only works on some instruments

    Hello,

    I am contacting you because I made script for a volume indicator which has colored bars if the volume reaches a certain thershold and draws rectangles on the price panel around the concerned candlesticks, basically. It compiled ok and seems to work perfectly on the FDAX and FDXM futures. However on the FSEX future it plots nothing and the indicator appears blank, no bars at all. I do not understand why (see the attached picture).

    What I did is I created a new indicator and then copied the script lines of the VOL indicator, and then added the necessary lines to color the bars for values bigger than a certain limit, and then those to draw the rectangles around the price sticks. Its pretty simple.

    Another thing I'd like to ask is why the soooo long name with the false,true statments and the #F00.. infos. Why is it appearing like that? I am doing something wrong with the script below? (see fragment attached)

    Thank you very much.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class AlexVolv2 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = Custom.Resource.NinjaScriptIndicatorDescriptionVOL ;
    Name = "AlexVolv2";
    BarsRequiredToPlot = 0;
    Calculate = Calculate.OnEachTick;
    DrawOnPricePanel = false;
    IsSuspendedWhileInactive = true;

    AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, Custom.Resource.VOLVolume);
    AddLine(Brushes.DarkGray, 0, Custom.Resource.NinjaScriptIndicatorZeroLine);

    VolRel1 = 500; <-- first volume threshold, this can be then modified in the indicator properties
    VolRel2 = 1200; <-- first volume threshold, this can also be then modified in the indicator properties
    ColorVolRel1 = Brushes.Yellow;
    ColorVolRel2 = Brushes.Red;
    ActivarZonas = true;
    ColorMarcoZonaUp = Brushes.Transparent;
    ColorMarcoZonaDown = Brushes.Transparent;
    ColorFondoZonaUp = Brushes.Lime;
    ColorFondoZonaDown = Brushes.Red;
    OpacidadFondoZona = 18;
    LongitudZona = 50;
    ActivarAlertas = true;
    SonidoAlertaVol1 = "";
    SonidoAlertaVol2 = "";
    TiempoRearmeAlarmas = 15;

    }
    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);
    }

    }
    AllowRemovalOfDrawObjects = true;
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];

    if (Value[0] >= VolRel1)
    {
    if (ActivarAlertas && SonidoAlertaVol1 != "") // && IsFirstTickOfBar) { //&& doOnce==false) {
    {
    //PlaySound(SonidoAlertaVol1);
    Alert("alerta1", Priority.High, "", SonidoAlertaVol1, TiempoRearmeAlarmas, Brushes.Transparent, Brushes.Transparent);
    //doOnce = true;
    }

    PlotBrushes[0][0] = ColorVolRel1;

    if (Close[0] > Open[0] && ActivarZonas)
    {
    DrawOnPricePanel = true;
    Draw.Rectangle(this, "tag1" + CurrentBar, false, 4, Low[0], LongitudZona*-1, High[0], ColorMarcoZonaUp, ColorFondoZonaUp, OpacidadFondoZona);
    }

    etc
    ...
    ...
    ...

    #2
    Hello jwaorpi,

    Thanks for your post.

    When you apply the indicator and it does not appear as expected, please check the NinjaTrader8 control center's "Log" tab for any error messages related to the indicator.

    The indicator name on the panel is showing all of the parameters used. As a script creator you can control what is shown by removing the [NinjascriptProperty] attribute from each parameter. refrence: https://ninjatrader.com/support/help...yattribute.htm However please note that if the indicator is called by another script you would be unable to specify those properties unless they have the NinjascriptProperty attribute

    As a user you can inhibit what is shown by changing the label property in the user interface by either deleting the name or adding quotes on either side of it. From the help guide, "The label displayed on the chart. Leaving the field blank will remove the label from being displayed on the chart. Enclosing a label in quotations ("MyEMA" for example) will display the text within the quotations and exclude the system added trailing series information." Please see "How to edit an indicator's parameters " on this page: https://ninjatrader.com/support/help...indicators.htm

    Comment


      #3
      Hello Paul

      Thanks for the quick feedback. I checked the log and indeed found an error line concerning the indicator (see image attached). Looks like it has to do with the number of "bars ago" called somewhere in the code. I think I found it in the script; seems that decreasing the number of "bars ago" bellow the OnBarUpdate method to a number of 1 or 0 solves the problem and the indicator works on FESX as well but I don't understand why. See the code below.

      Anyway I now can work with my "tuned volume indicator" with these instruments. If you could just help me clarify why this error happens I would appreciate.
      Thank you

      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here.
      Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
      if (Value[0] >= VolRel1)
      {
      if (ActivarAlertas && SonidoAlertaVol1 != "") // && IsFirstTickOfBar) { //&& doOnce==false) {
      {
      //PlaySound(SonidoAlertaVol1);
      Alert("alerta1", Priority.High, "", SonidoAlertaVol1, TiempoRearmeAlarmas, Brushes.Transparent, Brushes.Transparent);
      //doOnce = true;
      }

      PlotBrushes[0][0] = ColorVolRel1; // added

      if (Close[0] > Open[0] && ActivarZonas)
      {
      DrawOnPricePanel = true;
      Draw.Rectangle(this, "tag1" + CurrentBar, false, 1, Low[0], LongitudZona*-1, High[0], ColorMarcoZonaUp, ColorFondoZonaUp, OpacidadFondoZona);
      } //meaning the rectangle is drawn starting on 1 previous bar, instead of 4 like it was before. Seems that over 1 the indicator no longer works and the error shown on the log appears. I don't understand why this happens with this instrument, FESX and not in FDXM or FDAX.

      if (Close[0] < Open[0] && ActivarZonas)
      {
      DrawOnPricePanel = true;
      Draw.Rectangle(this, "tag2" + CurrentBar, false, 1, Low[0], LongitudZona*-1, High[0], ColorMarcoZonaDown, ColorFondoZonaDown, OpacidadFondoZona);
      }

      if (Close[0] == Open[0] && ActivarZonas)
      {
      DrawOnPricePanel = true;
      Draw.Rectangle(this, "tag3" + CurrentBar, false, 1, Low[0], LongitudZona*-1, High[0], Brushes.Transparent, Brushes.Blue, OpacidadFondoZona);
      }
      }

      etc.
      ...
      ​​​​​​​...

      Comment


        #4
        Hello jwaorpi,

        Thanks for your reply.

        When a script is loaded it will start with the very first historical bar of the data series and if on that bar you try to access a previous bar then you will get that error. You need to delay processing until the indicator has cycled through a minimum number of bars as required by your code. So if you were accessing say 4 bars ago then you would need to delay processing your code until the current bar is greater than 4.

        Typically this is done by checking the CurrentBar at the top of OnBarUpdate(), for example: if(CurrentBar < 4) return; // do not process below this line until 4 bars

        Reference: https://ninjatrader.com/support/help...currentbar.htm

        The reason why it did work was a matter of luck because your Draw statement is a conditional one and likely the conditions to draw the object were not true until well after the first few bars.
        Last edited by NinjaTrader_PaulH; 03-25-2020, 11:02 AM.

        Comment


          #5
          Hi Jwaorpi, was You able to fix it?

          Comment


            #6
            Hello,
            Yeah, understood and solved. Thanks a lot.
            Have a nice day.

            Comment


              #7
              Hi Jwaorpi, ich vermute Du bist auch aus D!? Hättest Du Lust an einem Austausch?
              Ich trade Eurex schon sehr lange! [email protected]

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              639 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              572 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X