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

How can i calculate SD effectively for all values?

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

    How can i calculate SD effectively for all values?

    Hello,

    I have an oscillator that showing overbought/oversold conditions. It's waving zero level. I want to add 3 lines above and 3 lines below to zero level. Lines will show 1, 2 and 3 standard deviations for both overbought & oversold plot values. Also I don't want to use period value for StdDev function and i want to calculate StdDev for all plot values as many as possible. I mean;

    1. Bar calculate StdDev(..., 1);
    2. Bar calculate StdDev(..., 2;
    3. Bar calculate StdDev(..., 3);
    4. Bar calculate StdDev(..., 4);
    5. Bar calculate StdDev(..., 5);
    N. Bar calculate StdDev(..., N);

    For accomplish this task i write code like below;

    Code:
    			BullishExtreme[0] = ...;
    			BearishExtreme[0] = ...;
    			
    			if (CurrentBar >= Bars.Count - 2)
    			{
    				var bullishExtremeStandardDeviation = StdDev(BullishExtreme, CurrentBar)[0];
    				var bearishExtremeStandardDeviation = StdDev(BearishExtreme, CurrentBar)[0];
    			
    				Lines[0].Value = 0;
    				Lines[1].Value = +bullishExtremeStandardDeviation;
    				Lines[2].Value = +bullishExtremeStandardDeviation * 2.0;
    				Lines[3].Value = +bullishExtremeStandardDeviation * 3.0;
    				Lines[4].Value = -bearishExtremeStandardDeviation;
    				Lines[5].Value = -bearishExtremeStandardDeviation * 2.0;
    				Lines[6].Value = -bearishExtremeStandardDeviation * 3.0;
    			}
    Above code working correct. But i have 4 questions about that;

    1. Is there any other effective way for accomplish this task especially for better speed/performance?

    2. When i add indicator to chart if i don't set "Maximum bars look back" property to Infinite indicator working correctly. But my expectation is calculation only take into account last 256 bars instead it's calculating values correctly. Why? What is the point about this property?

    3. My indicator working on bar close. When i check CurrentBar values, always there is difference 2 between CurrentBar and Bars.Count. Is the reason of difference;
    a. CurrentBar zero base
    b. Last bar close not yet called
    Am i right?

    4. If i'm right about third question, because of use as many as possible plot values for calculate StdDev should i change period parameter of StdDev function from CurrentBar to CurrentBar+1?

    Thanks,
    Aytac
    Last edited by aytacasan; 04-01-2017, 06:11 PM.

    #2
    Hello Aytac,

    No, I am not aware of a more efficient way of setting values in OnBarUpdate.

    If you question is about skipping the historical data and processing on the last processed historical bar, this will save CPU and resources if logically there is no need to set these historically. No, I am not aware of a more efficient way of skipping historical data either.

    Maximum bars lookback is used with added series. If set to TwoHundredFiftySix you will not be able to call back more than 256 bars ago from the current bar (i.e. Close[257] would not work and calling an indicator with a period greater than 256 and supplying the added series as the input series for that indicator would also not work).
    When set to Infinite, you can call back as far as you would like on any bar.

    All historical bars are always processed no matter the setting for how far you can look back.

    Triggering on the last processed historical bar is done when CurrentBar is equal to the total count minus 2 because CurrentBar starts at 0, and the last historical bar is not processed until real-time data is received and closes that bar. (Otherwise that last bar remains open and doesn't close and doesn't trigger OnBarUpdate)

    Whether you should use CurrentBar or CurrentBar + 1 depends on what you are trying to achieve.
    If you want to supply all of the historical data each time this is called then use CurrentBar + 1.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by GLFX005, Today, 03:23 AM
    0 responses
    1 view
    0 likes
    Last Post GLFX005
    by GLFX005
     
    Started by XXtrader, Yesterday, 11:30 PM
    2 responses
    11 views
    0 likes
    Last Post XXtrader  
    Started by Waxavi, Today, 02:10 AM
    0 responses
    6 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    14 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    3 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Working...
    X