I'm stuck on what I thought would be a simple coding task for Uli's range bar expansion indicator.
My goal was to color code the two moving averages EMA34 and LSMA red and magenta respectively when slope is down; green and blue when slope is up. Full original code is posted below.
My attempt to color code EMA34 by it's slope (shown next) failed:
original plot line (17 lines from the end):
if plotEMA34 then plot1[1](EMA34[value1],"LBEMA34")
my failed code attempt (just turns MA green):
if plotema34 and
EMA34[value1] > EMA34[value1-1]then
plot1[1](EMA34[value1],"LBEMA34",Green)
else if
plotema34 and
EMA34[value1] < EMA34[value1-1]then
plot1[1](EMA34[value1],"LBEMA34",red);
I believe the problem has to do with the fact that this is built within an array.
Any savy coders able to lend some ideas?
Thanks in advance!,
snowbird
-------------------------------------------------
//Range Expansion Bars by Uli Schmuli
inputs: BarRange(3.75),
PlotRangeBars(true),
PlotExpansionBars(true),
PlotExpansionPotential(true),
BullBarColor(green),
BearBarColor(red),
RBThickness(3),
PlotEMA34(true),
PlotLSMA(true);
var:RangeHigh(0),
RangeLow(0),
RangeOpen(open),
RangeClose(0),
RBcolor(green),
LBLow(0),
LBHigh(0),
LBOpen(0),
LBClose(0),
offset(0),
LBxAvg(0),
SmoothingFactor(2/35),
LSMAtemp(0);
Array: EMA34[100](0),
RBHigh[100](close),
RBLow[100](close),
RBOpen[100](Close),
RBClose[100](close),
LSMA[100](close);
if barnumber = 1 then //1st bar initialization
begin
if range < BarRange then
begin
RangeHigh = high;
RangeLow = Low;
end;
if range > BarRange then
begin
RangeHigh = High;
RangeLow = Low;
end;
LSMA[1] = close;
EMA34[1] = close;
RBclose[1] = close;
LSMA[1] = close;
LBopen = open;
end else //all other bars
Begin
if date <> date[1] then //new day, begin new bar & close out prior bar
begin
LBHigh = RangeHigh;
LBlow = RangeLow;
LBOpen = RangeOpen;
LBclose = iff(close<RBclose[1],RangeLow,RangeHigh);
For Value1 = 100 downto 2
begin
EMA34[value1] = EMA34[value1-1];
RBHigh[value1] = RBHigh[Value1-1];
RBLow[value1] = RBLow[Value1-1];
RBOpen[value1] = RBOpen[Value1-1];
RBClose[value1] = RBClose[value1-1];
LSMA[value1] = LSMA[value1-1];
end;
RBHigh[1] = LBHigh;
RBLow[1] = LBLow;
RBOpen[1] = LBOpen;
RBClose[1] = LBClose;
EMA34[1] = EMA34[2] + SmoothingFactor * (RBclose[1] - EMA34[2]);
value1 = LinRegArray(RBClose,25, 0, value2, value3,value4, LSMAtemp);
LSMA[1] = LSMAtemp;
RangeOpen = Open;
RangeHigh = High;
RangeLow = low;
RangeClose = close;
offset = 1;
end;
if offset[1] = 1 and date = date[1] then offset = 0;
if low >= rangelow and high <= rangehigh then //Bar totally in barrange
begin
end;
if high > Rangehigh and low >= rangelow then //new high value
begin
rangehigh = high;
If high - rangelow > barrange then //New Higher bar detected
begin
LBlow = RangeLow;
LBHigh = RangeLow + BarRange;
LBOpen = RangeOpen;
LBclose = LBHigh;
For Value1 = 100 downto 2
begin
EMA34[value1] = EMA34[value1-1];
RBHigh[value1] = RBHigh[Value1-1];
RBLow[value1] = RBLow[Value1-1];
RBOpen[value1] = RBOpen[Value1-1];
RBClose[value1] = RBClose[value1-1];
LSMA[value1] = LSMA[value1-1];
end;
RBHigh[1] = LBHigh;
RBLow[1] = LBLow;
RBOpen[1] = LBOpen;
RBClose[1] = LBClose;
EMA34[1] = EMA34[2] + SmoothingFactor * (RBclose[1] - EMA34[2]);
value1 = LinRegArray(RBClose,25, 0, value2, value3,value4, LSMAtemp);
LSMA[1] = LSMAtemp;
rangeopen = Rangelow + barrange;
rangeLow = Rangelow + barrange;
RangeClose = rangeopen;
offset = 1;
end;
end;
if low < RangeLow and high <= rangehigh then//new low value
begin
Rangelow = low;
if rangehigh - low > barrange then //New lower bar detected
begin
LBHigh = RangeHigh;
LBlow = RangeHigh - barrange;
LBOpen = RangeOpen;
LBclose = LBlow;
For Value1 = 100 downto 2
begin
EMA34[value1] = EMA34[value1-1];
RBHigh[value1] = RBHigh[Value1-1];
RBLow[value1] = RBLow[Value1-1];
RBOpen[value1] = RBOpen[Value1-1];
RBClose[value1] = RBClose[value1-1];
LSMA[value1] = LSMA[value1-1];
end;
RBHigh[1] = LBHigh;
RBLow[1] = LBLow;
RBOpen[1] = LBOpen;
RBClose[1] = LBClose;
EMA34[1] = EMA34[2] + SmoothingFactor * (RBclose[1] - EMA34[2]);
value1 = LinRegArray(RBClose,25, 0, value2, value3,value4, LSMAtemp);
LSMA[1] = LSMAtemp;
RangeOpen = LBclose;
RangeHigh = LBclose;
RangeLow = low;
RangeClose = close;
offset = 1;
end;
end;
if high > RangeHigh and Low < RangeLow and rangehigh - rangelow > barrange then//engulfing bar
begin
RangeLow = low;
RangeHigh = high;
end;
end;
begin
if offset = 1 then //new bar begun
begin
if RBclose[1] < RBclose[2] then RBcolor = BearBarColor else RBcolor = BullBarColor;
plot15[1](RBHigh[value1],"RBHighL",RBColor,default,RBthickness);
plot16[1](RBLow[value1],"RBLowL",RBcolor,default,RBthickness);
plot17[1](RBopen[value1],"RBopenL",RBcolor,default,RBthickness);
Plot18[1](RBClose[value1],"RBcloseL",RBColor,default,RBthickness);
if plotEMA34 then plot1[1](EMA34[value1],"LBEMA34")
if plotLSMA then plot5[1](LSMA[Value1],"LSMA");
end;
if close < LBclose then RBcolor = darkred else RBcolor = darkgreen;
if PlotExpansionBars then
begin
plot20(rangehigh,"chigh",RBColor,default,1);
plot21(rangelow,"clow",RBcolor,default,1);
plot22(rangeopen,"copen",RBcolor,default,1);
Plot23(Close,"cclose",RBColor,default,1);
end;
if PlotExpansionPotential then
begin
Plot24(rangehigh-barrange,"PotLow");
Plot25(RangeLow+barrange,"PotHigh");
end;
end;