Hi,
Written a code for plotting a shape on upper edge of the candle based on certain criteria.
This is working fine.
Now I want this criteria to be modified as following
- Shapes are drawn above the candles when some criteria meets => Working
- If the current price is greater than high of that candle, no need to draw the shape => Working
- Now I want to check, the highest price from that candle where shape was drawn to current candle, the highest price from this region should be less than the candle’s minm of(open, close) then only shape to be drwan => Need help
The logic I have in mind is as follows:
a. Shape drawn on -n1 th, -n2 th , -n3 th candles
b. minm(close,open) for those candles are m1,m2, m3 respectively
c. now finding highest price from -n1+1 candle to current candle is h1. Similar calculation for h2 & h3.
d. Check m1> h1, h2, h3=> if greater draw the shape or don’t draw.
function ctype(o1,h1,l1,c1) // function for determining Candle type, 1: Body less than 50% of the range, 2: Down candle, 3: Up Candle
{ body=abs(o1-c1);
hgt=h1-l1;
rati=body/hgt;
typ = IIf(rati<=.5,1,IIf(o1>c1,2,3));
return(typ);
}
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
col=ctype(O,H,L,C);
color = IIf(col==1, colorBlue, IIf(col==3,colorGreen,colorRed));
Plot(C,"Price",color,styleCandle );
b1=ctype(O,H,L,C);
b2=ctype(Ref(O,-1),Ref(h,-1),Ref(l,-1),Ref(c,-1));
b3=ctype(Ref(O,-2),Ref(h,-2),Ref(l,-2),Ref(c,-2));
lu=Ref(H,-3);
lb=Min(Ref(C,-3),Ref(O,-3));
//need code to find max from next candle where shape was drwan to current candle
//if that max<lb, set color to RED, else set the color to BLACK to make it invisible.
color = IIf(b1==2 AND b2==2 AND b3==1 AND lb>C, colorwhite, colorblack);
PlotShapes(shapeDownTriangle, color, layer = 0, yposition = lu, offset = -12, XShift =-2 );