this is more or less the code I posted earlier adding HH, HL, LL, etc
add chart also how it should look
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
-
49.8 KB Views: 376