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