Please help me repaint signal

#1
Hi seniors,

I request Trash, Kelvinhand, HappySingh to please help me with this.

I want buy signal on each green candle like in the pic below.


If the next candle cannot breach the high of the green candle then it should repaint and make the signal disappear.


But if high of green candle is broken then the signal should remain as it is.


P.S. I am currently using the condition Ref(h,1)>=h, but this condition doesnot put buy order on every green candle, it puts buy signal only when the next candle breaks the high of the green candle.

I hope someone would help me. I am doing this because I am using an automated system which should send buy signals at every green candle and the automated system deletes the signal if high is not breached. I want to match the automated system and amibroker. Please help me with this weird requirement of mine.

Thanks,
Purusharth
 
Last edited:
#3
I am trying on these lines..

Code:
/*
//whipsaw removal
Buysignal=Shortsignal=0;
for (i=1;i<BarCount-1;i++)
{
if (Buy[i])
	{
		Buy[i]=0;
		Buysignal=1;
		
    }
if (Buysignal==1 AND H[i+1]>=H[i])
    Buy[i]=1;
if (Buysignal==1 AND H[i+1]<H[i])
    Buy[i]=0;
}

*/
I am not experienced in afl.. just giving it a try.
seeking for help.

Thanks,
Purusharth
 
#4
I want the code to do something like this.



Though this code removes repaints following a different logic.
It want it to repaint if the next candle is not able to breach the high of the signal candle.

The code in the image is below.

Code:
_SECTION_BEGIN("Draw Camarilla Levels");
SetChartOptions(0,chartShowArrows|chartShowDates);
showcamarella=ParamList("Show Camarella Lines","YES|NO");
showcandlechart=ParamList("Show Candle chart","YES|NO");
showwhat=IIf(ParamList("Todays or Tomorrows Levels","Today|Tomorrow")=="Tomorrow",1,-1);
showinnertarget=ParamList("Show inner targets?","YES|NO",1);
showoutertarget=ParamList("Show outer targets?","YES|NO",1);
targetoption=ParamList("Target option ","1|2",0);
//Target option 1 = 0.5% and 0.1% from R2 levels
//Target option 2 = High/Low * Close and Low/High x Close
InCamparameter=Param("Modify Inner Cam parameter",1.1,0.5,2,0.1);
OutCamparameter=Param("Modify Outer Cam parameter",1.1,0.5,2,0.1);


if (showcandlechart=="YES")
{
	Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
}
EMA10=EMA(C,10);
EMA3=EMA(C,3);
Plot(EMA10,"EMA10", colorWhite,styleLine|styleNoLabel);
Plot(EMA3,"EMA3", colorGreen,styleLine|styleNoLabel);

XH = TimeFrameGetPrice( "H", inDaily,showwhat);
XL = TimeFrameGetPrice( "L", inDaily,showwhat);
XC = TimeFrameGetPrice( "C", inDaily, showwhat );



r2=(((xh-xl)*OutCamparameter)/2)+xc;
r1=(((xh-xl)*InCamparameter)/4)+xc;
s1=(xc-((xh-xl)*InCamparameter)/4);
s2=(xc-((xh-xl)*OutCamparameter)/2);
n3=1;
tgt1=(1+.005*n3)*r2;
tgt2=(1+.01*n3)*r2;
tgt3=s2/(1+.005*n3);
tgt4=s2/(1+.01*n3);


if (showcamarella=="YES")
{
Plot(r1,"R1",colorGreen,styleLine|styleDashed|styleNoTitle);
Plot(r2,"R2",colorGreen,styleLine|styleDashed|styleNoTitle);
Plot(s1,"S1",colorRed,styleLine|styleDashed|styleNoTitle);
Plot(s2,"S2",colorRed,styleLine|styleDashed|styleNoTitle);
if (showoutertarget=="YES" AND targetoption=="1")
{
	Plot(tgt1,"tgt1",colorYellow,styleLine|styleDashed|styleNoTitle);
	Plot(tgt2,"tgt2",colorYellow,styleLine|styleDashed|styleNoTitle);
	Plot(tgt3,"tgt3",colorYellow,styleLine|styleDashed|styleNoTitle);
	Plot(tgt4,"tgt4",colorYellow,styleLine|styleDashed|styleNoTitle);
}
if (showoutertarget=="YES" AND targetoption=="2")
{
	Plot((xh/xl*xc),"tgt1",colorYellow,styleLine|styleDashed|styleNoTitle);
	Plot((xl/xh*xc),"tgt3",colorYellow,styleLine|styleDashed|styleNoTitle);
}

if (showinnertarget=="YES")
{
	Plot(s1+(0.85*(r1-s1)),"int long target 2",colorBlue,styleLine|styleDashed|styleNoTitle);
	Plot(s1+(0.65*(r1-s1)),"int long target 1",colorBlue,styleLine|styleDashed|styleNoTitle);
	Plot(s1+(0.35*(r1-s1)),"int short target 1",colorPink,styleLine|styleDashed|styleNoTitle);
	Plot(s1+(0.15*(r1-s1)),"int short target 2",colorPink,styleLine|styleDashed|styleNoTitle);
}
Buy=Cross(C,s1) OR Cross(C,r1) OR Cross(C,r2);
Sell=Cross(r1,C) OR Cross(s1,C) OR Cross(s2,C) OR TimeNum()>144500;
//Cover=Buy;
//Sell=Short;

//parameters
gapavg=Param("Gap between Averages",8,0,20,.1);
gapcam=Param("Gap between Cam lines and fast avg",3.8,0,20,.1);
SP=Param("Stop Profit",23,0,25,.1);

Camlevel=IIf(abs(EMA3-r1)<abs(EMA3-r2),r1,r2);
Camlevel=IIf(abs(EMA3-s1)<abs(EMA3-r1),s1,Camlevel);
Camlevel=IIf(abs(EMA3-s2)<abs(EMA3-s1),s2,Camlevel);
Cvp=(O+C)/2;

Datex=DateNum();
//whipsaw removal
Buysignal=Sellsignal=lastbuy=lastsell=priceatbuy=priceatsell=slow=shigh=exitbuy=exitsell=curri=priceatexitbuy=priceatexitsell=0;
Lastexitsell=Lastexitbuy=profit=lastprofit=0;
for (i=1;i<BarCount-1;i++)
{
//change of day initialise variables
	if(Datex[i]!=Datex[i-1])
	{
		if (lastbuy==1)Lastprofit=profit[i-1]+Cvp[i-1]-priceatbuy;
		else if (Lastsell==1)Lastprofit=profit[i-1]+priceatsell-Cvp[i-1];
		else Lastprofit=profit[i-1];
		PlotText("Profit\n"+WriteVal(Lastprofit,1.0),i,H[i]+15,colorWhite);
		Buysignal=Sellsignal=lastbuy=lastsell=priceatbuy=priceatsell=curri=lastexitsell=lastexitbuy=0;
		profit[i]=0;
		
	}
	if(i==BarCount-2)
	{
		if (lastbuy==1)Lastprofit=profit[i]+Cvp[i]-priceatbuy;
		else if (Lastsell==1)Lastprofit=profit[i]+priceatsell-Cvp[i];
		else Lastprofit=profit[i-1];
		PlotText("Profit\n"+WriteVal(Lastprofit,1.0),i,H[i]+15,colorWhite);
	}


	if (Datex[i]==Datex[i-1])
	{
		shigh[i]=shigh[i-1];
		slow[i]=slow[i-1];
		profit[i]=profit[i-1];
	}
	if (H[i]>shigh[i])shigh[i]=H[i];
	if (L[i]<slow[i])slow[i]=L[i];
	if (Buy[i])
	{
		Buy[i]=0;
		Buysignal=1;
		Sellsignal=0;
	}
	if (Sell[i])
	{
		Sell[i]=0;
		Sellsignal=1;
		Buysignal=0;
	}
//	PlotText(WriteVal(profit[i],1.0),i,H[i]+5,colorWhite);
	if (Buysignal==1 AND ((EMA3[i]-EMA10[i]>gapavg) OR (EMA3[i]>EMA10[i])) AND EMA3[i]-Camlevel[i]>gapcam AND O[i]<C[i] )
	{
		if (lastbuy==1)profit[i]=profit[i]+Cvp[i]-priceatbuy;
		if (Lastsell==1)profit[i]=profit[i]+priceatsell-Cvp[i];
		Lastbuy=Lastsell=lastexitbuy=lastexitsell=0;
		Buysignal=0;
		Buy[i]=1;
		Lastbuy=1;
		priceatbuy=Cvp[i];
		slow[i]=L[i];
		shigh[i]=H[i];
		Curri=i;
	}
	if (SellSignal==1 AND ((EMA10[i]-EMA3[i]>gapavg) OR (EMA10[i]>EMA3[i])) AND Camlevel[i]-EMA3[i]>gapcam AND O[i]>C[i])
	{
		if (lastbuy==1)profit[i]=profit[i]+Cvp[i]-priceatbuy;
		if (Lastsell==1)profit[i]=profit[i]+priceatsell-Cvp[i];
		Lastbuy=Lastsell=lastexitbuy=lastexitsell=0;
		Sellsignal=0;
		Sell[i]=1;
		Lastsell=1;
		priceatsell=Cvp[i];
		slow[i]=L[i];
		shigh[i]=H[i];
		Curri=i;
	}
	if ((Lastbuy==1 OR (lastexitbuy==1 AND cvp[i]-priceatexitbuy>4)) AND shigh[i]-Cvp[i]>sp AND !Sell[i] AND i>Curri)
	{
		profit[i]=profit[i]+Cvp[i]-priceatbuy;
		exitbuy[i]=1;
		Lastexitbuy=1;
		Lastbuy=0;
		slow[i]=L[i];
		shigh[i]=H[i];
		priceatexitbuy=Cvp[i];
		Curri=i;
	}
	if ((Lastsell==1 OR (Lastexitsell==1 AND priceatexitsell-Cvp[i]>4)) AND Cvp[i]-slow[i]>sp AND !Buy[i] AND i>Curri)
	{
		profit[i]=profit[i]+priceatsell-Cvp[i];
		exitsell[i]=1;
		Lastexitsell=1;
		Lastsell=0;
		slow[i]=L[i];
		shigh[i]=H[i];
		priceatexitsell=Cvp[i];
		Curri=i;
	}
	if (i>Curri AND Lastexitsell==1 AND priceatexitsell-Cvp[i]>4)
	{
		Sellsignal=1;
		Lastexitsell=0;
	}
	if (i>Curri AND Lastexitbuy==1 AND Cvp[i]-priceatexitbuy>4)
	{
		buySignal=1;
		Lastexitbuy=0;
	}

	if (Buy[i] OR Sell[i] OR exitbuy[i] OR exitsell[i])
	{
	PlotText(WriteVal(Profit[i],1.0),i,H[i]+15,colorGreen);
	}

	

}









shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorLime, colorRed ), 0, IIf( Buy, Low, High));
shape2 = exitsell *shapeHollowUpArrow + exitbuy *shapeHollowDownArrow;
PlotShapes( shape2, IIf( exitsell, colorWhite, colorWhite ), 0, IIf( exitsell, Low, High));


}

function GetSecondNum()
{
    Time 		= Now( 4 );
    Seconds 	= int( Time % 100 );
    Minutes 	= int( Time / 100 % 100 );
    Hours 	= int( Time / 10000 % 100 );
    SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
    return SecondNum;
}
 


RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft	 = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo	 = TimeFrame - SecsLeft;


Title = Date()+"  "+ Interval(format=2)+"  "+Name()+" O "+WriteVal(O,1.2)+" H "+WriteVal(H,1.2)+"  L "+WriteVal(L,1.2)+" C "+WriteVal(C,1.2)+" Cam level " + WriteVal(Camlevel,1.2)+" Fast avg "+WriteVal(EMA3,1.2)+" CurrHigh "+WriteVal(shigh,1.2)+" Currlow "+WriteVal(slow,1.2)+" Avg Price "+WriteVal(Cvp,1.2)+" "+ EncodeColor(colorYellow)+ " Bar secs remaining "+WriteVal(secstogo,1.0);
Hope someone helps me.

Purusharth
 

Similar threads