I'm not sure how to do this (and I assume anything is possible in programming), but I want to export a variable by potentially running the while statement again if needed, and have it stop at CurrentBar to export a variable - I THINK that would be the way to do it. If at the CURRENTBAR that I'm looking at Close[0] is below or above "latestlow" I want something to happen. However, outside of while loop, or the indicator "latestlow" is always 0.
Here's the method with while loops ---- SKIP below for more defined question please ---
public int METHOD(int period, Brush color)
{
#region LowPivot
int y = 0;
int Lvls = 0;
//Four Matching Lows
if(Low[period]==Low[period+1] && Low[period]==Low[period+2] && Low[period]==Low[period+3])
{
y = 1;
while(y<=period)
{
if(y!=period ? Low[period+3]<Low[period+3+y] : Low[period+3]<Low[period+3+y])
Lvls++;
if(y!=period ? Low[period]<Low[period-y] : Low[period]<Low[period-y])
Lvls++;
y++;
}
}
//Three Matching Lows
else if(Low[period]==Low[period+1] && Low[period]==Low[period+2])
{
y=1;
while (y<=period)
{
if (y!=period ? Low[period+2]<Low[period+2+y] : Low[period+2]<Low[period+2+y])
Lvls++;
if (y!=period ? Low[period]<Low[period-y] : Low[period]<Low[period-y])
Lvls++;
y++;
}
}
//Two Matching Lows
else if (Low[period]==Low[period+1])
{
y=1;
while(y<=period)
{
if (y!=period ? Low[period+1]<Low[period+1+y] : Low[period+1]<Low[period+1+y])
Lvls++;
if (y!=period ? Low[period]<Low[period-y] : Low[period]<Low[period-y])
Lvls++;
y++;
}
}
//Regular Pivot
else
{
y=1;
while (y<=period)
{
if (y!=period ? Low[period]<Low[period+y] : Low[period]<Low[period+y])
Lvls++;
if (y!=period ? Low[period]<Low[period-y] : Low[period]<Low[period-y])
Lvls++;
y++;
}
}
//Auxiliary Checks
if (Lvls<period*2)
{
Lvls = 0;
//Four Lows - First and Last Matching - Middle 2 are lower
if (Low[period] <= Low[period+1] && Low[period]<=Low[period+2] && Low[period]==Low[period+3])
{
y = 1;
while (y <= period)
{
if (y != period ? Low[period + 3] < Low[period + 3 + y] : Low[period + 3] < Low[period + 3 + y])
Lvls++;
if (y != period ? Low[period] < Low[period - y] : Low[period] < Low[period - y])
Lvls++;
y++;
}
}
}
if(Lvls < period * 2)
{
Lvls = 0;
//Three Lows - Middle is lower than two outside
if (Low[period] <= Low[period + 1] && Low[period]==Low[period + 2])
{
y = 1;
while (y <= period)
{
if (y != period ? Low[period + 2]<Low[period + 2 + y] : Low[period + 2] < Low[period + 2 + y])
Lvls++;
if (y != period ? Low[period] < Low[period-y] : Low[period] <Low[period - y])
Lvls++;
y++;
}
}
}
if (Lvls >= period * 2)
{
Lower[period] = Low[period]; // draw the block
if (lowdrawbar != CurrentBar)
{
if (showText)
{
Draw.Text(this, "Low"+lowcount, true, Low[period].ToString(), period, Low[period], -20, color,
textFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
}
if (showRays)
{
Draw.Ray (this, "lowray"+lowcount, false, CurrentBar - lastlowbar, lastlow, period, Low[period],
color, DashStyleHelper.Dash, lineWidth);
}
lowcount++;
if (lowcount == history + 1)
{
lowcount = 1;
}
lowdrawbar = CurrentBar;
}
lastlow = Low[period]; // Save the low value for next ray drawn
lastlowbar = CurrentBar - period; // Save the low value location for next ray drawn
}
----- And we're back! ---
The variable I need is "lastlow" at a specific point. Say, if Close[0] crosses below or above lastlow, I want something executed. The method in this indicator returns y - used for something else within the indicator, and that's just the number "3".
If I print from within the method, or outside the method, prior to "return y;" from within the indicator, I get all the values at every single bar; but it will establish and keep the same latestlow for let's say 10+ bars. Since there are while methods, how can I access this at the RIGHT point, interjecting and picking up the latestlow, during the bar times that I'm looking it.
"Print (latestlow + CurrentBar); "
If i do -- ThisIndicator.latestlow I will always get a 0, since the while loop has not run, or if it has run, I will get the latest value only at the end of it.
Any thoughts are very much appreciated.
Comment