colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));
GraphXSpace = 10;
_SECTION_BEGIN("Demand/Supply Point");
/*
Demand Point is that Bar whose Low is lower than the Low of two bars immediately before AND ahead it AND
its Low may be equal to the Low of previous bar (to cover case of double bottom).
*/
//nbar=Param("N Pivot Bars",3,2,50,1);
DemandPoint = (L < Ref(L, -2) & L <= Ref(L, -1) & L < Ref(L, 1) & L < Ref(L, 2) ); //returns true/false
BuyP = 0;
//DemandPoint = L<Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar)>=L;
//Colour of Demand Line is user defined. Default is ColorRGB(0, 128, 255) i.e.blueish
colorDemandPoint = ParamColor("Demand Line", ColorRGB(0, 128, 255));
// Supply Point is that Bar whose High is Higher than the High of two bars immediately before and ahead it and
// its High may be equal to the High of previous bar (to cover case of double top).
SupplyPoint = (H > Ref(H, -2) & H >= Ref(H, -1) & H > Ref(H, 1) & H > Ref(H, 2) ); //returns True/false
SellP = 0;
//SupplyPoint = H>Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar)<=H;
//Colour of Supply Line is user defined. Default is ColorRGB(255, 128, 0) i.e. Orange.
colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
_SECTION_END();
_SECTION_BEGIN("Plot Trend Lines");
/*
Trend Lines are drawn by joining two Demand Points (dx0 and dx1) or two Supply points (sx0 and sx1).
Where x0, x1 are on Time axis and y0, y1 are on price axis.
Demand line is closed when a candle closes below it. Supply line is closed when a candle closes above it.
A Trend Lines is extended until it is closed by any candle.
In this section we identify these points AND then Plot TLs. These points are initialsed as 0 in the beginning.
*/
CountTrendBars = 0;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;
LVB= Status("lastvisiblebar"); //Inserted by Josh1
//-- Modified by KelvinHand and later by Josh1----------- to plot only on visible chart
function VisiBarsPerChart()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
nBars=1.5*VisiBarsPerChart();
if (nBars <LVB)
iLimit = (LVB) - nBars+2;
else
iLimit = 2; // end change by Josh1
//------------------------------------
//_TRACE( "LVB = "+NumToStr(LVB,1.0) );
//_TRACE( "Barcount = "+NumToStr(BarCount,1.0) );
// Next line changed by Josh1 since LVB includes blank bars. Now we get dynamic range from LVB to iLimit.
for (i = IIf(LVB>(BarCount-1),BarCount-1,LVB); i>iLimit; i--) {
if (DemandPoint[i]) {
if (dx1 == 0 & dy1 == 0) {
dx1 = i; //
dy1 = L[i];
PlotText( "HL", i, L[ i ]-3, colorPink ); // Identify the demand point by as "HL" meaning low.
} else {
dx0 = i;
dy0 = L[i];
PlotText( "L", i, L[ i ]-3, colorPink ); // Identify the demand point by as "L" meaning low.
colorHighliter[i+1] = ColorRGB(128, 128, 0); // // Highlight next candle with Yellow colour
}
if (dx0 != 0 & dx1 != 0 & dy0 != 0 & dy1 != 0) {
if (dy0 < dy1) { //
a = (dy0 - dy1) / (dx0 - dx1); // We calculate a = the slope of TL
b = dy0 - dx0 * a; // This gives displacement on Y axis
for (j = dx1; j < BarCount; j++) {
if (j != dx1) {
y2 = a * j + b;
if (C[j] < y2) {
dy1 = y2;
dx1 = j;
// Highlight candle breaking below demand line with Purple colour
// colorHighliter[j] = ColorRGB(128, 0, 128);
CountTrendBars[j] = dx1 - dx0 - 1;
break;
}
}
}
if (dy1 != y2) {
dy1 = y2;
dx1 = BarCount - 1;
}
Plot(LineArray(dx0, dy0, dx1, dy1, 0), "", colorDemandPoint, styleLine|styleThick, Null, Null, 0, 2);
}
dx1 = dx0;
dy1 = dy0;
dx0 = dy0 = 0;
}
}
if (SupplyPoint[i]) {
if (sx1 == 0 & sy1 == 0) {
sx1 = i;
sy1 = H[i];
} else {
sx0 = i;
sy0 = H[i];
PlotText( "H", i, H[ i ]+3, colorPink ); // Identify Supply point as "H" meaning high
colorHighliter[i+1] = ColorRGB(128, 0, 128); // Identify next candle with Purple colour.
}
if (sx0 != 0 & sx1 != 0 & sy0 != 0 & sy1 != 0) {
if (sy0 > sy1) {
a = (-sy0 + sy1) / (-sx0 + sx1);
b = sy0 - sx0 * a;
for (j = sx1; j < BarCount; j++) {
if (j != sx1) {
y2 = a * j + b;
if (C[j] > y2) {
sy1 = y2;
sx1 = j;
// Highlight candle breaking above Supply line with Yellow colour
// colorHighliter[j] = ColorRGB(128, 128, 0);
CountTrendBars[j] = sx1 - sx0 - 1;
break;
}
}
}
if (sy1 != y2) {
sy1 = y2;
sx1 = BarCount - 1;
}
Plot(LineArray(sx0, sy0, sx1, sy1, 0), "", colorSupplyPoint, styleLine|styleThick, Null, Null, 0, 2);
}
sx1 = sx0;
sy1 = sy0;
sx0 = sy0 = 0;
}
}
}
_SECTION_END();
//Price
SetBarFillColor(colorHighliter);
Plot(C, "Close", IIf(colorHighliter == ColorRGB(128, 0, 128), ColorRGB(255, 0, 255), IIf(colorHighliter == ColorRGB(128, 128, 0), ColorRGB(255, 255, 0), IIf(C > O, ColorRGB(0, 255, 0), IIf(C < O, ColorRGB(255, 0, 0), ColorRGB(255, 255, 255))))), styleCandle, Null, Null, 0, 1);
Title = "Trendline-Break +SRS " + Name() + " - " +Interval()/60 +" Min -" + Date() + "- Open = " + NumToStr(O, 1.2) + ", High = " + NumToStr(H, 1.2) + ", Low = " + NumToStr(L, 1.2) +
EncodeColor(colorYellow)+ ", Close = " + NumToStr(C, 1.2) ;