How to plot Buy/Sell signals on Range High/Low

I have been trying to add signals to the Range High and Low that I've plotted. I want the respective Buy and sell signals whenever the price crosses above or below the N days High Low. Here I have used the cross function but have also tried the same using comparison operators on close and RH/RL. None of them is working. the code does not give any errors but it does not plot any signals on chart either. What am I doing wrong here?

/* 
Objective:
1. add chart settings
2. add price
3. consider range high and low of previous 4 days
4. add lines to the highest and lowest points.
5. add signals when price crosses above or below the lines
*/


_SECTION_BEGIN("Price");
	SetChartOptions(0,chartShowArrows|chartShowDates); //Enables the X-axis to the chart
	Plot(Close,"Price",colorDefault,styleCandle);
	
_SECTION_END();

_SECTION_BEGIN("RHRL");
	RH = Plot(Ref(HHV(High, 4),-1),"RH", colorred);
	RL = Plot(Ref(LLV(Low, 4), -1),"RL", colorGreen);
		
		Buy = Cross(Close,RH);
		Sell = Cross(RL, Close);		

			PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, H, Offset=-40);
			PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,H, Offset=-50);
			PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,H, Offset=-45);
			PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-40);
			PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
			PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,L, Offset=-45);
			
_SECTION_END();		

Your use of Plot() is not correct.
Plot does not return (plotted) array but number. Plot just plots array.

9

To further work with plotted arrays store them to variables before.

/* 
Objective:
1. add chart settings
2. add price
3. consider range high and low of previous 4 days
4. add lines to the highest and lowest points.
5. add signals when price crosses above or below the lines
*/

_SECTION_BEGIN("Price");
	SetChartOptions(0,chartShowArrows|chartShowDates); //Enables the X-axis to the chart
	Plot(Close,"Price",colorDefault,styleCandle);
_SECTION_END();


_SECTION_BEGIN("RHRL");
	RH = Ref(HHV(High, 4),-1);
	RL = Ref(LLV(Low, 4), -1);

	Buy = Cross(Close,RH);
	Sell = Cross(RL, Close);	

	Plot(RH,"RH", colorred);
	Plot(RL,"RL", colorGreen);	

	PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, H, Offset=-40);
	PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,H, Offset=-50);
	PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,H, Offset=-45);
	PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-40);
	PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
	PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,L, Offset=-45);
_SECTION_END();	

These are all (basic) programming questions which can be found out easily by user herself/himself if following AmiBroker user guide. It is just a matter of reading existing documentation explaining everything in sharp detail already. To summarize... AmiBroker AFL works properly without bugs. It has been existing for more than two decades already. For further programming questions please read here before.


https://www.amibroker.com/guide/h_understandafl.html

1 Like