plz solve the problem

#11
I too had errors ..but could rectify reading the help file..

here is the working afl...
Code:
SetChartOptions(0, chartShowArrows | chartShowDates);
SetChartBkColor(ParamColor("Outer Panel", colorBlack));
SetChartBkGradientFill(ParamColor("Upper Chart", colorDarkGrey), ParamColor("Lower Chart", colorDarkGrey));
GraphXSpace = Param("GraphXSpace", 10, 0, 100, 1);

colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));

//Demand Point
colorDemandPoint = ParamColor("Demand Line", ColorRGB(0, 128, 255));
DemandPoint = (Ref(L, -1) < Ref(L, -2)) & (L < Ref(L, -1)) & (L < Ref(L, 1)) & (Ref(L, 1) < Ref(L, 2));

//Supply Point
colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
SupplyPoint = (Ref(H, -1) > Ref(H, -2)) & (H > Ref(H, -1)) & (H > Ref(H, 1)) & (Ref(H, 1) > Ref(H, 2));

CountTrendBars = 0;
CurrentBar = BarCount - 1;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;
for (i = 0; i < BarCount; i++) {
	CurrentBar = (BarCount - 1) - i;
	if (DemandPoint[CurrentBar]) {
		if (dx1 == 0 & dy1 == 0) {
			dx1 = CurrentBar;
			dy1 = L[CurrentBar];
		} else {
			dx0 = CurrentBar;
			dy0 = L[CurrentBar];
		}
		if (dx0 != 0 & dx1 != 0 & dy0 != 0 & dy1 != 0) {
			if (dy0 < dy1) {
				a = (-dy0 + dy1) / (-dx0 + dx1);
				b = dy0 - dx0 * a;
				for (j = dx1; j < BarCount; j++) {
					if (j != dx1) {
						y2 = a * j + b;
						if (C[j] < y2) {
							dy1 = y2;
							dx1 = j;
							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, Null, Null, 0, 2);
			}
			dx1 = dx0;
			dy1 = dy0;
			dx0 = dy0 = 0;
		}	
	}
	if (SupplyPoint[CurrentBar]) {
		if (sx1 == 0 & sy1 == 0) {
			sx1 = CurrentBar;
			sy1 = H[CurrentBar];
		} else {
			sx0 = CurrentBar;
			sy0 = H[CurrentBar];
		}
		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;
							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, Null, Null, 0, 2);
			}
			sx1 = sx0;
			sy1 = sy0;
			sx0 = sy0 = 0;
		}	
	}	
}

//Stop Loss & Targets
for (i = 0; i < BarCount; i++) {
	CurrentBar = (BarCount - 1) - i;
	if (colorHighliter[CurrentBar] == ColorRGB(128, 0, 128)) {
		StopLoss = 0;
		for (j = CurrentBar - CountTrendBars[CurrentBar]; j <= CurrentBar; j++) {
			StopLoss = Max(H[j], StopLoss);
		}
		if (CurrentBar - (BarCount - 1) != 0) {
			t1 = C[CurrentBar] - (StopLoss - C[CurrentBar]);
			t2 = C[CurrentBar] - ((StopLoss - C[CurrentBar]) * 1.272);
			t3 = C[CurrentBar] - ((StopLoss - C[CurrentBar]) * 1.618);
			Plot(LineArray(CurrentBar, StopLoss + 0.01, BarCount - 1, StopLoss + 0.01, 0), "", ColorRGB(255, 0, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			Plot(LineArray(CurrentBar, C[CurrentBar], BarCount - 1, C[CurrentBar], 0), "", ColorRGB(255, 255, 0), styleDots, Null, Null, 0, 0, 1);
			Plot(LineArray(CurrentBar, t1, BarCount - 1, t1, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			Plot(LineArray(CurrentBar, t2, BarCount - 1, t2, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			Plot(LineArray(CurrentBar, t3, BarCount - 1, t3, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			PlotText("Stop Loss\n@" + WriteVal(StopLoss + 0.01, 1.2), BarCount, StopLoss + 0.01, ColorRGB(255, 255, 255));
			PlotText("T1 @" + WriteVal(t1, 1.2), BarCount, t1, ColorRGB(255, 255, 255));
			PlotText("T2 @" + WriteVal(t2, 1.2), BarCount, t2, ColorRGB(255, 255, 255));
			PlotText("T3 @" + WriteVal(t3, 1.2), BarCount, t3, ColorRGB(255, 255, 255));
		}
		break;
	}
	if (colorHighliter[CurrentBar] == ColorRGB(128, 128, 0)) {
		StopLoss = 9999;
		for (j = CurrentBar - CountTrendBars[CurrentBar]; j <= CurrentBar; j++) {
			StopLoss = Min(L[j], StopLoss);
		}
		if (CurrentBar - (BarCount - 1) != 0) {
			t1 = C[CurrentBar] + (C[CurrentBar] - StopLoss);
			t2 = C[CurrentBar] + ((C[CurrentBar] - StopLoss) * 1.272);
			t3 = C[CurrentBar] + ((C[CurrentBar] - StopLoss) * 1.618);
			Plot(LineArray(CurrentBar, StopLoss - 0.01, BarCount - 1, StopLoss - 0.01, 0), "", ColorRGB(255, 0, 0), styleDots | styleNoLabel, Null, Null, 0,1);
			Plot(LineArray(CurrentBar, C[CurrentBar], BarCount - 1, C[CurrentBar], 0), "", ColorRGB(255, 255, 0), styleDots, Null, Null, 0,  1);
			Plot(LineArray(CurrentBar, t1, BarCount - 1, t1, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 1);
			Plot(LineArray(CurrentBar, t2, BarCount - 1, t2, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0,  1);
			Plot(LineArray(CurrentBar, t3, BarCount - 1, t3, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0,  1);
			PlotText("Stop Loss\n@" + WriteVal(StopLoss - 0.01, 1.2), BarCount, StopLoss - 0.01, ColorRGB(255, 255, 255));
			PlotText("T1 @" + WriteVal(t1, 1.2), BarCount, t1, ColorRGB(255, 255, 255));
			PlotText("T2 @" + WriteVal(t2, 1.2), BarCount, t2, ColorRGB(255, 255, 255));
			PlotText("T3 @" + WriteVal(t3, 1.2), BarCount, t3, ColorRGB(255, 255, 255));
		}		
		break;
	}
}

//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);

//Volume
/*colorVolume = ParamColor("Volume Area", ColorRGB(0, 0, 0));
Plot(Volume, "", colorVolume, styleArea | styleOwnScale | styleNoLabel, Null, Null, 0, 0, 1);*/

Title = Name() + " - {{INTERVAL}} - {{DATE}} - Open = " + NumToStr(O, 1.2) + ", High = " + NumToStr(H, 1.2) + ", Low = " + NumToStr(L, 1.2) + ", Close = " + NumToStr(C, 1.2) + " (" + WriteVal(ROC(C, 1), 1.2) + "%)"; /*, Volume = " + WriteVal(Volume, 1.2);*/

pls slove the query
-------------------
my amibroker ver 5.6.2
warning :502
you are calling plot()plotOHLC() function over 500 times,it's highly inefficient reduce number of calls
 

KelvinHand

Well-Known Member
#12
pls slove the query
-------------------
my amibroker ver 5.6.2
warning :502
you are calling plot()plotOHLC() function over 500 times,it's highly inefficient reduce number of calls
Then upgrade your amibroker.
latest official version is 5.60.
beta version is 5.64.1.
 
Last edited:

KelvinHand

Well-Known Member
#13
Try this, not sure whether it will reduce your errors


Code:
SetChartOptions(0, chartShowArrows | chartShowDates);
SetChartBkColor(ParamColor("Outer Panel", colorBlack));
SetChartBkGradientFill(ParamColor("Upper Chart", colorDarkGrey), ParamColor("Lower Chart", colorDarkGrey));
GraphXSpace = Param("GraphXSpace", 10, 0, 100, 1);

colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));

//Demand Point
colorDemandPoint = ParamColor("Demand Line", ColorRGB(0, 128, 255));
DemandPoint = (Ref(L, -1) < Ref(L, -2)) & (L < Ref(L, -1)) & (L < Ref(L, 1)) & (Ref(L, 1) < Ref(L, 2));

//Supply Point
colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
SupplyPoint = (Ref(H, -1) > Ref(H, -2)) & (H > Ref(H, -1)) & (H > Ref(H, 1)) & (Ref(H, 1) > Ref(H, 2));

CountTrendBars = 0;
//CurrentBar = BarCount - 1;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;


function VisiBarsPerChart()
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    return Min(lvb-fvb,BarCount-fvb);
}


nBars=1.5*VisiBarsPerChart();
if (nBars <BarCount)
 iLimit = (BarCount-1) - nBars;
else
 iLimit = 0;
  
//_TRACE( "Limit = "+NumToStr(iLimit) );
//_TRACE( "Barcount = "+NumToStr(BarCount) );

for (i = BarCount-1; i>iLimit; i--) {
	if (DemandPoint[i]) {
		if (dx1 == 0 & dy1 == 0) {
			dx1 = i;
			dy1 = L[i];
		} else {
			dx0 = i;
			dy0 = L[i];
		}
		if (dx0 != 0 & dx1 != 0 & dy0 != 0 & dy1 != 0) {
			if (dy0 < dy1) {
				a = (-dy0 + dy1) / (-dx0 + dx1);
				b = dy0 - dx0 * a;
				for (j = dx1; j < BarCount; j++) {
					if (j != dx1) {
						y2 = a * j + b;
						if (C[j] < y2) {
							dy1 = y2;
							dx1 = j;
							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, 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];
		}
		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;
							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, Null, Null, 0, 2);
			}
			sx1 = sx0;
			sy1 = sy0;
			sx0 = sy0 = 0;
		}	
	}	
}

//Stop Loss & Targets
for (i = BarCount-1; i>iLimit; i--) {
	if (colorHighliter[i] == ColorRGB(128, 0, 128)) {
		StopLoss = 0;
		for (j = i - CountTrendBars[i]; j <= i; j++) {
			StopLoss = Max(H[j], StopLoss);
		}
		if (i - (BarCount - 1) != 0) {
			t1 = C[i] - (StopLoss - C[i]);
			t2 = C[i] - ((StopLoss - C[i]) * 1.272);
			t3 = C[i] - ((StopLoss - C[i]) * 1.618);
			Plot(LineArray(i, StopLoss + 0.01, BarCount - 1, StopLoss + 0.01, 0), "", ColorRGB(255, 0, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			Plot(LineArray(i, C[i], BarCount - 1, C[i], 0), "", ColorRGB(255, 255, 0), styleDots, Null, Null, 0, 0, 1);
			Plot(LineArray(i, t1, BarCount - 1, t1, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			Plot(LineArray(i, t2, BarCount - 1, t2, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			Plot(LineArray(i, t3, BarCount - 1, t3, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 0, 1);
			PlotText("Stop Loss\n@" + WriteVal(StopLoss + 0.01, 1.2), BarCount, StopLoss + 0.01, ColorRGB(255, 255, 255));
			PlotText("T1 @" + WriteVal(t1, 1.2), BarCount, t1, ColorRGB(255, 255, 255));
			PlotText("T2 @" + WriteVal(t2, 1.2), BarCount, t2, ColorRGB(255, 255, 255));
			PlotText("T3 @" + WriteVal(t3, 1.2), BarCount, t3, ColorRGB(255, 255, 255));
		}
		break;
	}
	if (colorHighliter[i] == ColorRGB(128, 128, 0)) {
		StopLoss = 9999;
		for (j = i - CountTrendBars[i]; j <= i; j++) {
			StopLoss = Min(L[j], StopLoss);
		}
		if (i - (BarCount - 1) != 0) {
			t1 = C[i] + (C[i] - StopLoss);
			t2 = C[i] + ((C[i] - StopLoss) * 1.272);
			t3 = C[i] + ((C[i] - StopLoss) * 1.618);
			Plot(LineArray(i, StopLoss - 0.01, BarCount - 1, StopLoss - 0.01, 0), "", ColorRGB(255, 0, 0), styleDots | styleNoLabel, Null, Null, 0,1);
			Plot(LineArray(i, C[i], BarCount - 1, C[i], 0), "", ColorRGB(255, 255, 0), styleDots, Null, Null, 0,  1);
			Plot(LineArray(i, t1, BarCount - 1, t1, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0, 1);
			Plot(LineArray(i, t2, BarCount - 1, t2, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0,  1);
			Plot(LineArray(i, t3, BarCount - 1, t3, 0), "", ColorRGB(0, 255, 0), styleDots | styleNoLabel, Null, Null, 0,  1);
			PlotText("Stop Loss\n@" + WriteVal(StopLoss - 0.01, 1.2), BarCount, StopLoss - 0.01, ColorRGB(255, 255, 255));
			PlotText("T1 @" + WriteVal(t1, 1.2), BarCount, t1, ColorRGB(255, 255, 255));
			PlotText("T2 @" + WriteVal(t2, 1.2), BarCount, t2, ColorRGB(255, 255, 255));
			PlotText("T3 @" + WriteVal(t3, 1.2), BarCount, t3, ColorRGB(255, 255, 255));
		}		
		break;
	}
}

//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);

//Volume
/*colorVolume = ParamColor("Volume Area", ColorRGB(0, 0, 0));
Plot(Volume, "", colorVolume, styleArea | styleOwnScale | styleNoLabel, Null, Null, 0, 0, 1);*/

Title = Name() + " - {{INTERVAL}} - {{DATE}} - Open = " + NumToStr(O, 1.2) + ", High = " + NumToStr(H, 1.2) + ", Low = " + NumToStr(L, 1.2) + ", Close = " + NumToStr(C, 1.2) + " (" + WriteVal(ROC(C, 1), 1.2) + "%)"; /*, Volume = " + WriteVal(Volume, 1.2);*/
 
Last edited:

KelvinHand

Well-Known Member
#15
Can anyone post the complete corrected AFL please ?
All the AFL scripts are complete and correct.

The error was due to amibroker Plot() limitation to max 500 time or less.
Regardless of timeframe, whether 5min or 10min.


There are 4 solutions:

Solution 1. To solve this problem, you need to add a max counter =500 in the program to prevent it from overflow.

Solution 2. Do only plot those that are in the visible screen. This is Window Slicing.

Solution 3. Copy the section linearray data which is y=ax+b into a big array of size Barcount. then just plot once will do.

Solution 4: Use Gfx Move() and LineTo() to draw the trendlines


I had posted the solution 2 months ago. It work on my Ver 5.60. Here is the proof of solution 2.
So far, i had not face any errors.




Very Sad. Nobody appreciate it and look into it.
 
Last edited:

amitrandive

Well-Known Member
#16
KelvinHand

I really appreciate your efforts , but am not well versed with AmiBroker coding , so all the steps you have indicated are Greek to me.That is the reason I had requested a completed corrected AFL.

Amit
 

KelvinHand

Well-Known Member
#17
KelvinHand

I really appreciate your efforts , but am not well versed with AmiBroker coding , so all the steps you have indicated are Greek to me.That is the reason I had requested a completed corrected AFL.

Amit
All these thing are not target to non-programmer.
Just that i served it as information for those required to do code changing.

But when people keep having the problem, they are not explaining the errors properly.

The correct code is published in the wisestock by the author which is COMPLETED CORRECTED code that work on the Version 5.60++.

Any Ami version below 5.60, will not work properly.

So you want the COMPLETED CORRECTED code then you need to install
Ami Version 5.60++.


I posted the Modified Code to solve the Plot() issue, which considered COMPLETED CORRECTED CODE for the version 5.60.
You come to this thread and ask "Can anyone post the complete corrected AFL please ? " and bypass my code.

How can i don't feel sad.

If you try out and tell people it not working on your ami version 5.4~5.5, then people will help you to solve the issue.
 
Last edited:

amitrandive

Well-Known Member
#18
Apologize for the incorrect description of the error , but it is not working in Version 5.6 either.
Can you please give the link for the code in wisestocktrader ?
 

KelvinHand

Well-Known Member
#19
Apologize for the incorrect description of the error , but it is not working in Version 5.6 either.
Can you please give the link for the code in wisestocktrader ?
You see, Just this statement, "...but it is not working in Version 5.6 either.",
how to expect for help. No description in details.

No you only. There are a lot of people doing the same thing here.

your problem may not see on my side.
I see no detail, i don't bother, same as other people.




If cannot work on your Ver 5.6, I assume then it will not work for the original link
http://wisestocktrader.com/indicators/3761-trend-line-breakout


Code:
SetChartOptions(0, chartShowArrows | chartShowDates);
SetChartBkColor(ParamColor("Outer Panel", colorBlack));
SetChartBkGradientFill(ParamColor("Upper Chart", colorDarkGrey), ParamColor("Lower Chart", colorDarkGrey));
GraphXSpace = Param("GraphXSpace", 10, 0, 100, 1);

colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));

//Demand Point
colorDemandPoint = ParamColor("Demand Line", ColorRGB(0, 128, 255));
DemandPoint = (Ref(L, -1) < Ref(L, -2)) & (L < Ref(L, -1)) & (L < Ref(L, 1)) & (Ref(L, 1) < Ref(L, 2));

//Supply Point
colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
SupplyPoint = (Ref(H, -1) > Ref(H, -2)) & (H > Ref(H, -1)) & (H > Ref(H, 1)) & (Ref(H, 1) > Ref(H, 2));

CountTrendBars = 0;
//CurrentBar = BarCount - 1;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;


//-- Modified by KelvinHand -----------
function VisiBarsPerChart()
{
    lvb=Status("lastvisiblebar");
    fvb=Status("firstvisiblebar");
    return Min(lvb-fvb,BarCount-fvb);
}


nBars=1.5*VisiBarsPerChart();
if (nBars <BarCount)
 iLimit = (BarCount-1) - nBars;
else
 iLimit = 0;

//------------------------------------

  
for (i = BarCount-1; i>iLimit; i--) {
	if (DemandPoint[i]) {
		if (dx1 == 0 & dy1 == 0) {
			dx1 = i;
			dy1 = L[i];
		} else {
			dx0 = i;
			dy0 = L[i];
		}
		if (dx0 != 0 & dx1 != 0 & dy0 != 0 & dy1 != 0) {
			if (dy0 < dy1) {
				a = (-dy0 + dy1) / (-dx0 + dx1);
				b = dy0 - dx0 * a;
				for (j = dx1; j < BarCount; j++) {
					if (j != dx1) {
						y2 = a * j + b;
						if (C[j] < y2) {
							dy1 = y2;
							dx1 = j;
							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, styleThick);
			}
			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];
		}
		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;
							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, styleThick);

			}
			sx1 = sx0;
			sy1 = sy0;
			sx0 = sy0 = 0;
		}	
	}	
}

//Stop Loss & Targets
for (i = BarCount-1; i>iLimit; i--) {
	if (colorHighliter[i] == ColorRGB(128, 0, 128)) {
		StopLoss = 0;
		for (j = i - CountTrendBars[i]; j <= i; j++) {
			StopLoss = Max(H[j], StopLoss);
		}
		if (i - (BarCount - 1) != 0) {
			t1 = C[i] - (StopLoss - C[i]);
			t2 = C[i] - ((StopLoss - C[i]) * 1.272);
			t3 = C[i] - ((StopLoss - C[i]) * 1.618);
			Plot(LineArray(i, StopLoss + 0.01, BarCount - 1, StopLoss + 0.01, 0), "", colorRed, styleDots | styleNoLabel);
			Plot(LineArray(i, C[i], BarCount - 1, C[i], 0), "", colorYellow, styleDots);
			Plot(LineArray(i, t1, BarCount - 1, t1, 0), "", colorRed, styleDots | styleNoLabel);
			Plot(LineArray(i, t2, BarCount - 1, t2, 0), "", colorRed, styleDots | styleNoLabel);
			Plot(LineArray(i, t3, BarCount - 1, t3, 0), "", colorRed, styleDots | styleNoLabel);
			PlotText("Stop Loss\n@" + WriteVal(StopLoss + 0.01, 1.2), BarCount, StopLoss + 0.01, colorWhite);
			PlotText("T1 @" + WriteVal(t1, 1.2), BarCount, t1, colorWhite);
			PlotText("T2 @" + WriteVal(t2, 1.2), BarCount, t2, colorWhite);
			PlotText("T3 @" + WriteVal(t3, 1.2), BarCount, t3, colorWhite);
		}
		break;
	}
	if (colorHighliter[i] == ColorRGB(128, 128, 0)) {
		StopLoss = 9999;
		for (j = i - CountTrendBars[i]; j <= i; j++) {
			StopLoss = Min(L[j], StopLoss);
		}
		if (i - (BarCount - 1) != 0) {
			t1 = C[i] + (C[i] - StopLoss);
			t2 = C[i] + ((C[i] - StopLoss) * 1.272);
			t3 = C[i] + ((C[i] - StopLoss) * 1.618);
			Plot(LineArray(i, StopLoss - 0.01, BarCount - 1, StopLoss - 0.01, 0), "", colorRed, styleDots | styleNoLabel);
			Plot(LineArray(i, C[i], BarCount - 1, C[i], 0), "", colorYellow, styleDots);
			Plot(LineArray(i, t1, BarCount - 1, t1, 0), "", colorBrightGreen, styleDots | styleNoLabel);
			Plot(LineArray(i, t2, BarCount - 1, t2, 0), "", colorBrightGreen, styleDots | styleNoLabel);
			Plot(LineArray(i, t3, BarCount - 1, t3, 0), "", colorBrightGreen, styleDots | styleNoLabel);
			PlotText("Stop Loss\n@" + WriteVal(StopLoss - 0.01, 1.2), BarCount, StopLoss - 0.01, colorWhite);
			PlotText("T1 @" + WriteVal(t1, 1.2), BarCount, t1, colorWhite);
			PlotText("T2 @" + WriteVal(t2, 1.2), BarCount, t2, colorWhite);
			PlotText("T3 @" + WriteVal(t3, 1.2), BarCount, t3, colorWhite);
		}		
		break;
	}
}

//Price
SetBarFillColor(colorHighliter);
Plot(C, "Close", IIf(colorHighliter == ColorRGB(128, 0, 128), ColorRGB(255, 0, 255), IIf(colorHighliter == ColorRGB(128, 128, 0), colorYellow, IIf(C > O, colorBrightGreen, IIf(C < O, colorRed, colorWhite)))), styleCandle);

//Volume
/*colorVolume = ParamColor("Volume Area", ColorRGB(0, 0, 0));
Plot(Volume, "", colorVolume, styleArea | styleOwnScale | styleNoLabel, Null, Null, 0, 0, 1);*/

Title = Name() + " - {{INTERVAL}} - {{DATE}} - Open = " + NumToStr(O, 1.2) + ", High = " + NumToStr(H, 1.2) + ", Low = " + NumToStr(L, 1.2) + ", Close = " + NumToStr(C, 1.2) + " (" + WriteVal(ROC(C, 1), 1.2) + "%)"; /*, Volume = " + WriteVal(Volume, 1.2);*/
 
Last edited:

Similar threads