AFL help needed to plot lines

this is more or less the code I posted earlier adding HH, HL, LL, etc

add chart also how it should look

PHP:
// code by E.M.Pottasch, Jan 2015
SetBarsRequired(sbrAll,sbrAll);
xx=BarIndex();Lx=LastValue(xx); 
rightStrength=Param("Right Strength (Major Pivot)",5,1,50,1);
leftStrength=Param("Left Strength (Major Pivot)",5,1,50,1);
rightStrength_mini=Param("Right Strength (Mini Pivot)",3,1,50,1);
leftStrength_mini=Param("Left Strength (Mini Pivot)",3,1,50,1);
tf=Param("Time Frame (Minutes)",5,1,1440,1);tfrm=in1Minute*tf;
slippageFactor=Param("Slippage Factor",0,0,10,1);
useMiniStop=ParamToggle("Exit Type","Major Pivot Stop and Reverse|Mini Pivot Stop",1);
fvb=0;lvb=BarCount;

SetTradeDelays(0,0,0,0);
SetOption("CommissionMode",3);
SetOption("CommissionAmount",2.01);
SetOption("FuturesMode",True);
NumContracts=1;//StaticVarGet("NumContractsSV");
PositionSize=NumContracts*MarginDeposit;
SetOption("MaxOpenPositions",4);

slip=TickSize*slippageFactor;

function handleSignals(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice)
{
global BuyAdjusted;
global BuyPriceAdjusted;
global ShortAdjusted;
global ShortPriceAdjusted;
global SellAdjusted;
global SellPriceAdjusted;
global CoverAdjusted;
global CoverPriceAdjusted;
global longTarget;
global shortTarget;

BuyAdjusted=0;
BuyPriceAdjusted=0;
ShortAdjusted=0;
ShortPriceAdjusted=0;
SellAdjusted=0;
SellPriceAdjusted=0;
CoverAdjusted=0;
CoverPriceAdjusted=0;

for(i=fvb;i<lvb;i++) 
{
	if(Buy[i])
	{
		BuyAdjusted[i]=1;
		BuypriceAdjusted[i]=Min(BuyPrice[i]+slip,H[i]);
		
		for(j=i+1;j<BarCount;j++) 
		{					
			if(Sell[j])
			{
				SellAdjusted[j]=1;
				SellPriceAdjusted[j]=Max(SellPrice[j]-slip,L[j]);
				i=j-1;
				break;				
			}
			else if(Short[j])
			{
				SellAdjusted[j]=1;
				SellPriceAdjusted[j]=Max(ShortPrice[j]-slip,L[j]);
				i=j-1;
				break;				
			}
			else if(j==BarCount-1)
			{
				i=j;
				break;
			}						
		}
	}
	else if(Short[i])
	{
		ShortAdjusted[i]=1;
		ShortPriceAdjusted[i]=Max(ShortPrice[i]-slip,L[i]);
		
		for(j=i+1;j<BarCount;j++) 
		{					
			if(Cover[j])
			{
				CoverAdjusted[j]=1;
				CoverPriceAdjusted[j]=Min(CoverPrice[j]+slip,H[j]);
				i=j-1;
				break;				
			}
			else if(Buy[j])
			{
				CoverAdjusted[j]=1;
				CoverPriceAdjusted[j]=Min(BuyPrice[j]+slip,H[j]);
				i=j-1;
				break;				
			}
			else if(j==BarCount-1)
			{
				i=j;
				break;
			}										
		}
	}

}
}
function pkID(rightStrength,leftStrength)
{
	pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength);
	return pk;
}
function trID(rightStrength,leftStrength)
{
	tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength);
	return tr;
}

TimeFrameSet(tfrm); 
	pk=pkID(rightStrength,leftStrength);
	tr=trID(rightStrength,leftStrength);
	pkh=IIf(pk,H,Null);
	trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
	pk=TimeFrameExpand(pk,tfrm,expandFirst);
	pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
	pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
	pk=pk AND H==pkh;
	cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
	pk=pk AND cond1;
	
	tr=TimeFrameExpand(tr,tfrm,expandFirst);	
	trl=TimeFrameExpand(trl,tfrm,expandFirst);
	trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
	tr=tr AND L==trl;
	cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
	tr=tr AND cond1;
}

px0=ValueWhen(pk,xx,0); tx0=ValueWhen(tr,xx,0);
px1=ValueWhen(pk,xx,1); tx1=ValueWhen(tr,xx,1);
px2=ValueWhen(pk,xx,2); tx2=ValueWhen(tr,xx,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
 
ll=tr AND tl1<tl2;
hl=tr AND tl1>tl2;
hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2;
dt=pk AND ph1==ph2;
db=tr AND tl1==tl2;

pkm=pkID(rightStrength_mini,leftStrength_mini);
trm=trID(rightStrength_mini,leftStrength_mini);

pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength*fact+fact));
trLow1=Ref(ValueWhen(tr,L,1),-(rightStrength*fact+fact));
pkmHigh1=Ref(ValueWhen(pkm,H,1),-(rightStrength_mini+1));
trmLow1=Ref(ValueWhen(trm,L,1),-(rightStrength_mini+1));
		
SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1);
PlotShapes(shapeCircle*tr,IIf(Lx-ValueWhen(tr,xx)>rightStrength*fact+fact,ColorRGB(0,255,0),colorWhite),0,L,-10);
PlotShapes(shapeCircle*pk,IIf(Lx-ValueWhen(pk,xx)>rightStrength*fact+fact,ColorRGB(255,0,0),colorWhite),0,H,10);
PlotShapes(shapeSmallCircle*trm,IIf(Lx-ValueWhen(trm,xx)>rightStrength_mini,ColorRGB(0,70,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pkm,IIf(Lx-ValueWhen(pkm,xx)>rightStrength_mini,ColorRGB(70,0,0),colorWhite),0,H,10);

Plot(pkHigh1,"",colorBlue,1,Null,Null,0,-1,3);
Plot(trLow1,"",colorRed,1,Null,Null,0,-1,3);

Buy=(Cross(H,pkHigh1) OR (Ref(C,-1)<pkHigh1 AND H>pkHigh1)) AND pkHigh1>trmLow1;BuyPrice=Max(O,pkHigh1);
Short=(Cross(trLow1,L) OR (Ref(C,-1)>trLow1 AND L<trLow1)) AND trLow1<pkmHigh1;ShortPrice=Min(O,trLow1);

if(useMiniStop)
{
	Sell=Cross(trmLow1,L);SellPrice=Min(O,trmLow1);
	Cover=Cross(H,pkmHigh1);CoverPrice=Max(O,pkmHigh1);
	Plot(pkmHigh1,"",colorBlue,styledashed,Null,Null,0,0,1);
	Plot(trmLow1,"",colorRed,styledashed,Null,Null,0,0,1);
}
else
{
	Sell=Cross(trLow1,L);SellPrice=Min(O,trLow1);
	Cover=Cross(H,pkHigh1);CoverPrice=Max(O,pkHigh1);
}

handleSignals(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice);
Buy=BuyAdjusted;
BuyPrice=BuyPriceAdjusted;
Short=ShortAdjusted;
ShortPrice=ShortPriceAdjusted;
Sell=SellAdjusted;
SellPrice=SellPriceAdjusted;
Cover=CoverAdjusted;
CoverPrice=CoverPriceAdjusted;

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorDarkGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),colorRed,0,H,IIf(Short AND Sell,-30,-15));
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
PlotShapes(IIf(Cover,shapeSmallUpTriangle,shapeNone),colorDarkGreen,0,L,IIf(Cover AND Buy,-30,-15));
Plotshapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0);

fvb=Status("firstvisiblebarindex");
lvb=Min(Lx,Status("lastvisiblebarindex"));

for(i=fvb;i<lvb;i++) 
{
	if(ll[i]) PlotTextSetFont("LL","Arial Black",8,i,L[i],colorGreen,colorDefault,-30); 
	if(hl[i]) PlotTextSetFont("HL","Arial Black",8,i,L[i],colorGreen,colorDefault,-30); 
	if(db[i]) PlotTextSetFont("DB","Arial Black",8,i,L[i],colorLightBlue,colorDefault,-30); 
	if(hh[i]) PlotTextSetFont("HH","Arial Black",8,i,H[i],colorRed,colorDefault,20); 
	if(lh[i]) PlotTextSetFont("LH","Arial Black",8,i,H[i],colorRed,colorDefault,20); 
	if(dt[i]) PlotTextSetFont("DT","Arial Black",8,i,H[i],colorOrange,colorDefault,20);
}
 

Attachments

mechtrader

Well-Known Member
Hi Edward,
One thing that I think will filter out most false trades (also some good ones) is that the PH on which we enter should be greater than the prev pivot high that was made.

PFA image.



Thanks,
MT
HI Edward,

Thanx for your effort in adjusting the code but i think i was not able to explain the req properly.

Here in the image the blue line represents the Pivot high of the major time frame. (pkHigh1 in your code).
The code triggers a buy when price crosses pkHigh1.

What I want is buy should be triggered when 1) Cross(H,pkHigh1) 2) pkHigh1
is greater than the prev pkHigh1 value.

Reverse logic for shorts.

The pic explains two failed trades because pkHigh1 was not greater than prev pkHigh1 value.

I hope I have made my req clearer this time.

Thanks for your time,
MT
 
HI Edward,

Thanx for your effort in adjusting the code but i think i was not able to explain the req properly.

Here in the image the blue line represents the Pivot high of the major time frame. (pkHigh1 in your code).
The code triggers a buy when price crosses pkHigh1.

What I want is buy should be triggered when 1) Cross(H,pkHigh1) 2) pkHigh1
is greater than the prev pkHigh1 value.

Reverse logic for shorts.

The pic explains two failed trades because pkHigh1 was not greater than prev pkHigh1 value.

I hope I have made my req clearer this time.

Thanks for your time,
MT
ok yes I see what you mean. Check this if it is correct. The prev pkHigh1 and trLow1 are shown as faint blue and red lines. I call them pkHigh2 and trLow2 in the code, best regards

PHP:
// code by E.M.Pottasch, Jan 2015
SetBarsRequired(sbrAll,sbrAll);
xx=BarIndex();Lx=LastValue(xx); 
rightStrength=Param("Right Strength (Major Pivot)",5,1,50,1);
leftStrength=Param("Left Strength (Major Pivot)",5,1,50,1);
rightStrength_mini=Param("Right Strength (Mini Pivot)",3,1,50,1);
leftStrength_mini=Param("Left Strength (Mini Pivot)",3,1,50,1);
tf=Param("Time Frame (Minutes)",5,1,1440,1);tfrm=in1Minute*tf;
slippageFactor=Param("Slippage Factor",0,0,10,1);
useMiniStop=ParamToggle("Exit Type","Major Pivot Stop and Reverse|Mini Pivot Stop",1);
fvb=0;lvb=BarCount;

SetTradeDelays(0,0,0,0);
SetOption("CommissionMode",3);
SetOption("CommissionAmount",2.01);
SetOption("FuturesMode",True);
NumContracts=1;//StaticVarGet("NumContractsSV");
PositionSize=NumContracts*MarginDeposit;
SetOption("MaxOpenPositions",4);

slip=TickSize*slippageFactor;

function handleSignals(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice)
{
global BuyAdjusted;
global BuyPriceAdjusted;
global ShortAdjusted;
global ShortPriceAdjusted;
global SellAdjusted;
global SellPriceAdjusted;
global CoverAdjusted;
global CoverPriceAdjusted;
global longTarget;
global shortTarget;

BuyAdjusted=0;
BuyPriceAdjusted=0;
ShortAdjusted=0;
ShortPriceAdjusted=0;
SellAdjusted=0;
SellPriceAdjusted=0;
CoverAdjusted=0;
CoverPriceAdjusted=0;

for(i=fvb;i<lvb;i++) 
{
	if(Buy[i])
	{
		BuyAdjusted[i]=1;
		BuypriceAdjusted[i]=Min(BuyPrice[i]+slip,H[i]);
		
		for(j=i+1;j<BarCount;j++) 
		{					
			if(Sell[j])
			{
				SellAdjusted[j]=1;
				SellPriceAdjusted[j]=Max(SellPrice[j]-slip,L[j]);
				i=j-1;
				break;				
			}
			else if(Short[j])
			{
				SellAdjusted[j]=1;
				SellPriceAdjusted[j]=Max(ShortPrice[j]-slip,L[j]);
				i=j-1;
				break;				
			}
			else if(j==BarCount-1)
			{
				i=j;
				break;
			}						
		}
	}
	else if(Short[i])
	{
		ShortAdjusted[i]=1;
		ShortPriceAdjusted[i]=Max(ShortPrice[i]-slip,L[i]);
		
		for(j=i+1;j<BarCount;j++) 
		{					
			if(Cover[j])
			{
				CoverAdjusted[j]=1;
				CoverPriceAdjusted[j]=Min(CoverPrice[j]+slip,H[j]);
				i=j-1;
				break;				
			}
			else if(Buy[j])
			{
				CoverAdjusted[j]=1;
				CoverPriceAdjusted[j]=Min(BuyPrice[j]+slip,H[j]);
				i=j-1;
				break;				
			}
			else if(j==BarCount-1)
			{
				i=j;
				break;
			}										
		}
	}

}
}
function pkID(rightStrength,leftStrength)
{
	pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength);
	return pk;
}
function trID(rightStrength,leftStrength)
{
	tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength);
	return tr;
}

TimeFrameSet(tfrm); 
	pk=pkID(rightStrength,leftStrength);
	tr=trID(rightStrength,leftStrength);
	pkh=IIf(pk,H,Null);
	trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
	pk=TimeFrameExpand(pk,tfrm,expandFirst);
	pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
	pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
	pk=pk AND H==pkh;
	cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
	pk=pk AND cond1;
	
	tr=TimeFrameExpand(tr,tfrm,expandFirst);	
	trl=TimeFrameExpand(trl,tfrm,expandFirst);
	trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
	tr=tr AND L==trl;
	cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
	tr=tr AND cond1;
}

px0=ValueWhen(pk,xx,0); tx0=ValueWhen(tr,xx,0);
px1=ValueWhen(pk,xx,1); tx1=ValueWhen(tr,xx,1);
px2=ValueWhen(pk,xx,2); tx2=ValueWhen(tr,xx,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
 
ll=tr AND tl1<tl2;
hl=tr AND tl1>tl2;
hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2;
dt=pk AND ph1==ph2;
db=tr AND tl1==tl2;

pkm=pkID(rightStrength_mini,leftStrength_mini);
trm=trID(rightStrength_mini,leftStrength_mini);

pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength*fact+fact));
trLow1=Ref(ValueWhen(tr,L,1),-(rightStrength*fact+fact));
pkHigh2=Ref(ValueWhen(pk,H,2),-(rightStrength*fact+fact));
trLow2=Ref(ValueWhen(tr,L,2),-(rightStrength*fact+fact));
pkmHigh1=Ref(ValueWhen(pkm,H,1),-(rightStrength_mini+1));
trmLow1=Ref(ValueWhen(trm,L,1),-(rightStrength_mini+1));
		
SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1);
PlotShapes(shapeCircle*tr,IIf(Lx-ValueWhen(tr,xx)>rightStrength*fact+fact,ColorRGB(0,255,0),colorWhite),0,L,-10);
PlotShapes(shapeCircle*pk,IIf(Lx-ValueWhen(pk,xx)>rightStrength*fact+fact,ColorRGB(255,0,0),colorWhite),0,H,10);
PlotShapes(shapeSmallCircle*trm,IIf(Lx-ValueWhen(trm,xx)>rightStrength_mini,ColorRGB(0,70,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pkm,IIf(Lx-ValueWhen(pkm,xx)>rightStrength_mini,ColorRGB(70,0,0),colorWhite),0,H,10);

Plot(pkHigh1,"",colorBlue,1,Null,Null,0,-1,3);
Plot(trLow1,"",colorRed,1,Null,Null,0,-1,3);
Plot(pkHigh2,"",ColorRGB(0,0,100),1,Null,Null,0,-1,1);
Plot(trLow2,"",ColorRGB(100,0,0),1,Null,Null,0,-1,1);

Buy=(Cross(H,pkHigh1) OR (Ref(C,-1)<pkHigh1 AND H>pkHigh1)) AND pkHigh1>pkHigh2 AND pkHigh1>trmLow1;BuyPrice=Max(O,pkHigh1);
Short=(Cross(trLow1,L) OR (Ref(C,-1)>trLow1 AND L<trLow1)) AND trLow1<trLow2 AND trLow1<pkmHigh1;ShortPrice=Min(O,trLow1);

if(useMiniStop)
{
	Sell=Cross(trmLow1,L);SellPrice=Min(O,trmLow1);
	Cover=Cross(H,pkmHigh1);CoverPrice=Max(O,pkmHigh1);
	Plot(pkmHigh1,"",colorBlue,styledashed,Null,Null,0,0,1);
	Plot(trmLow1,"",colorRed,styledashed,Null,Null,0,0,1);
}
else
{
	Sell=Cross(trLow1,L);SellPrice=Min(O,trLow1);
	Cover=Cross(H,pkHigh1);CoverPrice=Max(O,pkHigh1);
}

handleSignals(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice);
Buy=BuyAdjusted;
BuyPrice=BuyPriceAdjusted;
Short=ShortAdjusted;
ShortPrice=ShortPriceAdjusted;
Sell=SellAdjusted;
SellPrice=SellPriceAdjusted;
Cover=CoverAdjusted;
CoverPrice=CoverPriceAdjusted;

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorDarkGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),colorRed,0,H,IIf(Short AND Sell,-30,-15));
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
PlotShapes(IIf(Cover,shapeSmallUpTriangle,shapeNone),colorDarkGreen,0,L,IIf(Cover AND Buy,-30,-15));
Plotshapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0);

fvb=Status("firstvisiblebarindex");
lvb=Min(Lx,Status("lastvisiblebarindex"));

for(i=fvb;i<lvb;i++) 
{
	if(ll[i]) PlotTextSetFont("LL","Arial Black",8,i,L[i],colorGreen,colorDefault,-30); 
	if(hl[i]) PlotTextSetFont("HL","Arial Black",8,i,L[i],colorGreen,colorDefault,-30); 
	if(db[i]) PlotTextSetFont("DB","Arial Black",8,i,L[i],colorLightBlue,colorDefault,-30); 
	if(hh[i]) PlotTextSetFont("HH","Arial Black",8,i,H[i],colorRed,colorDefault,20); 
	if(lh[i]) PlotTextSetFont("LH","Arial Black",8,i,H[i],colorRed,colorDefault,20); 
	if(dt[i]) PlotTextSetFont("DT","Arial Black",8,i,H[i],colorOrange,colorDefault,20);
}
 
added some flickering arrows to make signals more visible (i know how to waste my time).

replace section of code with this:

PHP:
RequestTimedRefresh(0.1);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),ColorRGB(0,mtRandom()*102,0),0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),ColorRGB(mtRandom()*255,0,0),0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),ColorRGB(mtRandom()*255,0,0),0,H,IIf(Short AND Sell,-30,-15));
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
PlotShapes(IIf(Cover,shapeSmallUpTriangle,shapeNone),ColorRGB(0,mtRandom()*102,0),0,L,IIf(Cover AND Buy,-30,-15));
Plotshapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0);
 

Attachments

casoni

Well-Known Member
added some flickering arrows to make signals more visible (i know how to waste my time).

replace section of code with this:

PHP:
RequestTimedRefresh(0.1);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),ColorRGB(0,mtRandom()*102,0),0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),ColorRGB(mtRandom()*255,0,0),0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),ColorRGB(mtRandom()*255,0,0),0,H,IIf(Short AND Sell,-30,-15));
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
PlotShapes(IIf(Cover,shapeSmallUpTriangle,shapeNone),ColorRGB(0,mtRandom()*102,0),0,L,IIf(Cover AND Buy,-30,-15));
Plotshapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0);

Thank you sir ,its really nice / small code for blinking , now its very easy viewing
:)
 
sir , actually we can plot only one multi tf pivot line using current formula ,
i mean to say that if 15m , hourly and daily also can be plotted along with regular 5m tf , than a great help .
all tf's pivot line(peaks,bottom's) plotted in 5m tf .
here , intention is to trade the major confluence line , where multiple tf's pivot line are at same point .
dell, I made some code that adds the 15m, 60m and daily pivot lines. Code is getting slow now and it looks messy. If you find something that could be used let me know. The timeframe corresponding to the pivot lines is plotted at the right of the chart in seconds

PHP:
// code by E.M.Pottasch, Jan 2015
SetBarsRequired(sbrAll,sbrAll);
xx=BarIndex();Lx=LastValue(xx); 
rightStrength=Param("Right Strength (Major Pivot)",5,1,50,1);
leftStrength=Param("Left Strength (Major Pivot)",5,1,50,1);
rightStrength_mini=Param("Right Strength (Mini Pivot)",3,1,50,1);
leftStrength_mini=Param("Left Strength (Mini Pivot)",3,1,50,1);
tf=Param("Time Frame (Minutes)",5,1,1440,1);tfrm=in1Minute*tf;
slippageFactor=Param("Slippage Factor",0,0,10,1);
useMiniStop=ParamToggle("Exit Type","Major Pivot Stop|Mini Pivot Stop",1);
blinkOnOff=ParamToggle("Blinking signal arrows","Blink Off|Blink On",0);
fvb=0;lvb=BarCount;
if(blinkOnOff)
	bbb=mtRandom();
else
	bbb=1;

SetTradeDelays(0,0,0,0);
SetOption("CommissionMode",3);
SetOption("CommissionAmount",2.01);
SetOption("FuturesMode",True);
NumContracts=1;//StaticVarGet("NumContractsSV");
PositionSize=NumContracts*MarginDeposit;
SetOption("MaxOpenPositions",4);

slip=TickSize*slippageFactor;

function handleSignals(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice)
{
global BuyAdjusted;
global BuyPriceAdjusted;
global ShortAdjusted;
global ShortPriceAdjusted;
global SellAdjusted;
global SellPriceAdjusted;
global CoverAdjusted;
global CoverPriceAdjusted;
global longTarget;
global shortTarget;

BuyAdjusted=0;
BuyPriceAdjusted=0;
ShortAdjusted=0;
ShortPriceAdjusted=0;
SellAdjusted=0;
SellPriceAdjusted=0;
CoverAdjusted=0;
CoverPriceAdjusted=0;

for(i=fvb;i<lvb;i++) 
{
	if(Buy[i])
	{
		BuyAdjusted[i]=1;
		BuypriceAdjusted[i]=Min(BuyPrice[i]+slip,H[i]);
		
		for(j=i+1;j<BarCount;j++) 
		{					
			if(Sell[j])
			{
				SellAdjusted[j]=1;
				SellPriceAdjusted[j]=Max(SellPrice[j]-slip,L[j]);
				i=j-1;
				break;				
			}
			else if(Short[j])
			{
				SellAdjusted[j]=1;
				SellPriceAdjusted[j]=Max(ShortPrice[j]-slip,L[j]);
				i=j-1;
				break;				
			}
			else if(j==BarCount-1)
			{
				i=j;
				break;
			}						
		}
	}
	else if(Short[i])
	{
		ShortAdjusted[i]=1;
		ShortPriceAdjusted[i]=Max(ShortPrice[i]-slip,L[i]);
		
		for(j=i+1;j<BarCount;j++) 
		{					
			if(Cover[j])
			{
				CoverAdjusted[j]=1;
				CoverPriceAdjusted[j]=Min(CoverPrice[j]+slip,H[j]);
				i=j-1;
				break;				
			}
			else if(Buy[j])
			{
				CoverAdjusted[j]=1;
				CoverPriceAdjusted[j]=Min(BuyPrice[j]+slip,H[j]);
				i=j-1;
				break;				
			}
			else if(j==BarCount-1)
			{
				i=j;
				break;
			}										
		}
	}

}
}
function pkID(rightStrength,leftStrength)
{
	pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength);
	return pk;
}
function trID(rightStrength,leftStrength)
{
	tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength);
	return tr;
}

TimeFrameSet(tfrm); 
	pk=pkID(rightStrength,leftStrength);
	tr=trID(rightStrength,leftStrength);
	pkh=IIf(pk,H,Null);
	trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
	pk=TimeFrameExpand(pk,tfrm,expandFirst);
	pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
	pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
	pk=pk AND H==pkh;
	cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
	pk=pk AND cond1;
	
	tr=TimeFrameExpand(tr,tfrm,expandFirst);	
	trl=TimeFrameExpand(trl,tfrm,expandFirst);
	trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
	tr=tr AND L==trl;
	cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
	tr=tr AND cond1;
}

px0=ValueWhen(pk,xx,0); tx0=ValueWhen(tr,xx,0);
px1=ValueWhen(pk,xx,1); tx1=ValueWhen(tr,xx,1);
px2=ValueWhen(pk,xx,2); tx2=ValueWhen(tr,xx,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
 
ll=tr AND tl1<tl2;
hl=tr AND tl1>tl2;
hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2;
dt=pk AND ph1==ph2;
db=tr AND tl1==tl2;

pkm=pkID(rightStrength_mini,leftStrength_mini);
trm=trID(rightStrength_mini,leftStrength_mini);

pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength*fact+fact));
trLow1=Ref(ValueWhen(tr,L,1),-(rightStrength*fact+fact));
pkHigh2=Ref(ValueWhen(pk,H,2),-(rightStrength*fact+fact));
trLow2=Ref(ValueWhen(tr,L,2),-(rightStrength*fact+fact));
pkmHigh1=Ref(ValueWhen(pkm,H,1),-(rightStrength_mini+1));
trmLow1=Ref(ValueWhen(trm,L,1),-(rightStrength_mini+1));
		
SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1);
PlotShapes(shapeCircle*tr,IIf(Lx-ValueWhen(tr,xx)>rightStrength*fact+fact,ColorRGB(0,255,0),colorWhite),0,L,-10);
PlotShapes(shapeCircle*pk,IIf(Lx-ValueWhen(pk,xx)>rightStrength*fact+fact,ColorRGB(255,0,0),colorWhite),0,H,10);
PlotShapes(shapeSmallCircle*trm,IIf(Lx-ValueWhen(trm,xx)>rightStrength_mini,ColorRGB(0,70,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pkm,IIf(Lx-ValueWhen(pkm,xx)>rightStrength_mini,ColorRGB(70,0,0),colorWhite),0,H,10);

Plot(pkHigh1,"",colorBlue,1,Null,Null,0,-1,3);
Plot(trLow1,"",colorRed,1,Null,Null,0,-1,3);
Plot(pkHigh2,"",ColorRGB(0,0,100),1,Null,Null,0,-1,1);
Plot(trLow2,"",ColorRGB(100,0,0),1,Null,Null,0,-1,1);
PlotTextSetFont("pk-"+tfrm,"Arial Black",8,Barcount,pkHigh1[BarCount-1],ColorRGB(0,0,255),colorDefault,0); 
PlotTextSetFont("tr-"+tfrm,"Arial Black",8,Barcount,trLow1[BarCount-1],ColorRGB(255,0,0),colorDefault,0); 
	
Buy=(Cross(H,pkHigh1) OR (Ref(C,-1)<pkHigh1 AND H>pkHigh1));BuyPrice=Max(O,pkHigh1);
Short=(Cross(trLow1,L) OR (Ref(C,-1)>trLow1 AND L<trLow1));ShortPrice=Min(O,trLow1);

if(useMiniStop)
{
	Sell=Cross(trmLow1,L);SellPrice=Min(O,trmLow1);
	Cover=Cross(H,pkmHigh1);CoverPrice=Max(O,pkmHigh1);
	Plot(pkmHigh1,"",colorBlue,styledashed,Null,Null,0,0,1);
	Plot(trmLow1,"",colorRed,styledashed,Null,Null,0,0,1);
}
else
{
	Sell=Cross(trLow1,L);SellPrice=Min(O,trLow1);
	Cover=Cross(H,pkHigh1);CoverPrice=Max(O,pkHigh1);
}

handleSignals(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice);
Buy=BuyAdjusted;
BuyPrice=BuyPriceAdjusted;
Short=ShortAdjusted;
ShortPrice=ShortPriceAdjusted;
Sell=SellAdjusted;
SellPrice=SellPriceAdjusted;
Cover=CoverAdjusted;
CoverPrice=CoverPriceAdjusted;

RequestTimedRefresh(0.1);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),ColorRGB(0,bbb*102,0),0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),ColorRGB(bbb*255,0,0),0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),ColorRGB(bbb*255,0,0),0,H,IIf(Short AND Sell,-30,-15));
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
PlotShapes(IIf(Cover,shapeSmallUpTriangle,shapeNone),ColorRGB(0,bbb*102,0),0,L,IIf(Cover AND Buy,-30,-15));
Plotshapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0);

fvb=Status("firstvisiblebarindex");
lvb=Min(Lx,Status("lastvisiblebarindex"));

for(i=fvb;i<lvb;i++) 
{
	if(ll[i]) PlotTextSetFont("LL","Arial Black",8,i,L[i],colorGreen,colorDefault,-30); 
	if(hl[i]) PlotTextSetFont("HL","Arial Black",8,i,L[i],colorGreen,colorDefault,-30); 
	if(db[i]) PlotTextSetFont("DB","Arial Black",8,i,L[i],colorLightBlue,colorDefault,-30); 
	if(hh[i]) PlotTextSetFont("HH","Arial Black",8,i,H[i],colorRed,colorDefault,20); 
	if(lh[i]) PlotTextSetFont("LH","Arial Black",8,i,H[i],colorRed,colorDefault,20); 
	if(dt[i]) PlotTextSetFont("DT","Arial Black",8,i,H[i],colorOrange,colorDefault,20);
}
    
tfrmArray=0;
tfrmArray[0]=in15Minute; 
tfrmArray[1]=inHourly;   
tfrmArray[2]=inDaily;
for(i=0;i<3;i++)
{
	tfrm=tfrmArray[i];
	
	TimeFrameSet(tfrm); 
		pk=pkID(rightStrength,leftStrength);
		tr=trID(rightStrength,leftStrength);
		pkh=IIf(pk,H,Null);
		trl=IIf(tr,L,Null);
	TimeFrameRestore();
	fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
	if(fact==0)fact=1;
	Lkbk=Nz(tfrm/Interval());
	if(Lkbk>1)
	{
		pk=TimeFrameExpand(pk,tfrm,expandFirst);
		pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
		pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
		pk=pk AND H==pkh;
		cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
		pk=pk AND cond1;
	
		tr=TimeFrameExpand(tr,tfrm,expandFirst);	
		trl=TimeFrameExpand(trl,tfrm,expandFirst);
		trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
		tr=tr AND L==trl;
		cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
		tr=tr AND cond1;
	}
	
	pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength*fact+fact));
	trLow1=Ref(ValueWhen(tr,L,1),-(rightStrength*fact+fact));

	Plot(pkHigh1,"",ColorRGB(0,0,255-i*40),1,Null,Null,0,-3,1+i);
	Plot(trLow1,"",ColorRGB(255-i*40,0,0),1,Null,Null,0,-3,1+i);
	PlotTextSetFont("pk-"+tfrm,"Arial Black",8,Barcount,pkHigh1[BarCount-1],ColorRGB(0,0,255-i*40),colorDefault,0); 
	PlotTextSetFont("tr-"+tfrm,"Arial Black",8,Barcount,trLow1[BarCount-1],ColorRGB(255-i*40,0,0),colorDefault,0); 
}
 
Last edited:

bunti_k23

Well-Known Member
do anybody have any idea ,how to use these conditions in buy sell conditions .as it is looking into future the signals are repainting .

is it possible to make a condition like only when the gap is confirmed then we get the signals:D ST's theory is superb:thumb:hatsoff:clapping::clapping::clapping:
 

bunti_k23

Well-Known Member
iam using this in buy sell conditions .

if bearish(red) cloud ,then only sell signals.
if bullish(green) cloud, then only buy signals.

Code:
GraphXSpace =15;
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetPositionSize(1,4);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


SetBarsRequired(sbrAll,sbrAll);
xx=BarIndex();x=xx;Lx=LastValue(x);
rightStrength=Optimize("R_S",Param("R_S",3,1,50,1) ,1,50,1);
leftStrength=Optimize("L_S",Param("L_S",3,1,50,1), 1,50,1);

function pkID(rightStrength,leftStrength)
{
pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength);
return pk;
}
function trID(rightStrength,leftStrength)
{
tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength);
return tr;
}

pk=pkID(rightStrength,leftStrength);
tr=trID(rightStrength,leftStrength);


SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0 ,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));


pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength+1));
trLow1=Ref(ValueWhen(Tr,L,1),-(rightStrength+1));
pkHigh0=ValueWhen(pk,H,0);
trLow0=ValueWhen(Tr,L,0);

upGap=Cross(C,pkHigh1) AND pkHigh1<trLow0;
dnGap=Cross(trLow1,C) AND trLow1>pkHigh0;

gapBaseUp=ValueWhen(upGap,pkHigh1);
gapBaseDn=ValueWhen(dnGap,trLow1);
gapExtrUp=ValueWhen(upGap,trLow0);
gapExtrDn=ValueWhen(dnGap,pkHigh0);

upGapArea=Flip(upGap,dnGap);
dnGapArea=Flip(dnGap,upGap);

gapBase=IIf(upGapArea,gapBaseUp,gapBaseDn);
gapExtr=IIf(upGapArea,gapExtrUp,gapExtrDn);

Plot(pkHigh1,"",colorBlue,24,Null,Null,0,2,1);
Plot(trLow1,"",colorRed,24,Null,Null,0,2,1);
Plot(gapBase,"",colorLightGrey,styleDashed,Null,Null,0,2,1);
Plot(gapExtr,"",colorLightGrey,styleDashed,Null,Null,0,2,1);
PlotOHLC(gapBase,gapBase,gapExtr,gapExtr,"",IIf(gapExtr>gapBase,colorSeaGreen,colorPink),styleCloud|styleNoRescale,Null,Null,0,-1,1);

[COLOR="Red"][SIZE="4"]uu = gapExtr>gapBase;
yy = gapExtr<gapBase;[/SIZE][/COLOR]
using 'uu' for buy and 'yy' for sell .but to form ST's gap we need PL>ref(PH) for bullish trend and PH<ref(PL) for bearish trend ,so the gap is confirmed when the second PH or PL is made .so i want to buy or sell only after the gap is confirmed ,but dont know which variable to use:annoyed: someone plz put some light on it .

Thanks in advance:lol:
 

Similar threads