Thursday, July 2, 2015

ST base system

This AFL is based on swing high low which gives target stoploss and most traded price areas
price areas.

AFL code:

 _SECTION_BEGIN("Clay");

GfxSetBkMode(1);

nol=27;

sk=((C-MA(C,nol))/MA(C,nol))*100;
Graph0=sk;
Graph0BarColor=IIf(sk>0,5,4);

_SECTION_BEGIN("hmw");


_SECTION_BEGIN("ema");
Lk = EMA(Close,21);
//Plot (lk," ",colorBrightGreen,styleDots);


GfxSelectFont("tohomabold", Status("pxheight")/16);
GfxSetTextAlign( 6 );
GfxSetTextColor(ColorRGB(10,250,250));
GfxSetBkMode(0);
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/10 );

cx=Param("cxposn",1085,0,1200,1);
cy=Param("cyposn",16,0,1000,1);
GfxSetBkColor(ColorRGB(200,50,100));
GfxSelectFont( "tohomabold",20,98, False);
GfxSetTextColor( colorYellow);
GfxSetTextColor( ColorHSB( 100, 10, 400) );
GfxTextOut("LTP. "+C+" ", cx, cy );

_SECTION_END();

_SECTION_BEGIN("Title");

DDayO = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
gfr = TimeFrameGetPrice("C", inDaily, -1);//close
_SECTION_END();



HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose,"" , Col_cci, styleCandle| styleNoLabel );

_SECTION_END();
_SECTION_BEGIN("");




SetBarsRequired(100000,0);
GraphXSpace = 15;

ea = EMA (C,5);
eb = EMA (C,34);
SetBarFillColor( IIf( ea > eb, colorGreen, colorRed ) );

Buy = ea > eb AND TimeNum() > 092000 AND TimeNum() < 150000;
Sell = eb > ea OR TimeNum() > 150000;
Short = 0;
Cover = 0;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);


SetTradeDelays(1,1,1,1);

Factor=Param("Factor",2.50,1,10,0.05);
Pd=Param("ATR Periods",150,1,200,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount; i++) {
TrendUp[i] = Null;
TrendDown[i] = Null;

trend[i]=1;


if (Close[i]>Up[i-1]) {
trend[i]=1;
if (trend[i-1] == -1) changeOfTrend = 1;

}
else if (Close[i]<Dn[i-1]) {
trend[i]=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}

if (trend[i]<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}

if (trend[i]>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}

if (trend[i]>0 && Dn[i]<Dn[i-1]){
Dn[i]=Dn[i-1];
}

if (trend[i]<0 && Up[i]>Up[i-1])
{ Up[i]=Up[i-1];
}

if (flag==1)
{ Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);;
}
if (flagh==1)
{ Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);;
}
if (trend[i]==1) {
TrendUp[i]=Dn[i];
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend[i]==-1) {
TrendDown[i]=Up[i];
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}



Buy = trend==1;
Sell=trend==-1;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;


BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);




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

TrendSL=IIf(trend==1,TrendUp,TrendDown);

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = TrendSL[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = TrendSL[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
//Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
//PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount+3,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount+3,tar2,Null,Clr);PlotText ("T3@"+tar3,BarCount+3,tar3,Null,Clr);

}

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorWhite, 4); // broader color
GfxRoundRect( x, y - 165, x2, y , 160, 90 ) ;
GfxTextOut( ( "* TRADING SYSTEM * "),141,y-160);
GfxTextOut( (" "),130,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 148, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 130, y-120);
GfxTextOut( ("STOP LOSS : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 130, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 130, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 130,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 130,y-40);
GfxTextOut( ("Current P/L * : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 130, y-22);;

}
_SECTION_END();




Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

shape = Buy * shapeUpArrow + Sell * shapeDownArrow ;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
//PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
dist = 2.5*ATR(5);
for( i = 0; i < BarCount; i++ ) {
if( Buy[i] ) PlotText( "Buy\n@" + Close[i], i, Low[i] - dist[i], colorWhite );
if( Sell[i] ) PlotText( "sell\n@" + Close[i], i, Low[i] + dist[i], colorWhite );
}


_SECTION_BEGIN("Ema_1");
P = ParamField("Field");
Type = ParamList("Type", "Weighted,Simple,Exponential,Double Exponential,Tripple Exponential,Wilders");

Periods89 = Param("Periods50", 50, 2, 300 );
Displacement2 = Param("Displacement2", 2, -50, 50 );
//Plot( EMA( P, Periods89 ),
//_DEFAULT_NAME(), colorWhite, styleDots, 0, 0, Displacement2 );

_SECTION_END();
rjl=Cross(Lk,tar1);
gol=Cross(tar1,Lk );

//PlotShapes(shapeHollowStar*rjl,colorAqua,0,H,-20);
//PlotShapes(shapeHollowStar*gol,colorViolet,0,L,20) ;
_SECTION_END();
_SECTION_BEGIN("Ema_2");
P = ParamField("Field");
Type = ParamList("Type", "Weighted,Simple,Exponential,Double Exponential,Tripple Exponential,Wilders");

Periods89 = Param("Periods200", 200, 2, 300 );
Displacement2 = Param("Displacement2", 2, -50, 50 );
Plot( EMA( P, Periods89 ),
_DEFAULT_NAME(), colorYellow, styleDots, 0, 0, Displacement2 );

_SECTION_END();
rjl=Cross(Lk,tar1);
gol=Cross(tar1,Lk );

//PlotShapes(shapeHollowStar*rjl,colorAqua,0,H,-20);
//PlotShapes(shapeHollowStar*gol,colorViolet,0,L,20) ;
_SECTION_END();

jl = EMA(Close,13);





rfw=Cross(Lk,jl);
bve=Cross(jl,Lk);



dist =1.2*ATR(5);

for( i = 0; i < BarCount; i++ )
{

//if( bve[i] ) PlotText( "AB\n" , i, L[ i ]-dist[i], colorWhite,colorDarkBlue );
//if( rfw[i] ) PlotText( "AS\n" , i, H[ i ]+dist[i], colorWhite, colorRed );
}

//PlotShapes(shapeStar*bve,colorWhite,0,H,-90);
//PlotShapes(shapeStar*rfw,colorWhite,0,L,20);

_SECTION_BEGIN("day");
TimeFrameSet( inDaily ); // switch now to dayily

Oo=EMA(C,3);

TimeFrameRestore(); // restore time frame to original

tb=EMA(gfr,3);



//Plot( TimeFrameExpand( Oo, inDaily),"", colorYellow,10+30+4| styleNoLabel);


_SECTION_END();


_SECTION_BEGIN("Volume");

cx = Param("cxposn",476,0,1200,1);
cy = Param("cyposn", 500,0,1000,10 );

GfxSelectFont( " Arial ", 14, 98, False );
GfxSetTextColor(ColorRGB(10,250,250));

GfxTextOut("Volume : " +Volume+ "", cx +20,cy +50);





_SECTION_END( );




_SECTION_BEGIN("tom");
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;

x=Param("xposn",99,0,1000,1);
y=Param("yposn",40,0,1000,1);
//GfxRoundRect( x+615, y+530, x+738, y+499, 0,0 );
//GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
//GfxSelectPen( ColorRGB( 203, 25, 23 ), 3 );
if ( NewPeriod )
{
//GfxSelectSolidBrush( colorYellow );
//GfxSelectPen( colorYellow, 2 );
//Say( "New period" );
}

GfxSetBkMode(1);
GfxSelectFont( "Arial", 13, 800, False );
GfxSetTextColor(ColorRGB(220,10,150) );
GfxTextOut( "Timeleft"+" : "+NumToStr( SecsToGo, 1.0 ), x+674, y+507 );

_SECTION_END( );




_SECTION_BEGIN("sys");

x=Param("xposn",315,0,1000,1);
y=Param("yposn",576,0,1000,1);

GfxSetTextColor(ColorRGB(10,250,250));
GfxTextOut( ( " Develop By "),1150,y-45);
GfxSetTextColor(ColorRGB(10,250,250));
GfxTextOut( ( "*Trading SYSTEM * "),1150,y-25);






_SECTION_END();



_SECTION_BEGIN("Ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
//Plot( 1, /*efines the height of the ribbon in percent of pane width */"ribbon",
//IIf( uptrend, colorLime, IIf( downtrend, colorRed,IIf(Signal()<MACD(), colorLightGrey, colorLightGrey ))), /* choose color */
//styleOwnScale|styleArea|styleNoLabel, -.05,50 );
_SECTION_END();
_SECTION_BEGIN("VOLUME_Hight of Volume Bars Control");


PlotVOL = ParamToggle( "plot Volume?","No| Yes",1);

VolColor = (C>O OR (C==O AND (H-C)<=(C-L) ))*ParamColor( "VUpColor" ,5) +

(C<O OR (C==O AND
(H-C)>(C-L)) )*ParamColor( "VDnColor" ,4) ;

VolScale = Param("1/Vol. Height (TimeBar chart)(fraction of
window) 5=1/5=20%",10, 2, 100, 1.0) ; // Timebars

if (PlotVOL >0)

{

Vheight = VolScale;

Plot(Prec(Volume ,0),"V",VolColor,
//styleNoTitle| styleOwnScale| styleNoLabel| styleThick| (styleCandle| styleNoLabel) ,Vheight ); }
//Plot(MA(Volume,50),"",colorLightBlue,styleLine);

styleNoTitle| styleOwnScale| styleNoLabel| styleThick| ParamStyle( "VStyle", styleHistogram,maskHistogram| styleNoLabel) ,Vheight ); }
//Plot(MA(Volume,50),"",colorLightBlue,styleLine);


_SECTION_END();

_SECTION_BEGIN("Volume At Price");
PlotVAPOverlay(Param("lines", 1000, 100, 1000, 10), Param("Width", 30, 1, 100, 1), ParamColor("Color", colorBlue), ParamToggle("Side", "Left|Right", 1) | 4 *ParamToggle("Z-order", "On top|Behind", 0));

_SECTION_END();

_SECTION_BEGIN("MarketProfile");
//------------------------------------------------------------------------------
//
// Formula Name: Market Profile
//
// Use with 5/15min chart
// Originial - From AFL library

//Market Profile 9/19/2009
Col_cci = IIf(CCI(21) > 14, colorBrightGreen,IIf(CCI(21) <-5,colorRed,IIf(CCI(21) > Ref(CCI(21),-1),colorBrightGreen,colorDarkRed)));

PlotOHLC(O,H,L,C,"Price",Col_cci,styleCandle| styleNoLabel);

SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartBkGradientFill(ParamColor("Upper Chart",1),ParamColor("Lower Chart",23));



EnMP2= ParamList("MarketProfile","Solid|Lines|Letters");
styleLines = ParamStyle("Style", styleLine, maskAll);

Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly",1);

Den = Param("Density", 5, 0.25, 100, 0.25); // Resolution in terms of $
percent=Param("Value Area", 70, 1, 100, 1);
ViewTPOCount= ParamToggle("Show TPO Count", "No|Yes",1);
Viewvalues= ParamToggle("Show Values", "No|Yes",1);

ViewPOC = ParamToggle("Show POC", "No|Yes",1);
ViewVALVAH = ParamToggle("Show VAL VAH Line", "No|Yes",1);
Viewfill = ParamToggle("Show VA Fill", "No|Yes",0);
Colorpoc=ParamColor("Color POC", colorYellow);
Colorfill=ParamColor("Color Fill", ColorRGB(20,40,60));


EnIB = ParamToggle("Show Initial Balance", "Yes|No");
IBBars = Param("Initial Balance Bars", 2, 0, 10, 1);

if(Period=="Daily"){
BarsInDay = BarsSince(Day() != Ref(Day(), -1));
Bot = TimeFrameGetPrice("L", inDaily, 0);
Top = TimeFrameGetPrice("H", inDaily, 0);
Vol = TimeFrameGetPrice("V", inDaily, 0);
}

if(Period=="Hourly"){
BarsInDay = BarsSince(Minute() != Ref(Minute(), -1));
Bot = TimeFrameGetPrice("L", in5Minute, 0);
Top = TimeFrameGetPrice("H", in5Minute, 0);
Vol = TimeFrameGetPrice("V", in5Minute, 0);
}

if(Period=="Weekly"){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));
Bot = TimeFrameGetPrice("L", inWeekly, 0);
Top = TimeFrameGetPrice("H", inWeekly, 0);
Vol = TimeFrameGetPrice("V", inWeekly, 0);
}

if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));
Bot = TimeFrameGetPrice("L", inMonthly, 0);
Top = TimeFrameGetPrice("H", inMonthly, 0);
Vol = TimeFrameGetPrice("V", inMonthly, 0);
}

CurTop = HHV(H,BarsInDay+1);
Curbot = LLV(L,BarsInDay+1);
Range = Highest(Top-Bot);
TodayRange = Top - Bot;

AveRange = Sum(Top-Bot,30)/30;
LAveRange = AveRange[BarCount-1];

// Initialization
baseX = 0;
baseY = floor(Bot[0]/Den)*Den;
relTodayRange = 0;
firstVisBar = Status("firstvisiblebar");
lastVisBar = Status("lastvisiblebar");

D=.0005;
total=0;
totaldn=0;
totalup=0;
shiftup=0;
shiftdn=0;
startr=0;

for (j=0; j <= 100; j++) {
x[j] = 0;
}

i0 = 0;
i1 = 0;
for (i=0; i<BarCount; i++) {
if (BarsInDay[i] == 0 AND i < firstVisBar) {
i0 = i;
}
if (BarsInDay[i] == 0 AND i >= lastVisBar) {
i1 = i;
}
}

i1 = BarCount-1;
for (i=i0; i<=i1; i++) {
if (BarsInDay[i] == 0) {
baseX = i;
baseY = floor(Bot[i]/Den)*Den;
maxY = floor(Top[i]/Den)*Den;
relTodayRange = (maxY-baseY)/Den;

for (j=0; j <= relTodayRange; j++) {
x[j] = 0;
}
}

range_x=lastVisBar-firstVisBar;
spread = Param("X Space", 80, 1, 200, 1);
tpl = Param("Time Per Letter (mins)", 30, 1, 360, 1);
Intervalmin=Interval()/60;
flt =Param("First Letter (Bars)", 1, 1, 60, 1);
teb=ParamToggle("To Each Bar","No|Yes");
Color=Param("Color Threshold",20,1,50,1);
stopg=0;
stopr=0;
new=0;

Voloumeunit=Vol[i]/LastValue(BarsInDay);


if (EnMP2 == "Letters") {
for (j=0; j<= relTodayRange; j++) {
if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
PlotText(StrExtract(" A , B , C , D , E , F , G , H , I , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z, a , b , c , d , e , f , g , h , i , j , k , L , m , n ,o , p , q , r , s , t , u , v , w , x , y , z ",
IIf(BarsInDay[i]<flt,0,ceil(BarsInDay[i]/(tpl/Intervalmin))-0)), baseX+IIf(teb==1,BarsInDay[i],x[j]*(range_x/spread)), baseY+j*Den,
colorWhite,ColorHSB(10+((ceil(BarsInDay[i]/(tpl/Intervalmin)))*Color),160,140));
x[j]++;

}
}
}

else if (EnMP2 == "Lines" OR EnMP2 == "Solid") {
for (j=0; j<= relTodayRange; j++) {
if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
if(Type=="Price Profile"){x[j]=x[j]+1;}
else if(Type=="Volume Profile"){x[j]=x[j]+round(V[i]/Voloumeunit);}

}
}
}

// Draw Initial Balance after 11am bar is complete
if (BarsInDay[i] == IBBars+1 AND EnIB == 0) {
Line1 = LineArray(i-2, curtop[i-1],i+7, curtop[i-1],0,True);
Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale);
Line1 = LineArray(i-2, curbot[i-1],i+7, curbot[i-1],0,True);
Plot(Line1,"",colorLightGrey,styleLine+styleDashed|styleNoRescale);
}

// Examine x[j]
if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) {
maxXj = 0;
maxj = 0;
midrange = int(relTodayRange/2)+1;
for (j=0; j<= relTodayRange; j++) {
if (maxXj < x[j]) {
maxXj = x[j]; maxj = j; StaticVarSet("Maxj",j); new=j;
} else if ( MaxXj == x[j]) {
if (abs(midrange-j) < abs(midrange-StaticVarGet("Maxj"))) {
maxXj = x[j]; maxj = j; StaticVarSet("Maxj",j); new=j;
}
}
}
for ( n = 1; n <= relTodayRange; n++ ) {
total[n]=x[n]+total[n-1];
}
Value_area=(total[relTodayRange]*percent)/100;

for ( a = 1; a <= relTodayRange; a++ )
{
if(Maxj-a>0 AND Maxj+a<relTodayRange)
{
if(MaxXj+total[Maxj+a]-total[Maxj]+(total[maxj]-MaxXj)-total[Maxj-(a+1)]>=Value_area) {shiftup=a; shiftdn=a; break;}
}  
else if(Maxj-a<1 )
{
if(MaxXj+total[Maxj+a]-total[Maxj]+(total[maxj]-MaxXj)>=Value_area){shiftup=a; shiftdn=maxj-1; break;}  
}
else if(Maxj+a>relTodayRange )
{
if(MaxXj+total[relTodayRange]-total[Maxj]+(total[maxj]-MaxXj)-total[Maxj-(a+1)] >=Value_area){shiftup=relTodayRange-maxj; shiftdn=a; break;}  
}
}

Vah = LineArray(baseX, baseY+(maxj+shiftup)*Den, i, baseY+(maxj+shiftup)*Den,0,True);
Val = LineArray(baseX, baseY+(maxj-shiftdn)*Den, i, baseY+(maxj-shiftdn)*Den,0,True);
poc = LineArray(baseX, baseY+maxj*Den, i, baseY+maxj*Den,0,True);
if(ViewVALVAH==1){Plot(Vah,"",ParamColor("Color_VA", colorTan),styleLine|styleNoRescale);
Plot(Val,"",ParamColor("Color_VA", colorTan),styleLine|styleNoRescale);}
if(ViewPOC==1){Plot(poc,"",Colorpoc,styleLine|styleNoRescale);}
if(Viewvalues==1){PlotText(""+(baseY+(maxj+shiftup)*Den),i-5,baseY+(maxj+shiftup)*Den,colorWhite);
PlotText(""+(baseY+(maxj-shiftdn)*Den),i-5,baseY+(maxj-shiftdn)*Den,colorWhite);
if(ViewTPOCount==1){PlotText(""+(total[maxj]-MaxXj)+" / "+(total[maxj-shiftdn+1]),basex,bot[i]-(Top[i]-bot[i])*0.05,ParamColor("Color_Below_VA", colorLime));
PlotText(""+(total[relTodayRange]-total[maxj])+" / "+(total[relTodayRange]-total[maxj+shiftup]),basex,Top[i],ParamColor("Color_Above_VA", colorRed));
}




if(ViewPOC==1){PlotText(""+(baseY+maxj*Den),i-5,baseY+maxj*Den,Colorpoc);}}
}

if (i < BarCount - 1 AND BarsInDay[i+1] == 0 OR i == BarCount-1) {

for (p = 1; p < relTodayRange+1; p++){
line = LineArray(baseX, baseY+p*Den, baseX+x[p], baseY+p*Den);
line2 = LineArray(baseX, baseY+(p-1)*Den, baseX+x[p-1], baseY+(p-1)*Den);

if (EnMP2 == "Solid")
{
PlotOHLC( Line, Line, Line2, Line2, "",IIf(p>(maxj+shiftup),ParamColor("Color_Above_VA", colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) ,styleCloud|styleNoRescale|styleNoLabel);
}
if (EnMP2 == "Lines")
{
Plot(line,"",IIf(p>(maxj+shiftup),ParamColor("Color_Above_VA", colorGrey40),IIf(p<=(maxj+shiftup)AND p>(maxj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) , styleLines|styleNoLabel);
}

}
if(Viewfill==1){PlotOHLC(Vah,Vah,Val,Val,"",Colorfill,styleCloud|styleNoRescale|styleNoLabel);}

}
}


_SECTION_END();
//==============================

DayH = TimeFrameGetPrice("H", inDaily, -1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);//low
DayC = TimeFrameGetPrice("C", inDaily, -1);//close
DayO = TimeFrameGetPrice("O", inDaily);// current day open
HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);

                    //GUPPY MOVING AVERAGE//

                 // HIGHER HIGH LOWER LOW SECTION//

_SECTION_BEGIN("HIGHER HIGH LOWER LOW");
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=Param("N Pivot Bars",5,2,50,1);
tf=Param("Time Frame (min)",5,1,1440,1);tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",1);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",0);
dispbe123=ParamToggle("Display bearish 123","Off|On",1);
dispbu123=ParamToggle("Display bullish 123","Off|On",1);
dispLabels=ParamToggle("Display Labels","Off|On",1);
entryType=ParamToggle("Entry Type","Regular|Agressive",1);
TimeFrameSet(tfrm);
if(PivotSymmetry)
{
fc=1;
pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
else
{
fc=2;
pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=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);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
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);
if(CleanPivots)
{
tr=IIf((tr==1 AND pk==1) AND px2<tx2,False,tr);
pk=IIf((tr==1 AND pk==1) AND px2>tx2,False,pk);
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);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
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);
tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>=tl2) OR (px0==px1 AND tl1>tl0)),False,tr);
pk=IIf(pk AND ((px0<tx0 AND ph1<ph0) OR (px2>tx1 AND ph1<=ph2) OR (tx0==tx1 AND ph1<ph0)),False,pk);
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);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
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);
tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>=tl2) OR (px0==px1 AND tl1>tl0)),False,tr);
pk=IIf(pk AND ((px0<tx0 AND ph1<ph0) OR (px2>tx1 AND ph1<=ph2) OR (tx0==tx1 AND ph1<ph0)),False,pk);
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);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
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);
}
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);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
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);
}
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;
ll_h=IIf(ll,1,0);
hl_h=IIf(hl,2,0);
hh_h=IIf(hh,3,0);
lh_h=IIf(lh,4,0);
dt_h=IIf(dt,5,0);
db_h=IIf(db,6,0);
combi=ll_h+hl_h+lh_h+hh_h+dt_h+db_h;
t0=ValueWhen(combi,combi,0);
t1=ValueWhen(combi,combi,1);
t2=ValueWhen(combi,combi,2);
t3=ValueWhen(combi,combi,3);
t4=ValueWhen(combi,combi,4);
t5=ValueWhen(combi,combi,5);
be123=pk AND t1==4 AND t2==2;
beAx=ValueWhen(be123,tx2);beAy=ValueWhen(be123,tl2);
beBx=ValueWhen(be123,px2);beBy=ValueWhen(be123,ph2);
beCx=ValueWhen(be123,tx1);beCy=ValueWhen(be123,tl1);
beDx=ValueWhen(be123,px1);beDy=ValueWhen(be123,ph1);
be123=be123 AND (beBy-beCy)/(beBy-beAy)>0.382 AND (beBy-beCy)/(beBy-beAy)<0.88;
rr=BarsSince(be123)>=0;idx=IIf(rr,xx-ValueWhen(be123,beCx),Null);
if(entryType) aa=(beCy-beAy)/(beCx-beAx);else aa=0;bb=beCy;
aa=ValueWhen(be123,aa);bb=ValueWhen(be123,bb);
beEx=ValueWhen(be123,px1);ii=px1-beCx;beEy=aa*ii+bb;
beTrendline=IIf(idx,aa*idx+bb,Null);beValidSignalArea=Flip(be123,tr);
beTrendline=IIf(beValidSignalArea,beTrendline,Null);
Short=Cross(beTrendline,C) AND !IsEmpty(beTrendline);Short=Ref(Short,-1);ShortPrice=O;
Short=ExRem(Short,be123);Sell=0;
bu123=tr AND t1==2 AND t2==4;
buAx=ValueWhen(bu123,px2);buAy=ValueWhen(bu123,ph2);
buBx=ValueWhen(bu123,tx2);buBy=ValueWhen(bu123,tl2);
buCx=ValueWhen(bu123,px1);buCy=ValueWhen(bu123,ph1);
buDx=ValueWhen(bu123,tx1);buDy=ValueWhen(bu123,tl1);
bu123=bu123 AND (buCy-buBy)/(buAy-buBy)>0.382 AND (buCy-buBy)/(buAy-buBy)<0.88;
rr=BarsSince(bu123)>=0;idx=IIf(rr,xx-ValueWhen(bu123,buCx),Null);
if(entryType) aa=(buCy-buAy)/(buCx-buAx);else aa=0;bb=buCy;
aa=ValueWhen(bu123,aa);bb=ValueWhen(bu123,bb);
buEx=ValueWhen(bu123,tx1);ii=tx1-buCx;buEy=aa*ii+bb;
buTrendline=IIf(idx,aa*idx+bb,Null);buValidSignalArea=Flip(bu123,pk);
buTrendline=IIf(buValidSignalArea,buTrendline,Null);
Buy=Cross(C,buTrendline) AND !IsEmpty(buTrendline);Buy=Ref(Buy,-1);BuyPrice=O;
Buy=ExRem(Buy,bu123);Cover=0;
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;}
abcdy_up=27;
abcdy_dn=15;
function GetVisibleBarCount()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelsToBarX(Pixels)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
fac=pxchartwidth/Pixels;
bar=(lvb-fvb)/fac;
return bar;
}
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 Value;
}
function GfxConvertBarToPixelX(bar)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
return 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");
}
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
abcdy_up=GfxConvertPixelToValueY(abcdy_up);
abcdy_dn=GfxConvertPixelToValueY(abcdy_dn);

_SECTION_END();
function vstop_func(trBull,trBear)
{
trailArray[0]=C[0];
for(i=1;i<BarCount;i++)
{
prev=trailArray[i-1];
if(C[i]>prev AND C[i-1]>prev)
{
trailArray[i]=Max(prev,C[i]-trBull[i]);
}
else if(C[i]<prev AND C[i-1]< prev)
{
trailArray[i]=Min(prev,C[i]+trBear[i]);
}
else if (C[i]>prev)
{
trailArray[i]=C[i]-trBull[i];
}
else
{
trailArray[i]=C[i]+trBear[i];
}
}
return trailArray;
}
x=xx=BarIndex();
tc=ParamList("Display Mode","ZIG|VSTOP|ZIG&VSTOP",0);
disp=ParamToggle("Display labels","Off|On",1);
perBull=Param("perBull",34,1,150,1);
perBear=Param("perBear",34,1,150,1);
multBull=Param("multBull",4,1,4,0.05);
multBear=Param("multBear",4,1,4,0.05);
trBull=multBull*ATR(perBull);
trBear=multBear*ATR(perBear);
trailArray = vstop_func(trBull,trBear);
ts=IIf(trailArray>C,trailArray,Null);
tl=IIf(trailArray<C,trailArray,Null);
lll=LLV(L,BarsSince(!IsEmpty(tl)));lll=IIf(ts,lll,Null);llls=lll;
ttt1=IIf((!IsEmpty(ts) AND IsEmpty(Ref(ts,1))) OR
BarIndex()==BarCount-1,1,Null);
ttt=ValueWhen(ttt1,lll,0);ttt=IIf(ts,ttt,Null);ttt=IIf(ttt1,Ref(ttt,-1),ttt);
tr=L==ttt;lll=Sum(tr,BarsSince(!IsEmpty(tl)));
qqq=ValueWhen(ttt1,lll,0);qqq=IIf(ts,qqq,Null);qqq=IIf(ttt1,Ref(qqq,-1),qqq);tr=tr
AND lll==qqq;
tr=IIf((!IsEmpty(ts) AND IsEmpty(Ref(ts,1)) AND
IsEmpty(Ref(ts,-1))),1,tr);//exception
hhh=HHV(H,BarsSince(!IsEmpty(ts)));hhh=IIf(tl,hhh,Null);hhhs=hhh;
ttt1=IIf((!IsEmpty(tl) AND IsEmpty(Ref(tl,1))) OR
BarIndex()==BarCount-1,1,Null);
ttt=ValueWhen(ttt1,hhh,0);ttt=IIf(tl,ttt,Null);ttt=IIf(ttt1,Ref(ttt,-1),ttt);
pk=H==ttt;hhh=Sum(pk,BarsSince(!IsEmpty(ts)));
sss=ValueWhen(ttt1,hhh,0);sss=IIf(tl,sss,Null);sss=IIf(ttt1,Ref(sss,-1),sss);pk=pk
AND hhh==sss;
pk=IIf((!IsEmpty(tl) AND IsEmpty(Ref(tl,1)) AND
IsEmpty(Ref(tl,-1))),1,pk);//exception
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);
switch(tc)
{
case("ZIG"):
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);aa1=IIf(pk,Ref(aa1,-1),aa1);ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND
px1<tx1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
//Plot(ls1,"",colorGreen,styleLine,0,0,0,2,3);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);aa1=IIf(tr,Ref(aa1,-1),aa1);ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND
tx1<px1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
//Plot(ls1,"",colorOrange,styleLine,0,0,0,2,3);
break;
case("VSTOP"):
//Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
//Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
//Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
//Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
break;
case("ZIG&VSTOP"):
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);aa1=IIf(pk,Ref(aa1,-1),aa1);ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND
px1<tx1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorBlue,styleLine,0,0,0,2,3);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);aa1=IIf(tr,Ref(aa1,-1),aa1);ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND
tx1<px1,1,0);bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);ls1=IIf(bb1,ls1,Null);
//Plot(ls1,"",colorOrange,styleLine,0,0,0,2,3);
//Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
//Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
//Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
//Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
break;
}
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
//SetBarFillColor(IIf(C>O,ParamColor("Candle Up Color",
//colorBrightGreen),IIf(C<=O,ParamColor("Candle Down Color",
//colorRed),colorLightGrey)));
//Plot(C,"Price",IIf(!IsEmpty(tl),ParamColor("Shadow Uptrend Color",
//ColorRGB(0,120,0)),IIf(!IsEmpty(ts),ParamColor("Shadow Downtrend Color",
//ColorRGB(120,0,0)),colorLightGrey)),64,0,0,0,0,1);
//Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color",
//ColorRGB(0,255,0)),IIf(C<=O,ParamColor("Shadow Color",
//ColorRGB(255,0,0)),colorLightGrey)),64,0,0,0,0,1);
PlotShapes(shapeSmallCircle*tr,colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*pk,colorRed,0,H,10);
dxhm=14;dxlm=10;dxh=0;dxl=0;dyhm=5;dylm=3;dyh=18;dyl=29;hm=30;lm=30;
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
}
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
}
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
}
if(disp)
{
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;
miny=Status("axisminy");
maxy=Status("axismaxy");
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
LowMargin=Miny+GfxConvertPixelToValueY(lm);
HighMargin=Maxy-GfxConvertPixelToValueY(hm);
dyllm=GfxConvertPixelToValueY(dylm);
dyhhm=GfxConvertPixelToValueY(dyhm);
dyll=GfxConvertPixelToValueY(dyl);
dyhh=GfxConvertPixelToValueY(dyh);
dxllm=GfxConvertPixelsToBarX(dxlm);
dxhhm=GfxConvertPixelsToBarX(dxhm);
dxll=GfxConvertPixelsToBarX(dxl);
dxhh=GfxConvertPixelsToBarX(dxh);
for(i=0;i<AllVisibleBars;i++)
{
if(ll[i+fvb] AND L[i+fvb]>LowMargin)
PlotText("LL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorBlack);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin)
PlotText("LL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorBlack);
if(hl[i+fvb] AND L[i+fvb]>LowMargin)
PlotText("HL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorBlack);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin)
PlotText("HL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorBlack);
if(db[i+fvb] AND L[i+fvb]>LowMargin)
PlotText("DB",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorBlack);
if(db[i+fvb] AND L[i+fvb]<=LowMargin)
PlotText("DB",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorBlack);
if(hh[i+fvb] AND H[i+fvb]<HighMargin)
PlotText("HH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorBlack);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin)
PlotText("HH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorRed);
if(lh[i+fvb] AND H[i+fvb]<HighMargin)
PlotText("LH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorBlack);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin)
PlotText("LH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorBlack);
if(dt[i+fvb] AND H[i+fvb]<HighMargin)
PlotText("DT",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorBlack);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin)
PlotText("DT",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorBlack);
}
}

// HURST CYCLE//

_SECTION_END();
CY1 =  Param("Short Cycle Length?" ,10, 1 ,1000 ,1 )/2;
CY2 =  Param("Medium Cycle Length?" ,80, 1 ,1000 ,1 )/2;
M1 =  Param("Short Cycle Multiplyer?" ,1, 0.01 ,10 ,1 );
M2 =  Param("Medium Cycle Multiplyer?" ,3, 0.01 ,10 ,1 );
T1 =  Ref(MA(Close ,CY1 ),CY1/2)+ M1*ATR(CY1 );
B1 =  Ref(MA( Close ,CY1 ),CY1/2)- M1*ATR(CY1 );
T2 =  Ref(MA(Close ,CY2 ),CY2/2)+ M2*ATR(CY2 );
B2 =  Ref(MA( Close ,CY2 ),CY2/2)- M2*ATR(CY2 );

//Plot(T1, "", colorLime);
//Plot(B1, "", colorLime);
//Plot(T2, "", colorRed);
//Plot(B2, "", colorRed);

// HIGH LOW AND PIVOTS//
_SECTION_BEGIN("Previous Days HI LO");
 DayH = TimeFrameGetPrice("H", inDaily, -1); DayHI = LastValue (DayH,1);// yesterdays high
 DayL = TimeFrameGetPrice("L", inDaily, -1); DayLI = LastValue (DayL,1); // yesterdays low
 DayC = TimeFrameGetPrice("C", inDaily, -1); DayCL = LastValue (DayC,1); // yesterdays close
 DayO = TimeFrameGetPrice("O", inDaily); // current day open
 DayH2= TimeFrameGetPrice("H", inDaily, -2); DayH2I = LastValue (DayH2,1); // Two days before high
 DayL2= TimeFrameGetPrice("L", inDaily, -2); DayL2I = LastValue (DayL2,1); // Two days before low
 DayH3= TimeFrameGetPrice("H", inDaily, -3); DayH3I = LastValue (DayH3,1); // Three days before high
 DayL3= TimeFrameGetPrice("L", inDaily, -3); DayL3I = LastValue (DayL3,1); // Three days before low

 numbars = LastValue(Cum(Status("barvisible")));
 hts = -33.5;

 YHL = ParamToggle("Yesterday HI LO","Show|Hide",0);
 if(YHL==1) {
 Plot(DayL,"YL",colorBlue,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(DayH,"YH",colorBrightGreen,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(DayC,"YC",colorGold,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 PlotText(" YH " , LastValue(BarIndex())-(numbars/Hts), DayHI, colorBrightGreen);
 PlotText(" YL " , LastValue(BarIndex())-(numbars/Hts), DayLI, colorBlue);
 PlotText(" YC " , LastValue(BarIndex())-(numbars/Hts), DayCL, colorGold);
 }

 TDBHL = ParamToggle("2/3Days before HI LO","Show|Hide",0);
 if(TDBHL==1) {
 Plot(DayL2,"2DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(DayH2,"2DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(DayL3,"3DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(DayH3,"3DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 PlotText(" 2DBH " , LastValue(BarIndex())-(numbars/Hts), DayH2I, colorTurquoise);
 PlotText(" 2DBL " , LastValue(BarIndex())-(numbars/Hts), DayL2I, colorTurquoise);
 PlotText(" 3DBH " , LastValue(BarIndex())-(numbars/Hts), DayH3I, colorTurquoise);
 PlotText(" 3DBL " , LastValue(BarIndex())-(numbars/Hts), DayL3I, colorTurquoise);
 }

 // Pivot Levels //
 PP = (DayL + DayH + DayC)/3; PPI = LastValue (PP,1); // Pivot
 R1 = (PP * 2) - DayL; R1I = LastValue (R1,1); // Resistance 1
 S1 = (PP * 2) - DayH; S1I = LastValue (S1,1); // Support 1
 R2 = PP + R1 - S1; R2I = LastValue (R2,1); // Resistance 2
 S2 = PP - R1 + S1; S2I = LastValue (S2,1); // Support 2
 R3 = PP + R2 - S1; R3I = LastValue (R3,1); // Resistance 3
 S3 = PP - R2 + S1; S3I = LastValue (S3,1); // Support 3

 ppl = ParamToggle("Pivot Levels","Show|Hide",0);
 if(ppl==1) {
 Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

 PlotText(" Pivot ", LastValue(BarIndex())-(numbars/Hts), PPI, colorYellow);
 PlotText(" R1 " , LastValue(BarIndex())-(numbars/Hts), R1I, colorViolet);
 PlotText(" S1 " , LastValue(BarIndex())-(numbars/Hts), S1I, colorViolet);
 PlotText(" R2 " , LastValue(BarIndex())-(numbars/Hts), R2I, colorViolet);
 PlotText(" S2 " , LastValue(BarIndex())-(numbars/Hts), S2I, colorViolet);
 PlotText(" R3 " , LastValue(BarIndex())-(numbars/Hts), R3I, colorViolet);
 PlotText(" S3 " , LastValue(BarIndex())-(numbars/Hts), S3I, colorViolet);
 }
 // Camerilla Levels //

 rg = (DayH - DayL);

 H5=DayC+1.1*rg; H5I = LastValue (H5,1);
 H4=DayC+1.1*rg/2; H4I = LastValue (H4,1);
 H3=DayC+1.1*rg/4; H3I = LastValue (H3,1);
 H2=DayC+1.1*rg/6; H2I = LastValue (H2,1);
 H1=DayC+1.1*rg/12; H1I = LastValue (H1,1);
 L1=DayC-1.1*rg/12; L1I = LastValue (L1,1);
 L2=DayC-1.1*rg/6; L2I = LastValue (L2,1);
 L3=DayC-1.1*rg/4; L3I = LastValue (L3,1);
 L4=DayC-1.1*rg/2; L4I = LastValue (L4,1);
 L5=DayC-1.1*rg; L5I = LastValue (L5,1);

 pcl = ParamToggle("Camerilla Levels","Show|Hide",0);
 if(pcl==1) {
 Plot(H5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(H4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(H3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(H2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(H1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(L1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(L2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(L3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(L4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 Plot(L5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
 PlotText(" H5 = " , LastValue(BarIndex())-(numbars/Hts), H5I +0.05, colorRose);
 PlotText(" H4 = " , LastValue(BarIndex())-(numbars/Hts), H4I +0.05, colorRose);
 PlotText(" H3 = " , LastValue(BarIndex())-(numbars/Hts), H3I +0.05, colorRose);
 PlotText(" H2 = " , LastValue(BarIndex())-(numbars/Hts), H2I +0.05, colorRose);
 PlotText(" H1 = " , LastValue(BarIndex())-(numbars/Hts), H1I +0.05, colorRose);
 PlotText(" L1 = " , LastValue(BarIndex())-(numbars/Hts), L1I +0.05, colorRose);
 PlotText(" L2 = " , LastValue(BarIndex())-(numbars/Hts), L2I +0.05, colorRose);
 PlotText(" L3 = " , LastValue(BarIndex())-(numbars/Hts), L3I +0.05, colorRose);
 PlotText(" L4 = " , LastValue(BarIndex())-(numbars/Hts), L4I +0.05, colorRose);
 PlotText(" L5 = " , LastValue(BarIndex())-(numbars/Hts), L5I +0.05, colorRose);
 }
 _SECTION_END();
_SECTION_BEGIN("LUNAR PHASE");
// Input your local time zone
TZ=Param("Your local Time Zone? [-12 to +12hrs]",2, -12,12,1);

// Lunar cycle
LunarMonth=29.530589;
Offset=7.254621;

// Calendar }
leap=frac(Year( )/4)==0 AND frac(Year()/ 100)!=0 OR frac(Year()/ 400)==0;
y=Year()*365+ int(Year( )/4)-int( Year()/100) +int(Year( )/400);
m=
IIf(Month()==2,31-leap,
IIf(Month()==3,59,
IIf(Month()==4,90,
IIf(Month()==5,120,
IIf(Month()==6,151,
IIf(Month()==7,181,
IIf(Month()==8,212,
IIf(Month()==9,243,
IIf(Month()==10,273,
IIf(Month()==11,304,
IIf(Month()==12,334, -leap))))))) ))));
CurrentDay=y+ m+Day()-TZ/ 24-Offset;

// Full Moon }
FM=frac(CurrentDay/ LunarMonth) ;
FM=PeakBars( FM, 1, 1)==0;

// New Moon }
NM=frac((CurrentDay +LunarMonth/ 2)/LunarMonth) ;
NM=PeakBars( NM, 1,1)==0;
FullMoon=FM-NM==1;
NewMoon=FM-NM==-1;
//Plot Moon Phase in own window }

shape =
IIf(FullMoon,shapeCircle,IIf(NewMoon,shapeCircle+shapePositionAbove,Null));

PlotShapes(shape,IIf(FullMoon,colorWhite,colorBlue),0,H);

_SECTION_END();              



Title =   Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "

+ "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+"  UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+"  DOWN "+ (V/MA(V,26))*100 + " %")+ EncodeColor(colorLightBlue)
+ EncodeColor(colorYellow)+   " Yesterday's High : "+ EncodeColor(colorWhite)+DayH + EncodeColor(colorYellow)+   "    Yesterday's Low : "+ EncodeColor(colorWhite)+DayL

+ EncodeColor(colorBrightGreen)+   "\n                  Hi: "+ EncodeColor(colorWhite)+H


+ EncodeColor(colorYellow)+   "\n       Op: "+ EncodeColor(colorWhite)+O+ EncodeColor(colorAqua)+   "   Cl: "+ EncodeColor(colorBrightGreen)+C
+ EncodeColor(colorRed)+   "\n                  Lo: "+ EncodeColor(colorWhite)+L

+" \n "

;

No comments:

Post a Comment