I have a bit of code that I'm having to rewrite many times so I thought I'd create a method to save time. Unfortunately the desired outcome of this bit of code takes several bars to develop and with the OnBarUpdate() the method gets called on every bar. Is there a way to allow a method to keep working though consecutive bars?
public void CrossingThreshold_Down(BoolSeries cond_1, IDataSeries indi_2)
{
bool abc_Down_Peak_1 = false;
bool abc_Down_Valley_1 = false;
bool abc_Down_Peak_2 = false;
int abc_Down_Peak_1_Value_Bar = 0;
double abc_Down_Peak_1_Value = 0;
bool abc_Down_CanCrossThreshold = false;
int abc_Down_Valley_1_Value_Bar = 0;
double abc_Down_Valley_1_Value = 0;
double abc_Down_Valley_Threshold = 0;
int abc_Down_Peak_2_Value_Bar = 0;
double abc_Down_Peak_2_Value = 0;
if(cond_1[0] && Finding_Peaks(indi_2[2], indi_2[1], indi_2[0])){
DrawDiamond("Stoch Peak 1 " + CurrentBar, true, 1, High[0] + .3, Color.Gold);
abc_Down_Peak_1 = true;
abc_Down_Peak_1_Value_Bar = HighestBar(indi_2, 10);
abc_Down_Peak_1_Value = indi_2[abc_Down_Peak_1_Value_Bar];
abc_Down_CanCrossThreshold = true;
}
if(abc_Down_CanCrossThreshold && CrossBelow(indi_2,abc_Down_Valley_Threshold, 1)){
abc_Down_CanCrossThreshold = false;
DrawDiamond("Cross Threshold Down " + CurrentBar, true, 0, Low[0] - .2, Color.BurlyWood);
}
if(abc_Down_Peak_1 && Finding_Valleys(indi_2[2], indi_2[1], indi_2[0])){
DrawDiamond("Stoch Valley 1 " + CurrentBar, true, 0, Low[0] - .3, Color.AntiqueWhite);
abc_Down_Peak_1 = false;
abc_Down_Valley_1 = true;
abc_Down_Valley_1_Value_Bar = LowestBar(indi_2, 2);
abc_Down_Valley_1_Value = indi_2[abc_Down_Valley_1_Value_Bar];
abc_Down_Valley_Threshold = abc_Down_Valley_1_Value;
DrawText("Threshold Level " + CurrentBar, " " + abc_Down_Valley_Threshold, 0, Low[0] - .25, Color.Black);
}
if(abc_Down_Valley_1 && Finding_Peaks(indi_2[2], indi_2[1], indi_2[0])){
DrawDiamond("Stoch Peak 2 " + CurrentBar, true, 0, High[0] + .3, Color.Black);
abc_Down_Valley_1 = false;
abc_Down_Peak_2 = true;
abc_Down_Peak_2_Value_Bar = HighestBar(indi_2, 2);
abc_Down_Peak_2_Value = indi_2[abc_Down_Peak_2_Value_Bar];
}
}
I thought that I could use a series of loops to check for the past conditions on every bar but I wonder about the performance of the program at that point.
P.S. What happened to the nice code block feature in the text window? (Choosing the ## to insert code into).
Thanks.
Comment