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

Indicator Real time Calculation

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

    Indicator Real time Calculation

    This indicator is not calculating right when I load it during the section.
    When the previus bar is green the count variable[1] should be = 1
    when I load it if the previus bar is green , then it consider the count variable[1] = 0 and calculate wrong.

    In the chart below you will see it in the last bar

    Can you help me please?


    Click image for larger version

Name:	WROM.png
Views:	312
Size:	46.6 KB
ID:	1099763






    CODE

    IsSuspendedWhileInactive = true;
    AddPlot(new Stroke(Brushes.Black), PlotStyle.Bar,"PlotWeis");

    }
    else if (State == State.DataLoaded)

    Volsum = new Series<double>(this);
    Count = new Series<double>(this);
    VOL1 = VOL(Close);
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    // Bars
    if (Close[0] > Open[0])
    {
    Count[0] = 1;
    }
    else if (Close[0] <= Open[0])
    {
    Count[0] = 0;
    }

    // Count
    if (Count[0] == Count[1])
    {
    Volsum[0] = Volsum[1] + VOL1[0];
    }

    else if (Count [0]!= Count[1])
    {
    Volsum[0] = VOL1[0];
    }

    PlotWeis[0] = Volsum[0];

    // Print(" " +" Data" + Time[0]+ " " +" Count0= " +Count[0] + " ------- " +" Count1= " +Count[1] );

    // Color
    if (Close[0]>Open[0])
    {
    PlotBrushes[0][0] = Brushes.Green;
    }
    if (Close[0]<=Open[0])
    {
    PlotBrushes[0][0] = Brushes.Red;
    }


    }

    #2

    Now I realod the indicator and as you can see it is different. When I realod and the previus bar is red it works ok. Looks like the Count[1] is always = 0 when I load it

    Click image for larger version

Name:	WROM1.png
Views:	289
Size:	46.8 KB
ID:	1099765

    Comment


      #3
      Hello Wagner,

      Thanks for your post.

      Could you clarify on what your expectation is and what you are trying to accomplish?

      Looking at the code, I see that you are tracking if there has been consecutive up or down bars and then you are accumulating volume when there are consecutive up/down bars.

      What part of the code specifically is not working as you expect? From what I see, Count is always assigned when there is an up or down bar. I would then expect Count[1] to be a 1 if the last bar is an up bar and a 0 if the last bar is a down bar. Is there a specific case where you see this not to be the case? You can print out Count[0] and Count[1] after you assign Count[0] to see what values they hold.

      Is the issue seen when setting the script to Calculate.OnBarClose, or is this seen with other Calculate modes?

      Could you also attach an export of the script and some steps to reproduce the symptoms? It can help to draw on your screenshots to point out the exact thing you want us to be looking for.

      Exporting as source code - https://ninjatrader.com/support/help...tAsSourceFiles

      I look forward to assisting.
      JimNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Barry Milan, Today, 10:35 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, Yesterday, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      40 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Today, 08:51 AM
      2 responses
      16 views
      0 likes
      Last Post bill2023  
      Working...
      X