_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN ("HH LL - Markers");
//All credit goes to the author of this code, I am not the author of this code.
RequestTimedRefresh(0.1,True);
xx=BarIndex();x=xx;Lx=LastValue(x);
rightStrength=Param("Fractal Pivot Right side Strength",5,2,50,1);
leftStrength=Param("Fractal Pivot Left side Strength",10,2,50,1);
tf=Param("Time Frame (min)",5,1,1440,1);
tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Force Pivots to Alternate","Off|On",0);
Cttop=Param("Code Title Top",15,1,250,1);
Ctspac=Param("Code Title Spacing",15,1,250,1);
dispLabels=ParamToggle("Display Labels","Off|On",1);
LabelColor=ParamColor("Label Color",colorYellow);
GfxSetTextColor(ParamColor("Code Title Color",colorLightGrey));
backGroundColor=ParamColor("Chart Background Color",colorBlack);
TimeFrameSet(tfrm);
pk=H>Ref(HHV(H,leftStrength),-1) AND Ref(HHV(H,rightStrength),rightStrength)<=H;
tr=L<Ref(LLV(L,leftStrength),-1) AND Ref(LLV(L,rightStrength),rightStrength)>=L;
px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,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);
ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
ph4=ValueWhen(pk,H,4); tl4=ValueWhen(tr,L,4);
if(CleanPivots)
{
pk=IIf((ph0>=ph1 AND tx0>px0 AND px0!=px1)
OR (ph1<ph2 AND px2>tx1)
OR (ph0>=ph1 AND tx0<px0 AND tx0==tx1 AND px0!=px1)
,False,pk);
tr=IIf((tl0<=tl1 AND px0>tx0 AND tx0!=tx1)
OR (tl1>tl2 AND tx2>px1)
OR (tl0<=tl1 AND px0<tx0 AND px0==px1 AND tx0!=tx1)
,False,tr);
px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,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);
ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
ph4=ValueWhen(pk,H,4); tl4=ValueWhen(tr,L,4);
}
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,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,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;
//GraphXSpace=5;SetChartBkColor(backGroundColor);
//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,0,0,0,0);
Plot(pkh,"",colorRed,styleThick,0,0,0,-1);
Plot(trl,"",colorBrightGreen,styleThick,0,0,0,-1);
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>=rightStrength*fact,ColorRGB(0,100,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>=rightStrength*fact,ColorRGB(255,0,0),colorWhite),0,H,10);
qq=Interval()/60;
if(qq < 60){tf=" min";tt=qq;}
else if(qq >= 60 AND qq < 1440){tf=" hrs";tt=qq/60;}
else if(qq >= 1440){tf=" days";tt=(qq/60)/24;}
qq=Max(tfrm/60,Interval()/60);
if(qq < 60){tfa=" min";tta=qq;}
else if(qq >= 60 AND qq < 1440){tfa=" hrs";tta=qq/60;}
else if(qq >= 1440){tfa=" days";tta=(qq/60)/24;}
//GfxSetOverlayMode(0);
//GfxSetBkMode(1);
//GfxSelectFont("Tahoma",11,200);
//GfxTextOut("Right Strenght: "+rightStrength,5,Cttop);
//GfxTextOut("Left Strenght: "+leftStrength,5,Cttop+Ctspac);
//GfxTextOut("Chart Timeframe: "+tt+""+tf,5,Cttop+Ctspac*2);
//GfxTextOut("Pivot Timeframe: "+tta+""+tfa,5,Cttop+Ctspac*3);
abcdy_up=27;
abcdy_dn=15;
function GetVisibleBarCount()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelToValueY(Pixels)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
fac=pxchartheight/Pixels;
Value=(Maxy-Miny)/fac;
return Nz(Value);
}
function GfxConvertBarToPixelX(bar)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
return Nz(pxchartleft+bar*pxchartwidth/(lvb-fvb+1));
}
function GfxConvertValueToPixelY(value)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
return Nz(pxchartbottom-floor(0.5+(Value-Miny)*pxchartheight/(Maxy-Miny)));
}
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
abcdy_up=GfxConvertPixelToValueY(abcdy_up);
abcdy_dn=GfxConvertPixelToValueY(abcdy_dn);
for(i=0;i<AllVisibleBars;i++)
{
GfxSelectFont("Tahoma",8,500);GfxSetBkMode(1);
if(ll[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("LL",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(hl[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("HL",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(db[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("DB",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(hh[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("HH",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(lh[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("LH",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(dt[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("DT",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
}
_SECTION_END();
_SECTION_BEGIN("Fix High Low Marker");
selecthigh = ParamList("Select High Point","ph1|ph2|ph3|ph4",1);
selectlow = ParamList("Select Low Point", "tl1|tl2|tl3|tl4",1);
PDH_ = Null;
PDL_ = Null;
Offset = 5;
if(selecthigh=="ph1")
{PDH_ = ph1;
PDHLine = LineArray(offset,SelectedValue(ph1),BarCount+2,SelectedValue(ph1),1);
}
if(selecthigh=="ph2")
{PDH_ = ph2;
PDHLine = LineArray(offset,SelectedValue(ph2),BarCount+2,SelectedValue(ph2),1);}
if(selecthigh=="ph3")
{PDH_ = ph3;
PDHLine = LineArray(offset,SelectedValue(ph3),BarCount+2,SelectedValue(ph3),1);}
if(selecthigh=="ph4")
{PDH_ = ph4;
PDHLine = LineArray(offset,SelectedValue(ph4),BarCount+2,SelectedValue(ph4),1);}
if(selectlow=="tl1")
{PDL_ = tl1;
PDLLine = LineArray(offset,SelectedValue(tl1),BarCount+2,SelectedValue(tl1),1);}
if(selectlow=="tl2")
{PDL_ = tl2;
PDLLine = LineArray(offset,SelectedValue(tl2),BarCount+2,SelectedValue(tl2),1);}
if(selectlow=="tl3")
{PDL_ = tl3;
PDLLine = LineArray(offset,SelectedValue(tl3),BarCount+2,SelectedValue(tl3),1);}
if(selectlow=="tl4")
{PDL_ = tl4;
PDLLine = LineArray(offset,SelectedValue(tl4),BarCount+2,SelectedValue(tl4),1);}
Plot(PDHLine,"LP",colorGreen,styleDashed|styleThick|stylenorescale);
Plot(PDLLine,"LT",colorRed,styleDashed|styleThick|stylenorescale);
//Following two lines below does not give the desired result but just "Zero" value.
BarsSinceHigh = BarsSince(PDH_); // I think I am wrong somewhere here
BarsSinceLow = BarsSince(PDL_);// and this line as well is wrong somewhere
Title = EncodeColor(colorYellow)+"Bars Since Defined High"+BarsSinceHigh+"\n"+
"Bars Since Defined Low"+BarsSinceLow;
_SECTION_END();