Monday, 8 September 2014

CENTER OF GRAVITY for Amibroker (AFL)




CENTER OF GRAVITY for Amibroker (AFL)



sx=Null;b=Null;ai=Null;x=Null;
reg=x1=x2=x3=z1=z2=z3=Null;
rega=x1a=x2a=x3a=z1a=z2a=z3a=Null;

bi=BarIndex();
eb=LastValue(bi);
order=Param("n-th Order",3,1,8,1);
bars=Param("Lookback Period",100,50,500,1);
sv=ParamToggle("Use Selected Value","Off|On",1);
alt=ParamToggle("Error Levels","Fibonacci|Standard",0);
ecart=1.61803399;
 
if(sv)
{
eb=SelectedValue(bi);
bb=Max(0,eb-bars);
}
else
{
bb=Max(0,eb-bars);
}
fin=eb;
nn=order+1;
sx[1]=bars+1;

if(fin>bars)
{
for(mi=1;mi<=2*nn-2;mi++)
{
suml=0;
for(n=0;n<=bars;n++)
{
suml=suml+n^mi;
}
sx[mi+1]=suml;
}
for(mi=1;mi<=nn;mi++)
{
suml=0;
for(n=0;n<=bars;n++)
{
if (mi==1)
suml=suml+Close[fin-n];
else
suml=suml+Close[fin-n]*n^(mi-1);
b[mi]=suml;
}
}
for(jj=1;jj<=nn;jj++)
{
for(ii=1;ii<=nn;ii++)
{
kk=ii+jj-1;
ai[(ii-1)*nn+jj]=sx[kk];
}
}
for(kk=1;kk<=nn-1;kk++)
{
ll=0;
mm=0;
for(ii=kk;ii<=nn;ii++)
{
if(abs(ai[(ii-1)*nn+kk])>mm)
{
mm=abs(ai[(ii-1)*nn+kk]);
ll=ii;
}
}
    if(ll==0) break;
if(ll!=kk)
{
for(jj=1;jj<=nn;jj++)
{
tt=ai[(kk-1)*nn+jj];
ai[(kk-1)*nn+jj]=ai[(ll-1)*nn+jj];
ai[(ll-1)*nn+jj]=tt;
}
tt=b[kk];
b[kk]=b[ll];
b[ll]=tt;
}
for(ii=kk+1;ii<=nn;ii++)
{
qq=ai[(ii-1)*nn+kk]/ai[(kk-1)*nn+kk];
for(jj=1;jj<=nn;jj++)
{
if(jj==kk)
ai[(ii-1)*nn+jj]=0;
else
ai[(ii-1)*nn+jj]=ai[(ii-1)*nn+jj]-qq*ai[(kk-1)*nn+jj];
}
b[ii]=b[ii]-qq*b[kk];
}
}
x[nn]=b[nn]/ai[nn*nn];
for(kk=1;kk<=nn-1;kk++)
{
tt=0;
ii=nn-kk;
for(jj=1;jj<=nn-ii;jj++)
{
tt=tt+ai[(ii-1)*nn+ii+jj]*x[ii+jj];
if(ai[(ii-1)*nn+ii]!=0)
x[ii]=(b[ii]-tt)/ai[(ii-1)*nn+ii];
}
}
for(n=0;n<=bars;n++)
{
suml=0;
for(kk=1;kk<=order;kk++)
{
suml=suml+x[kk+1]*n^kk;
}
reg[fin-n]=x[1]+suml;
}
}
SetChartOptions(0, chartShowDates);
Title = "Symbol: "+ Name()+ "\nPoly Order: "+order;
if(alt)
{
dev=StDev(Close-reg,bars);
sd=dev[fin];
x1a=reg+sd*1;
x2a=reg+sd*2;
x3a=reg+sd*3;
z1a=reg-sd*1;
z2a=reg-sd*2;
z3a=reg-sd*3;
Plot(C, "Close",colorLightGrey,styleCandle);
Plot(reg,"reg",colorBlue,1);
Plot(x3a,"x3a",ColorRGB(255,0,0),styleThick);
Plot(x2a,"x2a",ColorRGB(255,100,100),styleDashed);
Plot(x1a,"x1a",ColorRGB(255,200,200),styleDashed);
Plot(z3a,"z3a",ColorRGB(0,255,0),styleThick);
Plot(z2a,"z2a",ColorRGB(100,255,100),styleDashed);
Plot(z1a,"z1a",ColorRGB(200,255,200),styleDashed);
PlotOHLC(x3a,x3a,x1a,x1a,"",ColorRGB(30,0,0),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(z1a,z1a,z3a,z3a,"",ColorRGB(0,30,0),styleCloud|styleNoLabel,0,0,0,-1);
}
else
{
dev=StDev(Close,bars);
sd=ecart*dev[fin];
x1=reg+sd/(1.382*1.618);
x2=reg+sd/1.382;
x3=reg+sd;
z1=reg-sd/(1.382*1.618);
z2=reg-sd/1.382;
z3=reg-sd;
Plot(C, "Close",colorLightGrey,styleCandle);
Plot(reg,"reg",colorBlue,1);
Plot(x3,"x3",ColorRGB(255,0,0),styleThick);
Plot(x2,"x2",ColorRGB(255,100,100),styleDashed);
Plot(x1,"x1",ColorRGB(255,200,200),styleDashed);
Plot(z3,"z3",ColorRGB(0,255,0),styleThick);
Plot(z2,"z2",ColorRGB(100,255,100),styleDashed);
Plot(z1,"z1",ColorRGB(200,255,200),styleDashed);
PlotOHLC(x3,x3,x2,x2,"",ColorRGB(30,0,0),styleCloud|styleNoLabel,0,0,0,-1);
PlotOHLC(z2,z2,z3,z3,"",ColorRGB(0,30,0),styleCloud|styleNoLabel,0,0,0,-1);
}

Febo RSI ..real indicator for Amibroker (AFL)



Febo RSI ..real indicator for Amibroker (AFL)


_SECTION_BEGIN("fibonaci rsi");
barvisible = Status("barvisible");
r = RSI( 14 );
maxr = LastValue( Highest( IIf( barvisible, r, 0 ) ) );
minr = LastValue( Lowest( IIf( barvisible, r, 100 ) ) );
ranr = maxr - minr;
Plot( r, "RSI(14)", colorRed );
Plot( maxr , "0%", colorGrey50 );
Plot( maxr - 0.236 * ranr, "-23.6%", colorPaleGreen );
Plot( maxr - 0.382 * ranr, "-38.2%", colorPaleBlue );
Plot( maxr - 0.50 * ranr, "-50.0%", colorOrange );
Plot( maxr - 0.618 * ranr, "-61.8%", colorPaleBlue );
Plot( minr , "-100%", colorGrey50 );
GraphXSpace = 3;
_SECTION_END();

This Signals have only simple system of cross over of Fractyle Moving Averages…


This Signals have only simple system of cross over of Freestyle Moving Averages…
if you use in opposition treading, in daily time frame, this gives wounder full result !










EMA2=EMA(C,2);
EMA4=EMA(C,4);
EMA8=EMA(C,8);
EMA17=EMA(C,17);
EMA34=EMA(C,34);
FMA1=(EMA2-EMA4)+EMA2;
FMA2=(EMA4-EMA8)+EMA4;
FMA4=(EMA8-EMA17)+EMA8;
FMA8=(EMA17-EMA34)+EMA17;
Plot(FMA4,"FMA4",colorGreen,styleThick);
Plot(FMA8,"FMA8",colorRed,styleThick);
Buy=FMA4>FMA8;
Sell=FMA4<FMA8;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
PlotShapes(shapeHollowUpArrow * Buy,colorBrightGreen,0,L, Offset=-45);
PlotShapes(shapeHollowDownArrow * Sell,colorRed,0,H, Offset=-45);
A=(H+L)/2;
var1=Wilders(A,34);
var2=Wilders(A,5);
var3=var2-var1;
var4=var3-Wilders(var3,5);
Var5=(H-L)/V;
AO=Var3;
AC=Var4;
barcolor=IIf(AO>Ref(AO,-1) AND AC>Ref(AC,-1),colorGreen,IIf(AO<Ref(AO,-1) AND AC<Ref(AC,-1),colorRed,IIf(V>0 AND Var5<Ref(Var5,-1) AND V>Ref(V,-1),colorGold,colorBlack)));

HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4;

Plot( C, "Regular candles " + Name(), barcolor, styleCandle );

_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
GraphXSpace=Param("GraphXSpace",10,-45,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);

_SECTION_END();
_SECTION_BEGIN("Title");

DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
Title = EncodeColor(colorWhite)+"  "+EncodeColor(colorWhite)+ Name() + ", " + Interval(2) + ", " + Date() +
EncodeColor(colorWhite)   +  "\nO " + EncodeColor(colorWhite) + O +

 ",   H :  "   + H +
 ",   L  :  " + L +
 ",   C  :  "  + C +
EncodeColor(colorWhite)+ "\n Day-Open : " +DODay + "  Day-High : " +DHiDay + "  Day-Low : " + DLoDay
;

Saturday, 6 September 2014

Book Profit with 101% for Amibroker (AFL)

https://www.facebook.com/StocKanalysisBd?ref=hl

Book Profit with 101%  for Amibroker (AFL)





SetChartOptions(2,chartShowArrows|chartShowDates|chartWrapTitle);
SetChartOptions(0,chartShowArrows|chartShowDates);


//GfxGradientRect( 180, 30, 1759, 735, ColorRGB(40,40,40), ColorRGB(0,0,40) ); 
GfxSetOverlayMode(1); 
GfxSelectPen( ColorRGB(150,0,0), 1 ); 
GfxSelectSolidBrush( ColorRGB(0,0,40) ); 
GfxRectangle( 0,750, 1807, 35 ); 

GfxSelectPen( ColorRGB(150,0,0), 2 ); 
GfxSelectSolidBrush( ColorRGB(65,65,65) ); 
GfxPolygon(250,200,200,250,250,20,200,50); 

//GfxSelectPen( ColorRGB(125,0,0), 1 ); 
//GfxSelectSolidBrush( ColorRGB(0,0,40) ); 
//GfxRectangle( 10,100, 190, 160 ); 

GfxSelectPen( ColorRGB(0,0,0), 1 ); 
GfxSelectSolidBrush( ColorRGB(0,0,0) ); 
//GfxSetTextAlign( 250 );// center alignment

GfxSetOverlayMode(1); 
GfxSelectFont("Times New Roman", 30, 400, True ); 
GfxSetTextColor( ColorRGB( 105, 105, 105 ) );
GfxSetBkMode(0); // transparent
GfxTextOut("Pathfinder", 15 , 35 ); 


_SECTION_BEGIN("Flower");
si=Param("Zoom/In Out",5,-50,100,1);
GraphXSpace=si;  

r1 = Param( "ColorFast avg", 5, 2, 200, 1 );
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 );

m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, ColorRGB(155,155,155),IIf(m1>0 AND m1>s1,ColorRGB(0,125,0),IIf(m1>0 AND m1<s1,ColorRGB(180,30,160),ColorRGB(100,0,0))));

Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);
flowerClose = EMA((Open+High+Low+Close)/4,3) ;
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3);
Temp = Max(High, flowerOpen);
flowerHigh = EMA(Max(Temp, flowerClose),3);
Temp = Min(Low,flowerOpen);
flowerLow = EMA(Min(Temp, flowerClose),3);
barColor=IIf(Close>Open,ColorRGB(0,245,0),ColorRGB(255,0,0));

Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
total = 0;
total = total  + IIf(tskp_colortmplcnd0 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd1 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd2 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd3 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd4 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd5 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd6 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd7 > 0, 1, -1); 
total = total  + IIf(tskp_colortmplcnd8 > 0, 1, -1); 


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

 if( total[i] >= 5 )
  Color[i] = colorLime;
 else if(  total[i] <= -5 )
  Color[i] = colorRed;
 else
  Color[i] = colorWhite;
} 

Candle=ParamList("Candle","Modified Candlestick,Modified Heikin Ashi,Normal Candlestick",1);
if(Candle=="Modified Candlestick")
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
Plot (Close,"- Modified Candlestick", Color,ParamStyle( "Style", styleCandle|styleLine | styleThick, maskAll)); 
}
if(Candle=="Modified Heikin Ashi")
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<flowerClose, flowerClose, flowerOpen), "Modified Heikin Ashi", Color, styleCandle|styleLine);
}
if(Candle=="Normal Candlestick")
{
//ColorHighliter = myColor;
//SetBarFillColor( ColorHighliter );
PlotOHLC(O,H,L,C,"Normal Candlestick",barcolor,styleCandle|styleLine);
}


_SECTION_END();



_SECTION_BEGIN("Resistance");
supres=ParamToggle("Sup_Res","No|Yes",1);
if(supres)
{

Prd1=Param("Res_Period1",2,0,200,1);
                   
test   = TEMA  ( High , Prd1 ) ;   

PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,flowerHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,flowerHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,flowerHigh,2);//PeakValue2

MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak

RsColor=ParamColor("ResistColor",ColorRGB(225,0,0));
BrCount=Param("ResistBarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
 RsColor[i] = colorBlack;
}



MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1",  ColorRGB(200,0,0),ParamStyle("ResStyle1",styleDashed|styleNoTitle,maskAll));

RsColor2=ParamColor("Resist2Color",ColorRGB(225,0,0));
BrCount=Param("Resist2BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
 RsColor2[i] = colorBlack;
}

MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2", RsColor2,ParamStyle("ResStyle2",styleDashed|styleNoTitle,maskAll));

RsColor3=ParamColor("Resist3Color",ColorRGB(225,0,0));
BrCount=Param("Resist3BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
 RsColor3[i] = colorBlack;
}


MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", RsColor3,ParamStyle("ResStyle3",styleThick|styleDots|styleNoTitle,maskAll));



_SECTION_END();


_SECTION_BEGIN("Support");

Prd2=Param("Sup_Period1",2,0,200,1);
                   
test2   = TEMA ( Low , Prd2 ) ;   

SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,flowerLow,0);//PeakValue0
SPV1 = ValueWhen(SP,flowerLow,1);//PeakValue1
SPV2 = ValueWhen(SP,flowerLow,2);//PeakValue2

MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak

SpColor=ParamColor("SupColor",ColorRGB(0,225,0));
BrCount=Param("SupBarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
 SpColor[i] = colorBlack;
}


MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1",SpColor,ParamStyle("SupportLine1",styleDashed|styleNoTitle,maskAll));

SpColor2=ParamColor("SupColor2",ColorRGB(0,200,0));
BrCount=Param("Sup2BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
 SpColor2[i] = colorBlack;
}


MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2",Spcolor2,ParamStyle("SupportLine2",styleDashed|styleNoTitle,maskAll));

SpColor3=ParamColor("SupColor3",ColorRGB(0,175,0));
BrCount=Param("Sup3BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
 SpColor3[i] = colorBlack;
}


MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3",SpColor3,ParamStyle("SupportLine3",styleThick|styleDots|styleNoTitle,maskAll));
}
_SECTION_END();


_SECTION_BEGIN("TSKPPUSHDOTS");
if(Candle=="Modified Heikin Ashi")
{
Combo = E_TSKPCOMBO(Open,High,Low,Close,Volume);
NewUpDown = E_TSKPNEWUPDOWN(Open,High,Low,Close,Volume);
UpDown7 = 0.5*(High+Low) - E_TSKPSTOPLINE(High,Low,Close);
//r=Param("Red",0,0,255,1);
//g=Param("Green",0,0,255,1);
//b=Param("Blue",0,0,255,1);

if(Candle=="Normal Candlestick" OR Candle=="Modified Candlestick")
{
PlotShapes( IIf( ((Combo>0) AND (NewUpDown > 0) AND (UpDown7 > 0)),shapeSmallCircle,shapeNone), ColorRGB(0,125,255),0, Low, -8);
PlotShapes( IIf( ((Combo<0) AND (NewUpDown < 0) AND (UpDown7 < 0)),shapeSmallCircle,shapeNone), ColorRGB(225,0,0),0, High, 8);
}

else
{
PlotShapes( IIf( ((Combo>0) AND (NewUpDown > 0) AND (UpDown7 > 0)),shapeSmallCircle,shapeNone), ColorRGB(0,255,0),0, flowerlow, -12);
PlotShapes( IIf( ((Combo<0) AND (NewUpDown < 0) AND (UpDown7 < 0)),shapeSmallCircle,shapeNone), ColorRGB(255,0,0),0, flowerhigh, 12);
}
}
_SECTION_END();

Title = StrFormat("\\c02 {{NAME}} | {{DATE}} | Open : %g | High : %g | Low : %g | Close : %g | Change = %.1f%% | Volume = " +WriteVal( V, 1.0 ) +", {{VALUES}}",
O, H, L, C, SelectedValue( ROC( C, 1 )) );


_SECTION_BEGIN("TSKPPIVOT");

if(Candle=="Modified Heikin Ashi")
{
CHiPr = 0;
CLoPr = 9999999;
blsLong = 0;
PrevCOBar = 0;
NumBars = 0;
PrePP = 0;
PrevLowVal = 9999999;
BuySig = 0;
blsShort = 0;
PrevHiVal = 0;
blsNewCO = 0;
BarDif   = 0;

KPA900Val = E_TSKPA900(Close);
KPAutoStopVal = E_TSKPAUTOSTOP(High,Low,Close);

// -- Create 0-initialized arrays the size of barcount
aHPivs = flowerHigh - flowerHigh;
aLPivs = flowerLow - flowerLow;
aHiVal = flowerHigh - flowerHigh;
aLoVal = flowerLow - flowerLow;


Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
sctotal = 0;
sctotal = sctotal  + IIf(tskp_colortmplcnd0 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd1 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd2 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd3 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd4 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd5 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd6 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd7 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd8 > 0, 1, -1); 


for (curBar=0; curBar < BarCount-1; curBar++)
{

 if ( curBar == 0 )
 {
  CHiPr = flowerHigh[curBar];
  CHiBar = curBar;
  CLoPr = flowerLow[curBar];
  CLoBar = curBar;
  blsLong = 0;
  blsShort = 0;
  blsNewCO = 0;
  PrePP = 0;
  PrevCOBar = 0;
  PrevHiVal = flowerHigh[curBar];
  PrevLowVal = flowerLow[curBar];
  BuySig = 0;
  SellSig = 0;
  blsLL  = 0;
 }

 if (flowerHigh[CurBar] >= CHiPr) {
  CHiPr = flowerHigh[CurBar];
  ChiBar = CurBar;
 }

 if (flowerLow[CurBar] <= CLoPr) {
  CLoPr = flowerLow[CurBar];
  CLoBar = CurBar;
 }

 if ( (KPA900Val[curBar] >= KPAutoStopVal[curbar]) AND (PrePP != -1) AND (blsLong != 1) ){
  BarDif = CurBar - PrevCOBar;
  if (BarDif >= NumBars) {
   blsLong = 1;
   blsShort = 0;
   blsNewCO = 1;
   PrevCOBar = CurBar;
  }
 }

 if ( (KPA900Val[curBar] <= KPAutoStopVal[curbar]) AND (PrePP != 1) AND (blsShort != 1) ){
  BarDif = CurBar - PrevCOBar;
  if (BarDif >= NumBars) {
   blsLong = 0;
   blsShort = 1;
   blsNewCO = 1;
   PrevCOBar = CurBar;
  }
 }

 if ( (blsNewCO == 1) AND (sctotal[CurBar] >= 5) AND (blsLong == 1) ) {
  LVal = CurBar - CLoBar;
  for (j= CLoBar-1; j <= CLoBar+1; j++)
  {
   if (j >=0) {
    aLPivs[j] = 1;
    aLoVal[j] = CLoPr;
   }
  }
  PrePP = -1;
  blsNewCO = 0;
  CHiPr = flowerHigh[CurBar];
  CHiBar = CurBar;
  CLoPr = flowerLow[Curbar];
  CLoBar = CurBar;
  } 
  else if ((blsNewCO == 1) AND (sctotal[CurBar] <= -5) AND (blsShort == 1) ) {
  HVal = CurBar - CHiBar;
  for (j= CHiBar-1; j <= CHiBar+1; j++)
  {  
   if (j >=0) {
    aHPivs[j] = 1;
    aHiVal[j] = CHiPr;
   }
  }
  PrePP = 1;
  blsNewCO = 0;
  CHiPr = flowerHigh[CurBar];
  CHiBar = CurBar;
  CLoPr = flowerLow[Curbar];
  CLoBar = CurBar;
  } 
}

PlotShapes(IIf(aHPivs == 1, 21,shapeNone), ColorRGB(255,0,145),0,   aHiVal,Offset = 20);
PlotShapes(IIf(aHPivs == 1, 15,shapeNone), ColorRGB(200,50,75),0,   aHiVal,Offset = 20);
PlotShapes(IIf(aLPivs == 1, 21,shapeNone), ColorRGB(0,125,225),0, aLoVal, Offset = -20);
PlotShapes(IIf(aLPivs == 1, 15,shapeNone), ColorRGB(0,125,255),0, aLoVal, Offset = -20);
}


_SECTION_END();



_SECTION_BEGIN("TSKPMoMo");

if(Candle=="Modified Heikin Ashi")
{
blsLong = 0;
KPStopLine = E_TSKPSTOPLINE(High,Low,Close);
// tskp_upsell, tskp_triggerline, tskp_triggerlinevma
sw = E_TSKPUPSELL(Open,High,Low,Close,Volume);
KPTriggerLine = tskp_triggerline;
KPFast3Val = IIf((E_TSKPFAST3(Open,High,Low,Close,Volume)> 0),1, -1);
//tskp_fast2val1, tskp_fast2val2
dummy = E_TSKPFAST2(Open,High,Low,Close,Volume);
KPFast2Val = IIf ((tskp_fast2val1 > 0),1,-1); 



Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
sctotal = 0;
sctotal = sctotal  + IIf(tskp_colortmplcnd0 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd1 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd2 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd3 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd4 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd5 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd6 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd7 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd8 > 0, 1, -1); 

// tskp_mediumma,tskp_mediumup,tskp_mediumdown
dummy = E_TSKPMEDIUM(Close);
KPMediumUP = tskp_mediumup;
KPMediumDwn = tskp_mediumdown;
KPMediumMA = tskp_mediumma;

// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
aHiVal = H - H;
aLoVal = L - L;


for (curBar=5; curBar < BarCount-1; curBar++)
{


 if( (blsLong == -1) OR (blsLong == 0))
   {
       if ((sctotal[CurBar]  >= 5) AND (KPMediumUP[CurBar]  > KPMediumMA[CurBar] ) AND (KPFast3Val[CurBar]  == 1) AND 
        (KPFast2Val[CurBar]  == 1) AND (KPTriggerLine[CurBar]  >= KPStopLine[CurBar] ))
       {
         blsLong = 1;
    aLPivs[CurBar] = 1;
    aLoVal[CurBar] = Low[CurBar];
       }
    }

 if( (blsLong == 1) OR (blsLong == 0))
   {
       if ((sctotal[CurBar]  <= -5) AND (KPMediumDwn[CurBar]  < KPMediumMA[CurBar] ) AND (KPFast3Val[CurBar]  == -1) AND 
       (KPFast2Val[CurBar]  == -1) AND (KPTriggerLine[CurBar]  <= KPStopLine[CurBar] ))
       {
         blsLong = -1;
         aHPivs[Curbar] = 1;
    aHiVal[Curbar] = High[Curbar];
       }
    }

    if ((blsLong == 1) AND ((sctotal[CurBar]  < 5) OR (KPMediumUP[CurBar]  < KPMediumMA[CurBar] )  OR  
       (KPFast2Val[CurBar]  < 1)  OR  (KPFast3Val[CurBar]  < 1) OR (KPTriggerLine[CurBar]  < KPStopLine[CurBar] )) )
       {
           blsLong= 0;
        }
          
      if ((blsLong == -1) AND ((sctotal[CurBar]  > -5)  OR  (KPMediumDwn[CurBar] > KPMediumMA[CurBar] )  OR  
         (KPFast2Val[CurBar]  > -1)  OR (KPFast3Val[CurBar]  > -1)  OR 
         (KPTriggerLine[CurBar]  > KPStopLine[CurBar] )) )
         {
            blsLong = 0;
         }
}

PlotShapes (IIf(aHPivs == 1, shapeHollowSmallSquare, shapeNone) ,colorRed, layer = 0, yposition = flowerHigh, offset = 12 );
PlotShapes (IIf(aLPivs == 1, shapeHollowSmallSquare, shapeNone) ,colorLime, layer = 0, yposition = flowerLow, offset = -12 );

} 
_SECTION_END();

_SECTION_BEGIN("TSKPEBand");
/* Standard Error Bands */
Periods = Param("Standard Error", 20, 3, 200, 1); 
Smooth  = Param("Smooth",12,2,100,1);


LRCurve = LinearReg( C, periods ); 
MALRCurve  = MA(LRCurve, Smooth);
SEValue = StdErr( C, periods ); 
SErrorAvg =  MA(SEValue, Smooth);

LowerBand = MALRCurve - SErrorAvg ;
UpperBand = MALRCurve + SErrorAvg ;

Plot( MALRCurve , "MidBand", ParamColor("ColorMB",ColorRGB(0,200,0))  , ParamStyle("StyleMB", style=styleDashed, Mask=maskDefault )); 
Plot( UpperBand , "UpperBand", ParamColor("ColorUp",colorTeal)  , ParamStyle("StyleUp", style=styleDashed, Mask=maskDefault ));
Plot( LowerBand , "LowerBand", ParamColor("ColorLo",colorTeal), ParamStyle("StyleLo", style=styleDashed, Mask=maskDefault ));
_SECTION_END();


_SECTION_BEGIN("Cloud Setting");
//Cloud
ParmCloud = ParamToggle("Cloud", "No|Yes", 1);

CloudResColor=ParamColor("CloudResColor",ColorRGB(15,15,15));
CR=Upperband;
CS=Lowerband;

if(parmCloud == 1)
{
 PlotOHLC( CS, CS, CR,CR, "Band", CloudResColor, styleCloud | styleNoLabel|styleNoTitle); 
}

_SECTION_END();

_SECTION_BEGIN("KPL Swing");
//Copyright Kamalesh Langote. Email:kpl@vfmdirect.com. More details at http://www.vfmdirect.com/kplswing
//Save indicator as "kplswing.afl" in C: program files > Amibroker > Formulas > Custom folder and then drap and drop on price chart
no=Param( "Swing", 20, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase); // or styleaArea

Buy=Cross(C,tsl);
Sell=Cross(tsl,C);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));
_SECTION_END();


///////////This system has kpl swing with ishimaku clouds and targets and stop loss

/////////////////////////////////// Programs Begins

//////////////////with near days high low scanner



////////////////////////////////////////////////////////////////////////////////////////////////




////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
//{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = s5d[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 = s5d[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, s5d[BarCount-1], Ref(s5d, -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);

}


printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // 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( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( ( " Trading System "),88,y-165);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 88, y-22);;

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBlack) );
Hor=Param("Horizontal Position",750,800,800,800);
Ver=Param("Vertical Position",27,27,27,27);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();

////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////





/*Plot EMA*/
Plot( EMA( Close,13), "13 EMA", colorRed,styleLine);
Plot( EMA( Close,34), "34 EMA", colorBlue,styleLine);
Plot( EMA( Close,55), "55 EMA", colorBlack,styleLine);
Plot( EMA( Close,89), "89 EMA", colorYellow,styleLine);

//////////////////////Clouds
_SECTION_BEGIN("Ichimoku Cloud Charts");
GraphXSpace =1;
prds = Param("Standard Line Periods?", 13,5,26,1);
prds1 = Param("Turning Line Periods?", 3,3,10,1);
prds2 = Param("Delayed Line Periods?", 12,4,25,1);
prds3 = Param("Spans Periods?", 16,10,52,1);
TL = ( HHV( H, prds1) + LLV( L, prds1) )/2;
SL = ( HHV( H, prds) + LLV( L, prds) )/2;
DL = Ref( C, prds2);
Sp1 = Ref( ( SL + TL )/2, -prds2);
Sp2 = Ref( (HHV( H, prds3) + LLV(L, prds3))/2, -prds2);
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
if ( ParamToggle( "Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip = StrFormat( "Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: " + NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
}
PlotOHLC (Sp1,Sp1,Sp2,Sp2,"Cloud",IIf(Sp1>Sp2,ParamColor("Span1 Color", ColorRGB(0,255,0)),ParamColor("Span2 Color",ColorRGB(255,104,32))),styleCloud);

_SECTION_END(); 

/////////////////////////////////////Kpl Swing
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//kpl swing formula here
//---- heikin ashi
HaClose = (O+H+L+C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), .40); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * IIf(StrFind(Name(),"JPY"),100,10000);
// Plot(EMA(HaClose,9),"",colorWhite, styleLine);
// Plot(EMA(HaClose,18),"",colorBlack, styleLine);
_SECTION_BEGIN("KPL Swing");
no=Param( "Swing", 10, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase); // or styleaArea

_SECTION_END();





////////////////////details of stock at the title

_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 ) ) ));

_SECTION_END();



/////////////////////weekly high low

_SECTION_BEGIN("weekly-H-L");
Hclose=HHV(H,5);
Lclose= LLV(L,5);
DH = EncodeColor(colorDarkBlue) + "weekly-H-L = " + Hclose + "\n";
DL = EncodeColor(colorDarkRed) + "weekly-H-L = " + Lclose + "\n";
_N(Title = StrFormat("{{NAME}} ({{INTERVAL}}), {{DATE}} ; {{OHLCX}}, V=%1.0f\n {{VALUES}}\n\n", V) + DH + DL);

_SECTION_END(); 

/////////////////Stock near days high and low scanner
TimeFrameSet(inHourly);
H1 = HHV(H, 1) ;

H2= (H1-C)< .001*C;

L1 = LLV(L,1) ;


L2 = (C-L1) < .001*C ;

TimeFrameRestore() ;

SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol");
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn(C, "CMP", 1.2);



Filter = H2 OR L2 ;

Buy = H2 ;
Sell = L2 ;


///////////////////////////candle stick reader


_SECTION_BEGIN("Candle Identification");
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
function CandlePattern(P)
   {
   global PatternName;
   if(P == 0) { PatternName = "NearDoji"; Pv = (abs(O-C)<= ((H-L)*0.1)); }
   else if(P == 1) { PatternName = "BlackCandle"; Pv = (O>C); }
   else if(P == 2) { PatternName = "LongBlackCandle"; Pv = (O>C AND
(O-C)/(.001+H-L)>.6); }
   else if(P == 3) { PatternName = "SmallBlackCandle"; Pv = ((O>C) AND
((H-L)>(3*(O-C)))); }
   else if(P == 4) { PatternName = "WhiteCandle"; Pv = (C>O); }
   else if(P == 5) { PatternName = "LongWhiteCandle"; Pv = ((C>O) AND
((C-O)/(.001+H-L)>.6)); }
   else if(P == 6) { PatternName = "SmallWhiteCandle"; Pv = ((C>O) AND
((H-L)>(3*(C-O)))); }
   else if(P == 7) { PatternName = "BlackMaubozu"; Pv = (O>C AND H==O AND
C==L); }
   else if(P == 8) { PatternName = "WhiteMaubozu"; Pv = (C>O AND H==C AND
O==L); }
   else if(P == 9) { PatternName = "BlackClosingMarubozu"; Pv = (O>C AND
C==L); }
   else if(P == 10) { PatternName = "WhiteClosingMarubozu"; Pv = (C>O AND
C==H); }
   else if(P == 11) { PatternName = "BlackOpeningMarubozu"; Pv = (O>C AND
O==H); }
   else if(P == 12) { PatternName = "WhiteOpeningMarubozu"; Pv = (C>O AND
O==L); }
   else if(P == 13) { PatternName = "HangingMan"; Pv = (((H-L)>4*(O-C)) AND
((C-L)/(.001+H-L)>= 0.75) AND ((O-L)/(.001+H-L)>= 0.75)); }
   else if(P == 14) { PatternName = "Hammer"; Pv = (((H-L)>3*(O-C)) AND
((C-L)/(.001+H-L)>0.6) AND ((O-L)/(.001+H-L)>0.6)); }
   else if(P == 15) { PatternName = "InvertedHammer"; Pv = (((H-L)>3*(O-C))
AND ((H-C)/(.001+H-L)>0.6) AND ((H-O)/(.001+H-L)>0.6)); }
   else if(P == 16) { PatternName = "ShootingStar"; Pv = (((H-L)>4*(O-C))
AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75)); }
   else if(P == 17) { PatternName = "BlackSpinningTop"; Pv = ((O>C) AND
((H-L)>(3*(O-C))) AND (((H-O)/(.001+H-L))<.4) AND
(((C-L)/(.001+H-L))<.4)); }
   else if(P == 18) { PatternName = "WhiteSpinningTop"; Pv = ((C>O) AND
((H-L)>(3*(C-O))) AND (((H-C)/(.001+H-L))<.4) AND
(((O-L)/(.001+H-L))<.4)); }
   else if(P == 19) { PatternName = "BearishAbandonedBaby"; Pv = ((C1 == O1)
AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H)); }
   else if(P == 20) { PatternName = "BearishEveningDojiStar"; Pv = ((C2>O2)
AND ((C2-O2)/(.001+H2-L2)>.6) AND (C2<O1) AND (C1>O1) AND
((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1)); }
   else if(P == 21) { PatternName = "DarkCloudCover"; Pv = (C1>O1 AND
((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(.001+(H-L)>0.6)); }
   else if(P == 22) { PatternName = "BearishEngulfing"; Pv = ((C1>O1) AND
(O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1))); }
   else if(P == 23) { PatternName = "ThreeOutsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND
(C<C1)); }
   else if(P == 24) { PatternName = "BullishAbandonedBaby"; Pv = ((C1 == O1)
AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1)); }
   else if(P == 25) { PatternName = "BullishMorningDojiStar"; Pv = ((O2>C2)
AND ((O2-C2)/(.001+H2-L2)>.6) AND (C2>O1) AND (O1>C1) AND
((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1)); }
   else if(P == 26) { PatternName = "BullishEngulfing"; Pv = ((O1>C1) AND
(C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1))); }
   else if(P == 27) { PatternName = "ThreeOutsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND
(C>C1)); }
   else if(P == 28) { PatternName = "BullishHarami"; Pv = ((O1>C1) AND (C>O)
AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1))); }
   else if(P == 29) { PatternName = "ThreeInsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND
(C>C1) AND (O>O1)); }
   else if(P == 30) { PatternName = "PiercingLine"; Pv = ((C1<O1) AND
(((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND
((C-O)/(.001+(H-L))>0.6)); }
   else if(P == 31) { PatternName = "BearishHarami"; Pv = ((C1>O1) AND (O>C)
AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1))); }
   else if(P == 32) { PatternName = "ThreeInsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND
(C<C1) AND (O<O1)); }
   else if(P == 33) { PatternName = "ThreeWhiteSoldiers"; Pv = (C>O*1.01)
AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND
(O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<.2) AND
(((H1-C1)/(H1-L1))<.2) AND (((H2-C2)/(H2-L2))<.2); }
   else if(P == 34) { PatternName = "DarkCloudCover"; Pv = (C1>O1*1.01) AND
(O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND
(MA(C,13)-Ref(MA(C,13),-4)>0); }
   else if(P == 35) { PatternName = "ThreeBlackCrows"; Pv = (O>C*1.01) AND
(O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1)
AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<.2) AND (((C1-L1)/(H1-L1))<.2)
AND (((C2-L2)/(H2-L2))<.2); }
   else if(P == 36) { PatternName = "doji"; Pv = (O == C); }
   else if(P == 37) { PatternName = "GapUp"; Pv = GapUp(); }
   else if(P == 38) { PatternName = "GapDown"; Pv = GapDown(); }
   else if(P == 39) { PatternName = "BigGapUp"; Pv = L>1.01*H1; }
   else if(P == 40) { PatternName = "BigGapDown"; Pv = H<0.99*L1; }
   else if(P == 41) { PatternName = "HugeGapUp"; Pv = L>1.02*H1; }
   else if(P == 42) { PatternName = "HugeGapDown"; Pv = H<0.98*L1; }
   else if(P == 43) { PatternName = "DoubleGapUp"; Pv = GapUp() AND
Ref(GapUp(),-1); }
   else if(P == 44) { PatternName = "DoubleGapDown"; Pv = GapDown() AND
Ref(GapDown(),-1); }
   return Pv;
   }

PatternNameList = "";
for(Cp=0; Cp<=44; Cp++)
 {
 VarSet("Pattern"+NumToStr(Cp,1.0),CandlePattern(cP));
 PatternNameList = PatternNameList +PatternName+","; 
 }

BI = BarIndex();
SelectedBar = SelectedValue(BI) -BI[0];
//Selectedbar = Status("lastvisiblebar")-1;
PStr="";
for(Cp=0; Cp<=44; Cp++)
 {
 Temp = VarGet("Pattern"+NumToStr(Cp,1.0));
 if(temp[SelectedBar]) Pstr=Pstr+"#"+NumToStr(Cp,1.0)+" - "+StrExtract(PatternNameList,Cp)+"\n";
 }


FS=Param("Font Size",11,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite );  
GfxSetTextColor( ParamColor("Color",colorWhite) ); 
Hor=Param("Horizontal Position",237,1,1200,1);
Ver=Param("Vertical Position",50,1,830,1); 
GfxTextOut("Candle Reader= "+Pstr, Hor , Ver );




_SECTION_END();

Friday, 5 September 2014

A Nice Explorer for Amibroker (AFL)


https://www.facebook.com/StocKanalysisBd?ref=hl

Explorer for Amibroker (AFL)





function T3(price,periods)
{
 s = 0.84;
 e1=EMA(price,periods);
 e2=EMA(e1,Periods);
 e3=EMA(e2,Periods);
 e4=EMA(e3,Periods);
 e5=EMA(e4,Periods);
 e6=EMA(e5,Periods);
 c1=-s*s*s;
 c2=3*s*s+3*s*s*s;
 c3=-6*s*s-3*s-3*s*s*s;
 c4=1+3*s+s*s*s+3*s*s;
 Ti3=c1*e6+c2*e5+c3*e4+c4*e3;
 return ti3;
}

//WAD
TrueRangeHigh=Max( Ref(Close,-1), High );
TrueRangeLow=Min( Ref(Close,-1), Low );
WAD = Cum(IIf(C > Ref(C,-1),C-TrueRangeLow, IIf(C < Ref(C,-1),C-TrueRangeHigh,0)));
wadup = WAD > EMA (WAD,20);
waddn = WAD < EMA (WAd,20);
wadbl = Cross(WAD, EMA(WAD,20));
wadbr = Cross(EMA(WAD,20), WAD);
wad_status= WriteIf(wadup, "Bullish Zone", WriteIf(waddn, "Bearish Zone", WriteIf(wadbl, "Bullish Cross", WriteIf(wadbr, "Bearish Cross", "Zilch"))));
wad_Col=IIf(wadup OR wadbl, colorGreen, IIf(waddn OR wadbr, colorRed, colorLightGrey));


//Trend Strength
up = ADX(10) > 20;
down = ADX(10) < 20;
choppy = ADX(10) < PDI(10) AND ADX(10) < MDI(10);
adx_status= WriteIf(up, "Strong Trend", WriteIf(down, "Weak Trend", WriteIf( choppy, "Choppy", "Zilch")));
adx_Col=IIf(up, colorGreen, IIf(down, colorRed, IIf(Choppy, colorPink, colorLightGrey)));

// Coppock
r1=ROC(C,14);
r2=ROC(C,11);
ck=EMA((r1+r2),10);
upt=IIf(ck>0 AND ROC(ck,1)>0,ck,0);
ups=IIf(ck>0 AND ROC(ck,1)<0,ck,0);
downs=IIf(ck<0 AND ROC(ck,1)>0,ck,0);
down=IIf(ck<0 AND ROC(ck,1)<0,ck,0);
cop_status= WriteIf(upt, "Uptrend", WriteIf(ups, "Uptrend Sidways", WriteIf(downs, "Downtrend Sideways", WriteIf(down, "Downtrend", "Zilch"))));
cop_Col=IIf(upt, colorDarkGreen, IIf(ups, colorGreen, IIf(downs, colorOrange, IIf(down, colorRed, colorLightGrey))));

//Initial Buy Signal
Ibuy =  Cross(RSI(14), EMA(RSI(14),9));
Isell = Cross(EMA(RSI(14),9), RSI(14));
Ibuy = ExRem(Ibuy, ISell);
Isell = ExRem(ISell, Ibuy);
BlRSI = RSI(14) > EMA(RSI(14),9);
BrRSI = RSI(14) < EMA(RSI(14),9);
Ibuy_status= WriteIf(Ibuy, "Buy Warning", WriteIf(Isell, "Sell Warning", WriteIf(BlRSI, "Bullish Zone", WriteIf(BrRSI, "Breaish Zone", "Zilch"))));
I_Col=IIf(Ibuy OR BlRSI, colorGreen, IIf(Isell OR BrRSI, colorRed, colorLightGrey));

//BB Breakout
bbk2 = Cross(RSI(14),30) AND
RSI(14) > Ref(RSI(14),-1);
bbk_status= WriteIf(bbk2, "Break RSI", "Zilch" );
bbk_Col=IIf(bbk2, colorGreen, colorLightGrey);


//Price Smoothing
TBuy = Cross (T3(C,3), T3(C,5));
TSell =  Cross (T3(C,5), T3(C,3));
TBuy = ExRem(TBuy, TSell);
TSell = ExRem(TSell, TBuy);
Tbuy_status= WriteIf(TBuy, "Buy", WriteIf(TSell, "Sell", "Zilch"));
T_Col=IIf(TBuy, colorGreen, IIf(TSell, colorRed, colorLightGrey));

//Guppy MMA
P1 = EMA(C,3);
P2 = EMA(C,5);
P3 = EMA(C,8);
P4 = EMA(C,10);
P5 = EMA(C,12);
P6 = EMA(C,15);
P7 = EMA(C,30);
P8 = EMA(C,35);
P9 = EMA(C,40);
P10 = EMA(C,45);
P11 = EMA(C,50);
P12 = EMA(C,55);
P13 = EMA(C,60);
GBuy = Cross (P1,P8);
GSell = Cross(P8,P1);
GBuy = ExRem(GBuy, GSell);
GSell = ExRem(GSell, GBuy);
Gbuy_status= WriteIf(GBuy, "Buy", WriteIf(GSell, "Sell", "Zilch"));
G_Col=IIf(GBuy, colorGreen, IIf(GSell, colorRed, colorLightGrey));

//EMA-9
MAbuy = Cross(C, EMA(C,9));
MAsell= Cross(EMA(C,9),C);
MAbuy = ExRem(MAbuy, MAsell);
MAsell = ExRem(MAsell, MAbuy);
MA1 = C > EMA(C,9);
MA11 = C < EMA(C,9);
MA_status= WriteIf(MAbuy, "Buy", WriteIf(MAsell, "Sell", WriteIf(MA1, "Bullish", WriteIf(MA11, "Bearish","Zilch"))));
MA_Col=IIf(MAbuy OR MA1, colorGreen, IIf(MAsell OR MA11, colorRed, colorLightGrey));

//EMA-20
MA2buy = Cross(C, EMA(C,20));
MA2sell= Cross(EMA(C,20),C);
MA2buy = ExRem(MA2buy, MA2sell);
MA2sell = ExRem(MA2sell, MA2buy);
MA2 = C > EMA(C,20);
MA22 = C < EMA(C,20);
MA2_status= WriteIf(MA2buy, "Buy", WriteIf(MA2sell, "Sell", WriteIf(MA2, "Bullish", WriteIf(MA22, "Bearish","Zilch"))));
MA2_Col=IIf(MA2buy OR MA2, colorGreen, IIf(MA2sell OR MA22, colorRed, colorLightGrey));

//EMA-9 x 20
MA3buy = Cross(EMA(C,9), EMA(C,20));
MA3sell= Cross(EMA(C,20),EMA(C,9));
MA3buy = ExRem(MA3buy, MA3sell);
MA3sell = ExRem(MA3sell, MA3buy);
MA3 = EMA(C,9) > EMA(C,20);
MA33 = EMA(C,9) < EMA(C,20);
MA3_status= WriteIf(MA3buy, "Buy", WriteIf(MA3sell, "Sell", WriteIf(MA3, "Bullish", WriteIf(MA33, "Bearish","Zilch"))));
MA3_Col=IIf(MA3buy OR MA3, colorGreen, IIf(MA3sell OR MA33, colorRed, colorLightGrey));

//Midterm Bullish or Bearish
mBull = C > EMA(C,50);
mBear= C < EMA(C,50);
mt_status= WriteIf(mBull, "Bullish", WriteIf(mBear, "Bearish", "Zilch"));
mt_Col=IIf(mBull, colorGreen, IIf(mbear, colorRed, colorLightGrey));

//Longterm Bullish or Bearish
Bull = C > EMA(C,200);
Bear= C < EMA(C,200);
lt_status= WriteIf(Bull, "Bullish", WriteIf(Bear, "Bearish", "Zilch"));
lt_Col=IIf(Bull, colorGreen, IIf(bear, colorRed, colorLightGrey));

//Long-term Price Trend
rc= C > EMA (C,50) AND C < EMA(C,200) AND EMA(C,50) < EMA(C,200);
ac=  C > EMA (C,50) AND C > EMA(C,200) AND EMA(C,50) < EMA(C,200);
bl= C > EMA (C,50) AND C > EMA(C,200) AND EMA(C,50) > EMA(C,200);
wr= C < EMA (C,50) AND C > EMA(C,200) AND EMA(C,50) > EMA(C,200);
ds= C < EMA (C,50) AND C < EMA(C,200) AND EMA(C,50) > EMA(C,200);
br= C < EMA (C,50) AND C < EMA(C,200) AND EMA(C,50) < EMA(C,200);

ltp=WriteIf(rc, "RECOVERY", WriteIf(ac, "ACCUMULATION", WriteIf(bl, "BULLISH", WriteIf(wr, "WARNING",WriteIf(ds, "DISTRIBUTION",WriteIf(br, "BEARISH", "Zilch"))))));
ltp_col=IIf( rc, colorBlue, IIf( ac, colorGreen, IIf(bl, colorDarkGreen, IIf(wr, colorOrange, IIf(ds, colorRed, IIf(br, colorDarkRed, colorLightGrey ))))));

G=((O-Ref(L,-1))/Ref(L,-1))*100;
F=((C-Ref(C,-1))/Ref(C,-1))*100;

//T-3 Delta
T3Day = T3(Close, 3);
T5Day = T3(Close, 5);
Delta = T3Day - T5Day;


// Filter=O<Ref(L,-1) AND C>Ref(C,-1)|C>Ref(O,-1)
// AND L<Ref(L,-1) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3)
// AND V>Ref(V,-1) AND V>(MA(Ref(V,-1),5)+(MA(Ref(V,-1),5)*0.3)) AND MA(V,21)>50000;

Filter=MA(V,21)>50000 AND Close < 15;

Buy=Filter;

AddColumn(V, "Volome", 1, IIf(V > Ref(V,-1), colorGreen, colorRed),-1);
AddColumn(((V/EMA(Ref(V,-1),10)))*100, "VolSpike %", 1.2, IIf(V> EMA(Ref(V,-1),10), colorBlue, colorRed),-1);
AddColumn(Delta, "Delta",1.2, IIf(delta < 0, colorRed, colorGreen),-1);
AddColumn(C, "Close", 1.2, IIf(C > Ref(C,-1), colorGreen, colorRed),-1);
AddColumn(G,"O Low%",1.2,-1);
AddColumn(F,"C High%",1.2,-1);
AddColumn(RSI(14),"RSI-14",1.2, IIf(RSI(14) > Ref(RSI(14),-1), colorGreen, colorRed),-1);
AddColumn(ADX(10),"ADX-10",1.2,IIf(ADX(10) > Ref(ADX(10),-1), colorGreen, colorRed),-1);
AddTextColumn(bbk_status, "Breaks", 1.6, colorWhite, bbk_Col,-1);
AddTextColumn(Tbuy_status, "T3-Signal", 1.6, colorWhite, T_Col,-1);
AddTextColumn(Gbuy_status, "Guppy", 1.6, colorWhite, G_Col,-1);
AddTextColumn(MA_status, "EMA-9", 1.6, colorWhite, MA_Col,-1);
AddTextColumn(MA2_status, "EMA-20", 1.6, colorWhite, MA2_Col,-1);
AddTextColumn(MA3_status, "EMA-9x20", 1.6, colorWhite, MA3_Col,-1);
AddTextColumn(Ibuy_status, "RSI signal", 1.6, colorWhite, I_Col,-1);
AddTextColumn(adx_status, "Trend", 1.6, colorWhite, adx_Col,-1);
AddTextColumn(cop_status, "Coppock", 1.6, colorWhite, cop_Col,-1);
//AddTextColumn(wad_status, "WAD", 1.6, colorWhite, WAD_Col,-1);
//AddTextColumn(mt_status, "EMA-50", 1.6, colorWhite, mt_Col,-1);
//AddTextColumn(lt_status, "EMA-200", 1.6, colorWhite, lt_Col,-1);
AddTextColumn(ltp, "Phase", 1.6, colorWhite, ltp_Col,-1);

Dinamic Support resistance with Heiken Ashi flower Afl


// https://www.facebook.com/StocKanalysisBd?ref=hl

Dinamic Support resistance with Heiken Ashi  flower Afl 






SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("\\c02 {{NAME}} || {{INTERVAL}} {{DATE}} || Open %g,High: %g,Low: %g, Close: %g (%.1f%%)
Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}",
O, H, L, C, SelectedValue( ROC( C, 1 )) ));
barcolor =IIf(C>O, ParamColor("Up candlestick", colorBrightGreen ), ParamColor("Down candlestick", colorOrange ));


_SECTION_BEGIN("o");


MaxGraph = 12;
BuyOffSet = 18;
SellOffset = BuyOffSet;
RegLength = 5;
BuyATRPeriod = 2;
SellATRPeriod = BuyATRPeriod;
ATRMultiplier = 0.5;
G8 = HHV(H-ATRMultiplier*ATR(BuyATRPeriod),BuyOffset); 
G9 = LLV(L+ATRMultiplier*ATR(SellATRPeriod),SellOffset);
ave=(G8+G9)/2;

nn=21;
mmm=120;
TYP=(High + Low + 2*Close)/4;
CI=(TYP-MA(TYP,14))/(0.015*StDev(TYP,14));
CCCI=EMA(CI,5)+mmm;
Hh=HHV(H,nn);
Ll=LLV(L,nn);
MM=(Hh+Ll)/2;
CCCC=EMA(CCCI*(Hh-Ll)/(2*mmm)+Ll,5);

Mbuy = (Cccc>Ref(Cccc,-1) AND Ref(Cccc,-1)<Ref(Cccc,-2) AND Cccc<ave) OR Cross(Cccc,Ll) OR Cross(Cccc,G9);
MSell= (Cccc<Ref(Cccc,-1) AND Ref(Cccc,-1)>Ref(Cccc,-2) AND Cccc>ave) OR Cross(Hh,Cccc) OR Cross(G8,Cccc);
PlotShapes( IIf( MBuy, shapeHollowSmallCircle, shapeNone ), colorBlue, 0, yposition = L, offset = -25 );
PlotShapes( IIf( MSell, shapeHollowSmallCircle, shapeNone ), colorYellow, 0, yposition = H, offset = 25 );
_SECTION_END();

BuyOffSet = 18;
SellOffset = 18;
RegLength = 5;
BuyATRPeriod = 2;
SellATRPeriod = BuyATRPeriod;
ATRMultiplier = 0.5;

G8 = HHV(H-ATRMultiplier*ATR(BuyATRPeriod),BuyOffset);
G9 = LLV(L+ATRMultiplier*ATR(SellATRPeriod),SellOffset);
ave=(G8+G9)/2;

CC = EMA((Open+High+Low+Close)/4,3);
CO = EMA((Ref(Open,-1) + Ref(CC,-1))/2,3);
Temp = Max(High,CO);
CH = EMA(Max(Temp, CC),3);
Temp = Min(Low,CO);
CL = EMA(Min(Temp, CC),3);
Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

// Bar fill color
Show_color = ParamToggle("Display CandleColor", "No|Yes", 1);
r1 = Param( "ColorFast avg", 5, 2, 200, 1 );
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 );
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, colorWhite,IIf(m1>0 AND m1>s1,colorLightBlue,IIf(m1>0 AND m1<s1,colorOrange,colorRed)));
barColor=IIf(Mbuy ,colorBrightGreen,IIf(Msell,colorDarkRed,mycolor));
if(Show_color)
{
ColorHighliter = barColor;
SetBarFillColor( ColorHighliter );

}

barColor1=IIf(C>Green ,colorBlue,IIf(C < RED,colorRed,colorLightYellow));
Barcolor2=IIf(C>Green, colorLightBlue,IIf(C < RED, colorRed, colorWhite));
barColor=IIf(Mbuy ,colorBrightGreen,IIf(Msell,colorDarkRed,barcolor2));
SetBarFillColor(barcolor);
PlotOHLC( CO,CH,CL,CC, "Price", barcolor1, styleCandle );
nn=14;
mmm=120;
Hh=HHV(CH,nn);
Ll=LLV(CL,nn);
Hh1=HHV(IIf(CC>CO,CC,CO),nn);
Ll1=LLV(IIf(CC<CO,CC,CO),nn);
MM=(Hh+Ll)/2;
Plot(HHV(Hh,40),"Resistance",colorRed,styleLine|styleThick);
Plot(LLV(Ll,40),"Support",colorGrey40,styleLine|styleThick);
Plot(Hh,"Resistance",colorDarkRed,styleLine|styleThick);
Plot(Ll,"Support",colorGreen,styleLine|styleThick);
Plot(Hh1,"Resistance",11,styleLine);
Plot(Ll1,"Support",colorBrightGreen,styleLine);

_SECTION_BEGIN("9Trading2");
function Rise( Pd, perd, Pl, perl )
{
MAD = DEMA(Pd,perd);
MAL = LinearReg(Pl,perl);
CondR = ROC(MAD,1)>0 AND ROC(MAL,1)>0;
CondF = ROC(MAD,1)<0 AND ROC(MAL,1)<0;
R[0] = C[0]>(H[0]+L[0])/2;

for(i=1;i<BarCount;i++)
{
if( CondR[i] )
{
R[i] = 1;
}
else
{
if( CondF[i] )
{
R[i] = 0;
}
else
{
R[i] = R[i-1];
}
}
}
return R;
}

PrD = C;
PrL = H/2+L/2;
PrdD = PrdL = PrdM = Param("Prd",12,2,40,1);

permax = Max(prdd,prdl);

Rs = IIf( BarIndex()<permax, 0, Rise(PrD, PrdD, PrL, PrdL) );
Fs = IIf( BarIndex()<permax, 0, 1-Rs );

Confirm = MA(C,prdm);

function DirBar( dr, df )
{
B[0] = 0;

for(i=1;i<BarCount;i++)
{
if( dr[i-1] && df[i] )
{
B[i] = 1;
}
else
{
if( df[i-1] && dr[i] )
{
B[i] = 1;
}
else
{
B[i] = B[i-1] + 1;
}
}
}
return B;
}

Bs = DirBar( Rs, Fs );
Direction = ROC(Confirm,1) > 0 AND ROC(Confirm,5) > 0;
Downward = ROC(Confirm,1) < 0 AND ROC(Confirm,5) < 0;

Select = Rs AND Ref(Fs,-1);
Caution = Fs AND Ref(Rs,-1);

PlotShapes( shapeSmallCircle* select, colorBlue, 0, CL, -2 );
PlotShapes( shapeSmallCircle* Caution, colorRed, 0, CH,2 );
_SECTION_END();
_SECTION_BEGIN("ATR Trailing SL");
ka = 1;
Pero = Param("ATR", 4, 1, 30, 0.50);

HACLOSE=(O+H+L+C)/4;

j=Haclose;
f=ATR(Pero);

rfsctor = WMA(f, Pero);

revers = ka * rfsctor;

Trend = 1;
NW[0] = 0;

for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j[i] < NW[i-1])
{
Trend[i] = -1;
NW[i] = j[i] + Revers[i];
}
else
{
Trend[i] = 1;
if((j[i] - Revers[i]) > NW[i-1])
{
NW[i] = j[i] - Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j[i] > NW[i-1])
{
Trend[i] = 1;
NW[i] = j[i] - Revers[i];
}
else
{
Trend[i] = -1;
if((j[i] + Revers[i]) < NW[i-1])
{
NW[i] = j[i] + Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
}



Buy1= C>NW;
Sell1=C<NW;
Buy2 = ExRem(Buy1, Sell1);
Sell2 = ExRem(Sell1, Buy1);
PlotShapes(shapeHollowUpArrow * Buy2, colorGreen,0,L, - 40);
PlotShapes(shapeHollowDownArrow * Sell2, colorRed,0,H, - 40);

_SECTION_END();


_SECTION_BEGIN("Volatility");
Pero = Param("Volatility", 4, 1, 30, 0.50);
A = HHV(C,Pero);
B = HHV(O,Pero);
Cat = HHV(H,Pero);

E = LLV(C,Pero);
F = LLV(O,Pero);
Hat = LLV(L,Pero);

BO1 = IIf(A>B, A, B);
BO = IIf(BO1 >Cat, BO1, Cat);

BD1 = IIf(E <F, E, F);
BD = IIf(BD1 <Hat, BD1, Hat);

Buy11 = C > Ref(BO,-1);
Sell22 = C < Ref(BD,-1);
Buy2 = ExRem(Buy11, Sell22);
Sell2 = ExRem(Sell22, Buy11);
PlotShapes(shapeHollowUpArrow * Buy2, colorGreen,0,CL, - 33);
PlotShapes(shapeHollowDownArrow * Sell2, colorRed,0,CH, -33);
_SECTION_END();










_SECTION_BEGIN("Stochastic");

StochKval = StochK(10,5);
StochDval = StochD(10,5,5);

SSbuy = Cross(StochK(10,5), StochD(10,5,5));
SSsell = Cross (StochD(10,5,5), StochK(10,5));

Filter = SSbuy OR SSsell;

PlotShapes(IIf(SSbuy AND StochKval < 26, shapeHollowSmallSquare,shapeNone), colorBrightGreen,0,CL, - 10);
PlotShapes(IIf(SSbuy AND StochKval < 26,shapeSmallCircle, shapeNone),colorBrightGreen,0,CL, - 10);
PlotShapes(IIf(SSbuy AND StochKval > 26, shapeSmallSquare,shapeNone), colorBrightGreen,0,CL, - 10);
PlotShapes(IIf(SSbuy AND StochKval > 26,shapeSmallCircle, shapeNone),colorDarkGreen,0,CL, - 10);
PlotShapes(shapeHollowSmallSquare * SSsell, colorRed,0,CH, 10);
PlotShapes(shapeSmallCircle * SSsell, colorRed,0,CH, 10);

_SECTION_END();

_SECTION_BEGIN("Text");
Font = ParamList("Font:","Calibri|Bauhaus 93|Arial|Futura|Tahoma|Times New Roman");
FontColor=ParamColor("FontColor", colorOrange);
FontSize=Param("FontSize", 12,1,100);
TextPosition1=Param("TextPosition1", 2,1,800);
TextPosition2=Param("TextPosition2", 30,1,1000);

GfxSelectFont(font, FontSize, 800);
GfxSetBkMode(1);
GfxSetTextColor(Fontcolor);
GfxTextOut("", TextPosition1, TextPosition2);
GfxSetBkColor(colorWhite);

_SECTION_END();

Wednesday, 3 September 2014

Resistance BREAK OUTS with Side Volume at Price AFL for Amibroker



//Resistance BREAK OUTS with Side Volume at Price



_SECTION_BEGIN("BREAK OUTS");


CodeName = "   Breakouts";
SetFormulaName("  Breakouts");


SetChartOptions(0, chartShowDates | chartWrapTitle);
if (ParamToggle("Tooltip shows", "All Values|Only Prices"))
{
  ToolTip = StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g (%.1f%%) \nVolume: " + NumToStr(V, 1), O, H, L, C, SelectedValue(ROC(C, 1)));
}

space = Param("Space on Chart", 20,  - 15, 50, 1);
GraphXSpace = space;
SetChartBkColor(ParamColor("Background Color", colorBlack));



H0 = H;
L0 = L;
C0 = C;
O0 = O;

Lookback = Param("LookBack", 10, 10, 50, 1); 
shift = Param("Shift", 5, 1, 50, 1); // ?
x0 = LastValue(Cum(1));
x1 = x0 - shift;
H = Ref(H,  - shift + 1);
L = Ref(L,  - shift + 1);
H1 = LastValue(Ref(HHV(H, Lookback),  - 1));
L1 = LastValue(Ref(LLV(L, Lookback),  - 1));

Plot(H1, "H1", colorYellow);
Plot(L1, "L1", colorYellow);

H = H0;
L = L0;
C = C0;
O = O0;

up = Cross(H, H1)AND Cum(1) > x1;
dn = Cross(L1, L)AND Cum(1) > x1;

Plot(C, "Close", IIf(Cum(1) > x1 - Lookback AND Cum(1) <= x1, colorBlue, IIf(Up, colorBrightGreen, IIf(Dn, colorRed, IIf(C > O, colorGreen, colorRed)))), 64);
PlotShapes(shapeDownArrow *(Cum(1) == x1 + 1), colorBlue);


TRIGGER = ParamToggle("Trigger ", "CLOSE|HIGH OR LOW");


XH1 = Cross(C, H1);
XL1 = Cross(L1, C);
XH2 = Cross(H, H1);
XL2 = Cross(L1, L);

if (TRIGGER == 0)
{
  Buy = XH1;
  Sell = XL1;
}

else
{
  Buy = XH2;
  Sell = XL2;
}


TradeDisplay = ParamToggle("Remove Extra Trades?", "No|Yes");

if(TradeDisplay != 0){
    Buy = ExRem(Buy, Sell);
      Sell = ExRem(Sell, Buy); 
}

Filter = Buy OR Sell;
Action = WriteIf(Buy, "BUY", WriteIf(Sell, "SELL", "   "));


AddColumn(C, "Last ", 2.2, colorWhite, colorBlue);
AddTextColumn(Action, "Action", 8.0, IIf(XH1, colorDarkGreen, colorDarkRed), colorWhite);
AddColumn(IIf(XH1, H1, L1), "BREAKOUT LEVEL", 3.2, colorYellow, IIf(XH1, colorDarkGreen, colorDarkRed));


PlotShapes(Buy *shapeUpArrow, colorBrightGreen, 0, L  ,  - 30);
PlotShapes(Sell *shapeDownArrow, colorLightYellow, 0, H,  - 30);
_SECTION_END();


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

_SECTION_END();

Monday, 1 September 2014

Woodiescci Signal with Candlestick Chart ...

Woodiescci  Signal with Candlestick Chart ...


///  https://www.facebook.com/StocKanalysisBd?ref=hl











_SECTION_BEGIN("Price");
pds = 20;
MAFAST = EMA( Close, 20 );
MASLOW = EMA( Close, 40 );
 
DonchianUpper = HHV( Ref( H, -1 ), pds );
DonchianLower = LLV( Ref( L, -1 ), pds );
DonchianMiddle = ( DonchianUpper + DonchianLower ) / 2;
 
UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close, 40 );
DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close, 40 );
Color = IIf( UpTrend, colorGreen, IIf( DnTrend, colorRed, colorBlue) );
UpTrend=ExRem(UpTrend,DnTrend);
Dntrend=ExRem(DnTrend,UpTrend);

Plot( C, "Price", Color, styleCandle | styleThick );
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0);

_SECTION_END();
PlotShapes(IIf(UpTrend, shapeUpArrow, shapeNone),colorBrightGreen, 0,L, Offset=-45);
PlotShapes(IIf(DnTrend, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);


_SECTION_BEGIN("L.T.P.");
cx = Param( "cxposn", 1000, 0, 1250, 1 );
cy = Param( "cyposn", 25, 0, 500, 1 );
GfxSelectFont( "Candara", 18, 98, False );
gfxcup = SelectedValue(C > Ref(C,-1));
gfxpcolor = IIf(gfxcup,colorBrightGreen,colorRed);
GfxSetTextColor(gfxpcolor);
//GfxSetTextColor( colorWhite );
GfxTextOut( "L.T.P.  " + C + " ", cx, cy );
_SECTION_END();

_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---sunday---Monday--TuesdayWednesday-Thursday--Friday--Saturday", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",0,-55,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "Otithi Lozz", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
_SECTION_END();

_SECTION_BEGIN("Title");

DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily);
DLoDay = TimeFrameGetPrice("L", inDaily);
Title = EncodeColor(colorWhite)+"   Otithi     "+EncodeColor(colorWhite)+ Name() + ", " + Interval(2) + ", " + Date() + "   -  "+strWeekday + "  - " +
EncodeColor(colorWhite)   +  "\nO " + EncodeColor(colorWhite) + O +

 ",   H :  "   + H +
 ",   L  :  " + L +
 ",   C  :  "  + C +
"\n"+EncodeColor(colorWhite)+ "  Day-Open : " +DODay + "  Day-High : " +DHiDay + "  Day-Low : " + DLoDay


;
_SECTION_BEGIN("Time Left");
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",430,0,1000,1);
y=Param("yposn",40,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New period" );
}

cx = Param( "cxposn", 1080, 0, 1250, 1 );
cy = Param( "cyposn", 5, 0, 500, 1 );
GfxSelectFont( "Candara", 14, 98, False );

GfxSetTextColor(colorBlue);

GfxTextOut( "T i m e L e f t   " + SecsToGo + " ", cx, cy );
_SECTION_END();



//------------------------------------------------------------------------------
//
//
//------------------------------------------------------------------------------
//
//  Here is Woodie's CCI Daily panel which was originally coded by Crasher_FL
//  and Wring. It is a modified Daily CCI Panel with the CCI 20, CCI 50 and CCI
//  6. It is complete with pattern recognition,backtesting, scanning, and
//
//  exploration options. The Pattern Recognition helps find the ZLR, HFE,
//  GB100(with a 34ema +/- 15 degree nuance), VT,FAMIR,MR and Choppy (Chop mode
//  being
//
//  defined as the CCI bars inbetween the 100's for 10 or more bars. The reset
//  out of chop is when the CCI hooks from extreme at the 200's). . The pattern
//  recognition is
//
//  located at the top left corner next to "Signal: ".
//
//  1=zlr
//
//  2-famir
//
//  3=vt
//
//  4=gb100
//
//  5=momentum reversal
//
//  This version has the Mplay Exit Indicator in it. The MPLAY exit is a CCI
//  hook to the oposite direction followed by another with the price closing in
//  the oposite
//
//  direction of the trade. I have coded the MPLAY Indicator with the CCI
//  panel. It is a series of green and red circles just below the +200 line.
//  The nearest green circle
//
//  that appears after a pattern (any pattern, not just the coded ones) is the
//  exit for a long position. The nearest red circle is the exit after a short
//  pattern. Ignore all the ones
//
//  inbetween. The circles appear after every and any occurance of an MPLAY
//  Exit, regardless if a pattern has appeared or not. Just use the nearest
//  applicable circle to exit
//
//  a pattern entered.
//
//  I also added the EMA angle colors to the 100's. Turquoise= uptrend,
//  Red=downtrend, Yellow=not trending. This code was originally in the cci
//  panel coded by
//
//  Crasher, I just tweeked it to be displayed in visual format. It is
//  identical to woodie's modification to the cci panel, which he uses as a
//  chop inicator as well. If there is a
//
//  constant color, the trend is in that direction. If the colors are mixed,
//  then there is a chop.
//
//  Use this setting for the background color like Woodie's charts...
//
//  Hue: 93
//
//  Sat: 44
//
//  Lum:87
//
//  Red:75
//
//  Green: 109
//
//  Blue: 96
//
//  Trade at your own risk, please use your own descretion, for educational
//  purposes only.
//
//  go here for further updates:
//
//
//  http://woodiescciclub.com/forum/viewforum.php?f=17&amp;sid=0f5f3762dff52213a0bcd2f983655cec
//
//  -Dennis
//
//------------------------------------------------------------------------------

///////////////////////////////

// CCI Woodies Style - Started by Wring

// Codded/Added by by Kris

// Added by Dennis and Greg

// Version: 1.027

// Last Update: 11/04/2005

// Additions:

// timer, EMA angle, LSMA angle, trending indicator

// Amibroker 4.70

///////////////////////////////

Version(4.70);

z = CCI(20);

z6 = CCI(6);

CCI50_var = CCI(50);

LSMA25 = LinearReg(C, 25 );

EMA34 = EMA(C,34);

PI = atan(1.00) * 4;

periods = 30;

HighHigh = HHV(H, periods);

LowLow = LLV(L, periods);

range = 25 / (HighHigh - LowLow) * LowLow;

TTMperiod = 6;

Low_ma = EMA(L, TTMperiod);

High_ma = EMA(H, TTMperiod);

Low_third = (High_ma - Low_ma) / 3 + Low_ma;

High_third = 2 * (High_ma - Low_ma) / 3 + Low_ma;

tempnum = Now( 4 ) - TimeNum();

TimeRem = Interval() - ((int(tempnum[BarCount - 1] / 100) * 60) +

(tempnum[BarCount - 1] - int(tempnum[BarCount - 1] / 100) * 100));

if (TimeRem[BarCount - 1] < 0) TimeRem = 0;

TitleTimeRem = EncodeColor(colorBlueGrey) + "Time Remaining: ";

MinuteVar = int(TimeRem / 60);

SecondsVar = int(frac(TimeRem / 60) * 60);

if (TimeRem[BarCount - 1] > 60)

{

TitleTimeRem = TitleTimeRem + EncodeColor(colorWhite) + MinuteVar + ":"

+ WriteIf(SecondsVar > 9, "", "0") + SecondsVar;

}

else if (TimeRem[BarCount - 1] > 20)

{

TitleTimeRem = TitleTimeRem + EncodeColor(colorYellow) + MinuteVar + ":"

+ WriteIf(SecondsVar > 9, "", "0") + SecondsVar;

}

else

{

TitleTimeRem = TitleTimeRem + EncodeColor(colorLime) + MinuteVar + ":" +

WriteIf(SecondsVar > 9, "", "0") + SecondsVar;

}

if(SelectedValue(CCI50_var) < 0)

{

CCI50Title = EncodeColor(colorRed);

}

else

{

CCI50Title = EncodeColor(colorLime);

}

CCI50Title = CCI50Title + "CCI 50 = " + round(CCI50_var) + ", ";

stop_range = IIf(O < C, IIf((H - O) < (C - L), C - L, H - O),

IIf((O - L) < (H - C), H - C, O - L));

StopTitle = EncodeColor(colorWhite) + "Stop = " + EncodeColor(colorYellow);

StopTitle = StopTitle + StrToNum(NumToStr(stop_range, 4.4));

x1_EMA34 = 0;

x2_EMA34 = 1;

y1_EMA34 = 0;

y2_EMA34 = (Ref(EMA34, -1) - EMA34) / Avg * range;

c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34));

angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);

TitleAngleEMA34 = EncodeColor(colorWhite) + "\nEMA34 angle = ";

angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);

if(SelectedValue(angle_EMA34) >= 25)

{

TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorTurquoise);

}

else if(SelectedValue(angle_EMA34) <= -25)

{

TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorRed);

}

else if(SelectedValue(angle_EMA34) >= 5)

{

TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorTurquoise);

}

else if(SelectedValue(angle_EMA34) <= -5)

{

TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorRed);

}

else

{

TitleAngleEMA34 = TitleAngleEMA34 + EncodeColor(colorYellow);

}

TitleAngleEMA34 = TitleAngleEMA34 + angle_EMA34;

x1_LSMA25 = 0;

x2_LSMA25 = 1;

y1_LSMA25 = 0;

y2_LSMA25 = (Ref(LSMA25, -1) - LSMA25) / Avg * range;

c_LSMA25 = sqrt((x2_LSMA25 - x1_LSMA25)*(x2_LSMA25 - x1_LSMA25) + (y2_LSMA25 - y1_LSMA25)*(y2_LSMA25 - y1_LSMA25));

angle_LSMA25 = round(180 * acos((x2_LSMA25 - x1_LSMA25)/c_LSMA25) / PI);

TitleAngleLSMA25 = EncodeColor(colorWhite) + "LSMA25 angle = ";

angle_LSMA25 = IIf(y2_LSMA25 > 0, - angle_LSMA25, angle_LSMA25);

if(SelectedValue(angle_LSMA25) >= 25)

{

TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorTurquoise);

}

else if(abs(SelectedValue(angle_LSMA25)) <= -25)

{

TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorRed);

}

else if(SelectedValue(angle_LSMA25) >= 5)

{

TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorTurquoise);

}

else if(SelectedValue(angle_LSMA25) <= -5)

{

TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorRed);

}

else

{

TitleAngleLSMA25 = TitleAngleLSMA25 + EncodeColor(colorYellow);

}

TitleAngleLSMA25 = TitleAngleLSMA25 + angle_LSMA25;

TitleTrending = WriteIf((abs(angle_EMA34) >= 15) AND (abs(angle_EMA34 +

angle_LSMA25) >= 50), EncodeColor(colorWhite) + ", SW = " +

EncodeColor(colorLime) + "TRENDING",

WriteIf((abs(angle_EMA34) >= 5) AND (((angle_EMA34 >= 0) AND

(angle_LSMA25 >= 0)) OR ((angle_EMA34 <= 0) AND (angle_LSMA25 <= 0)))

AND (abs(angle_EMA34 + angle_LSMA25) >= 30), EncodeColor(colorWhite) +

", SW = " + EncodeColor(colorYellow) + "NORMAL",

EncodeColor(colorWhite) + ", SW = " + EncodeColor(colorRed) + "FLAT"));

SW = IIf((abs(angle_EMA34) >= 15) AND (abs(angle_EMA34 + angle_LSMA25)

>= 50), IIf(angle_LSMA25 > 0, 2, -2),

IIf((abs(angle_EMA34) >= 5) AND (((angle_EMA34 >= 0) AND (angle_LSMA25

>= 0)) OR ((angle_EMA34 <= 0) AND (angle_LSMA25 <= 0))) AND

(abs(angle_EMA34 + angle_LSMA25) >= 30), IIf(angle_LSMA25 > 0, 1, -1), 0));

// Colour the bars for Woodies Trend Following

Plusbars = BarsSince(z < 0);

Minusbars = BarsSince(z > 0);

TrendBarCount = 6;

Color[0] = colorDefault;

Trend[0] = 0;

TTMColor[0] = colorDefault;

for( i = 1; i < BarCount; i++ )

{

if (C[i] > High_third[i])

{

TTMColor[i] = colorDarkGreen;

}

else if (C[i] < Low_third[i])

{

TTMColor[i] = colorDarkRed;

}

else

{

TTMColor[i] = TTMColor[i - 1];

}

if (Plusbars[i] >= TrendBarCount)

{

Trend[i] = 1;

}

else if (Minusbars[i] >= TrendBarCount)

{

Trend[i] = -1;

}

else

{

Trend[i] = Trend[i - 1];

}

if (Trend[i] == 1)

{

if (Minusbars[i] == TrendBarCount - 1)

{

Color[i] = colorYellow;

}

else if (z[i] < 0)

{

Color[i] = colorBlack;

}

else

{

Color[i] = colorLime;

}

}

else if (Trend[i] == -1)

{

if (Plusbars[i] == TrendBarCount - 1)

{

Color[i] = colorYellow;

}

else if (z[i] >= 0)

{

Color[i] = colorBlack;

}

else

{

Color[i] = colorRed;

}

}

else

{

Color[i] = colorDefault;

}

}

// CCI Line

//Plot(z,"CCI 20", colorBlack, styleLine | styleThick | styleNoLabel);

// Turbo CCI

//Plot(z6,"CCI 6", colorDarkYellow, styleLine | styleNoLabel);

// zero line 25lsma

//Plot(0,"", IIf(C > LSMA25,colorLime,IIf(C<LSMA25,colorRed,colorTeal)), styleDots | styleNoLine | styleThick | styleNoLabel);

// CCI Histogram

//Plot(z,"", Color, styleHistogram | styleThick | styleNoLabel);

// CCI 50

//Plot(CCI50_var,"CCI 50",colorPink, styleLine| styleNoLabel);

// Set up color for the 100s, green if 34ema above red if below

Color = IIf(C > EMA34, colorGreen,

IIf(C == EMA34, colorTeal, colorRed));

//Set Color for the SW

ColorSW = IIf(abs(SW) == 2, colorLime,

IIf(abs(SW) == 1, colorYellow, colorRed));

// Plot the 100s

//Plot(100,"",Color,styleDashed|styleNoLabel);

//Plot(-100,"",Color,styleDashed|styleNoLabel);

ColorANGLE_EMA = IIf(angle_EMA34 >=5, colorTurquoise,

IIf(angle_EMA34 <=-5, colorRed, colorYellow));

//ColorANGLE_EMA1 = IIf(angle_EMA34 >=25, colorTurquoise,

// IIf(angle_EMA34 <=-25, colorRed, colorBlack));

//ColorANGLE_EMA = IIf(abs(angle_EMA34) >=25, colorGreen,

// IIf(abs(angle_EMA34) >=15, colorYellow, colorRed));

//Plot(100,"", ColorANGLE_EMA , styleDashed | styleThick | styleNoLabel);

//Plot(-100,"", ColorANGLE_EMA , styleDashed | styleThick | styleNoLabel);

// Plot the 50s

//Plot(50,"", colorDarkGrey, styleDashed | styleNoLabel);

//Plot(-50,"", colorDarkGrey , styleDashed | styleNoLabel);

//Plot(50,"", TTMColor, styleDots | styleNoLine | styleNoLabel);

//Plot(-50,"", TTMColor, styleDots | styleNoLine | styleNoLabel);

// Plot the 200s

//Plot(200,"", ColorSW, styleThick | styleNoLabel);

//Plot(-200,"", ColorSW, styleThick | styleNoLabel);

// Plot the grids

//PlotGrid(0);

//PlotGrid(50);

//PlotGrid(-50);

//PlotGrid(-100);

//PlotGrid(100);

//PlotGrid(-200);

//PlotGrid(200);

// choppy

A= (HHV(z,10)<=100 AND LLV(z,10)>=-100);

B= (Ref(z,-1)>200 AND z<200) OR (Ref(z,-1)<-200 AND z>-200);

bs_a=BarsSince(A);

bs_b=BarsSince(B);

bars = IIf( bs_A < Bs_B, bs_a, 0);

// ZLR Long

uptrend_a=BarsSince(z<0);

uptrend_b=BarsSince(z>0);

Linex_long=Ref(z,-1)>100 AND z<100;

barsfromline_long=BarsSince(Linex_long);

CCIhook_long=z>Ref(z,-1) AND Ref(z,-1)>-100 AND Ref(z,-1)<Ref(z,-2) AND Ref(z,-2)>-100 AND z>0;

SW_trendinglong= sw==1 OR sw==2;

zlrlong=(Ref(angle_ema34,-2)>=5 AND Ref(angle_ema34,-1)>=5 AND angle_ema34>=5) AND  SW_trendinglong AND z<120 AND barsfromline_long<10 AND CCIhook_long AND (uptrend_a>=6 AND z>-100 OR

(uptrend_b<6 AND LLV(z,uptrend_b)>-100 AND z>-100 AND (Ref(uptrend_a,-6)>=6 AND z>-100 OR Ref(uptrend_a,-5)>=6 AND z>-100 OR Ref(uptrend_a,-4)>=6 AND z>-100 OR Ref(uptrend_a,-3)>=6 AND z>-100 OR

Ref(uptrend_a,-2)>=6 AND z>-100 OR Ref(uptrend_a,-1)>=6 AND z>-100)));

//PlotShapes(IIf(zlrlong,shapeDigit1,shapeNone),colorLime,0,0,-15);


// ZLR Short

downtrend_a=BarsSince(z>0);

downtrend_b=BarsSince(z<0);

Linex_short=Ref(z,-1)<=-100 AND z>=-100;

barsfromline_short=BarsSince(Linex_short);

CCIhook_short=z<Ref(z,-1) AND Ref(z,-1)<100 AND Ref(z,-1)>Ref(z,-2) AND Ref(z,-2)<100 AND z<0;

SW_trendingshort= sw==-1 OR sw==-2;

zlrshort= (Ref(angle_ema34,-2)<=-5 AND Ref(angle_ema34,-1)<=-5 AND angle_ema34<=-5) AND SW_trendingshort AND z>-120 AND barsfromline_short<10 AND CCIhook_short AND (downtrend_a>=6 AND z<100 OR

(downtrend_b<6 AND HHV(z,downtrend_b)<100 AND z<100 AND (Ref(downtrend_a,-6)>=6 AND z<100 OR Ref(downtrend_a,-5)>=6 AND z<100 OR Ref(downtrend_a,-4)>=6 AND z<100 OR

Ref(downtrend_a,-3)>=6 AND z<100 OR Ref(downtrend_a,-2)>=6 AND z<100 OR Ref(downtrend_a,-1)>=6 AND z<100)));

PlotShapes(IIf(zlrshort,shapeDigit1+ shapePositionAbove,shapeNone),colorRed,0,0,-15);

// MR Long

MRuptrend_a=BarsSince(z<0);

MRuptrend_b=BarsSince(z>0);

MRLinex_long=Ref(z,-1)>100 AND z<100;

MRbarsfromline_long=BarsSince(MRLinex_long);

MRCCIhook_long=z>Ref(z,-1) AND Ref(z,-1)<=Ref(z,-2) AND Ref(z,-2)<Ref(z,-3) AND z>-100 AND z<100;

MRlong= Ref(z,-1)<=0 AND MRCCIhook_long AND (MRuptrend_a>=6 AND z>-100 OR

(MRuptrend_b<6 AND LLV(z,MRuptrend_b)>-100 AND z>-100 AND (Ref(MRuptrend_a,-6)>=6 AND z>-100 OR Ref(MRuptrend_a,-5)>=6 AND z>-100 OR Ref(MRuptrend_a,-4)>=6 AND z>-100 OR Ref(MRuptrend_a,-3)>=6 AND z>-100 OR

Ref(MRuptrend_a,-2)>=6 AND z>-100 OR Ref(MRuptrend_a,-1)>=6 AND z>100)));

PlotShapes(IIf(MRlong,shapeDigit5,shapeNone),colorLime,0,0,-50);

// MR Short

MRdowntrend_a=BarsSince(z>0);

MRdowntrend_b=BarsSince(z<0);

MRLinex_short=Ref(z,-1)<=-100 AND z>=-100;

MRbarsfromline_short=BarsSince(MRLinex_short);

MRCCIhook_short=z<Ref(z,-1) AND Ref(z,-1)>=Ref(z,-2)  AND Ref(z,-2)>Ref(z,-3) AND z<100 AND z>-100;

MRshort= Ref(z,-1)>=0 AND MRCCIhook_short AND (MRdowntrend_a>=6 AND z<100 OR

(MRdowntrend_b<6 AND HHV(z,MRdowntrend_b)<100 AND z<100 AND (Ref(MRdowntrend_a,-6)>=6 AND z<100 OR Ref(MRdowntrend_a,-5)>=6 AND z<100 OR Ref(MRdowntrend_a,-4)>=6 AND z<100 OR

Ref(MRdowntrend_a,-3)>=6 AND z<100 OR Ref(MRdowntrend_a,-2)>=6 AND z<100 OR Ref(MRdowntrend_a,-1)>=6 AND z<100)));

PlotShapes(IIf(MRshort,shapeDigit5+ shapePositionAbove,shapeNone),colorRed,0,0,-50);

// Famir Short

Famir_downtrend_a=BarsSince(z<0);

Famir_downtrend_b=BarsSince(z>0);

FamirLinex_short=Ref(z,-1)>=100 AND z<100;

Famir_barsfromline_short=BarsSince(FamirLinex_short);

Famir_pivotshort= (Ref(z,-2)<Ref(z,-1)AND Ref(z,-1)<=55 AND Ref(z,-2)<=55) OR (Ref(z,-3)<Ref(z,-1)AND Ref(z,-1)<=55 AND Ref(z,-2)<=55 AND Ref(z,-3)<=55)

OR (Ref(z,-4)<Ref(z,-1) AND Ref(z,-1)<=55 AND Ref(z,-2)<=55 AND Ref(z,-3)<=55);

Famirhook_short=Famir_pivotshort AND z<Ref(LLV(z,Famir_barsfromline_short),-1) AND (z>=-55 AND z<=55) AND C<Lsma25;

Famirshort= Famir_barsfromline_short<10 AND Famirhook_short AND (Famir_downtrend_a>=6 OR

(Famir_downtrend_b<6 AND (Ref(Famir_downtrend_a,-6)>=6 OR Ref(Famir_downtrend_a,-5)>=6 OR Ref(Famir_downtrend_a,-4)>=6 OR

Ref(Famir_downtrend_a,-3)>=6 OR Ref(Famir_downtrend_a,-2)>=6 OR Ref(Famir_downtrend_a,-1)>=6))) AND C<LSMA25;

PlotShapes(IIf(famirShort,shapeDigit2+ shapePositionAbove,shapeNone),colorRed,0,0,-15);

// Famir Long

Famir_uptrend_a=BarsSince(z<0);

Famir_uptrend_b=BarsSince(z>0);

FamirLinex_long=Ref(z,-1)<=-100 AND z>-100;

Famir_barsfromline_long=BarsSince(FamirLinex_long);

Famir_pivotlong= (Ref(z,-2)>Ref(z,-1)AND Ref(z,-1)>=-55 AND Ref(z,-2)>=-55) OR (Ref(z,-3)>Ref(z,-1) AND Ref(z,-1)>=-55 AND Ref(z,-2)>=-55 AND Ref(z,-3)>=-55)

OR (Ref(z,-4)>Ref(z,-1) AND Ref(z,-1)>=-55 AND Ref(z,-2)>=-55 AND Ref(z,-3)>=-55);

Famirhook_long=Famir_pivotlong AND z>Ref(HHV(z,Famir_barsfromline_long),-1) AND (z>=-55 AND z<=55) AND C>Lsma25;

Famirlong= Famir_barsfromline_long<10 AND Famirhook_long AND (Famir_uptrend_a<6 OR

(Famir_uptrend_b>=6 AND(Ref(Famir_uptrend_a,-6)<6 OR Ref(Famir_uptrend_a,-5)<6 OR Ref(Famir_uptrend_a,-4)<6 OR Ref(Famir_uptrend_a,-3)<6 OR

Ref(Famir_uptrend_a,-3)<6 OR Ref(Famir_uptrend_a,-2)<6 OR Ref(Famir_uptrend_a,-1)<6))) AND C>LSMA25;

PlotShapes(IIf(famirlong,shapeDigit2,shapeNone),colorLime,0,0,-15);

// HFE

HFEshort=(Ref(z,-1)>200 AND z<200);

HFElong=(Ref(z,-1)<-200 AND z>-200);

HFE= (Ref(z,-1)>200 AND z<200) OR (Ref(z,-1)<-200 AND z>-200);

PlotShapes(IIf(Ref(z,-1)>200 AND z<200,shapeDownTriangle,shapeNone),IIf(Ref(z,-1)>200 AND z<200,colorYellow,shapeNone),0,200,-20);

PlotShapes(IIf(Ref(z,-1)<-200 AND z>-200,shapeUpTriangle,shapeNone),IIf(Ref(z,-1)<-200 AND z>-200,colorYellow,shapeNone),0,-200,-20);

// VT Long

vtLinex_long=Ref(z,-1)<=-200 AND z>-200;

vt_barsfromline_long=BarsSince(vtLinex_long);

vtlong_A = z<-200;

vtlong_B = Ref(z,-1)<=Ref(z,-2) OR

Ref(z,-2)<=Ref(z,-3) OR

Ref(z,-3)<=Ref(z,-4) OR

Ref(z,-4)<=Ref(z,-5) OR

Ref(z,-5)<=Ref(z,-6) OR

Ref(z,-6)<=Ref(z,-7) OR

Ref(z,-7)<=Ref(z,-8);

vtlong_bs_A = BarsSince(vtlong_A);

vtlong_bs_B = BarsSince(vtlong_b);

Vtlong_bars = vtlong_bs_A>=5 AND vtlong_bs_B<=0;

vt_pivotlong= Vtlong_bars;

swinghibars=BarsSince(z>Ref(HHV(z,vt_barsfromline_long),-1));

vthook_long= vt_pivotlong AND z>Ref(HHV(z,vt_barsfromline_long),-1);

vtlong= vt_barsfromline_long<=11 AND (Ref(HHV(z,vt_barsfromline_long),-1)<0 OR HHV(z,vt_barsfromline_long)<=0) AND vthook_long AND C>Lsma25 AND Ref(swinghibars>=2,-1) AND z>-100;

//PlotShapes(IIf(vtlong,shapeDigit3,shapeNone),colorLime,0,Min(z,0),-45);

// VT Short

vtLinex_short=Ref(z,-1)>=200 AND z<200;

vt_barsfromline_short=BarsSince(vtLinex_short);

vtshort_A = z>200 ;

vtshort_B =Ref(z,-1)>=Ref(z,-2) OR

Ref(z,-2)>=Ref(z,-3) OR

Ref(z,-3)>=Ref(z,-4) OR

Ref(z,-4)>=Ref(z,-5) OR

Ref(z,-5)>=Ref(z,-6) OR

Ref(z,-6)>=Ref(z,-7) OR

Ref(z,-7)>=Ref(z,-8);

vtshort_bs_A = BarsSince(vtshort_A);

vtshort_bs_B = BarsSince(vtshort_b);

Vtshort_bars = vtshort_bs_A>=5 AND vtshort_bs_B<=0;

vt_pivotshort= Vtshort_bars;

swinglowbars= BarsSince(z<Ref(LLV(z,vt_barsfromline_short),-1));

vthook_short= vt_pivotshort AND z<Ref(LLV(z,vt_barsfromline_short),-1);

vtshort= vt_barsfromline_short<=11 AND (Ref(LLV(z,vt_barsfromline_short),-1)>0 OR LLV(z,vt_barsfromline_short)>0) AND vthook_short AND C<Lsma25 AND Ref(swinglowbars>=2,-1) AND z<100;

//PlotShapes(IIf(vtshort,shapeDigit3+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-45);

// GB 100 Long

uptrend_a=BarsSince(z<0);

uptrend_b=BarsSince(z>0);

Linex_longGB=Ref(z,-1)>100 AND z<100;

barsfromline_longGB=BarsSince(Linex_longGB);

CCIhook_longGB= Ref(z,-1)<-100 AND z>-100;

GB100long= barsfromline_longGB<20 AND angle_EMA34>=5 AND CCIhook_longGB AND (uptrend_b<6 AND(Ref(uptrend_a,-6)>=6 OR Ref(uptrend_a,-5)>=6 OR Ref(uptrend_a,-4)>=6 OR Ref(uptrend_a,-3)>=6 OR

Ref(uptrend_a,-2)>=6 OR Ref(uptrend_a,-1)>=6));

//PlotShapes(IIf(GB100long,shapeDigit4,shapeNone),colorLime,0,0,-60);

// GB100 Short

downtrend_a=BarsSince(z>0);

downtrend_b=BarsSince(z<0);

Linex_shortGB=Ref(z,-1)<-100 AND z>-100;

barsfromline_shortGB=BarsSince(Linex_shortGB);

CCIhook_shortGB=Ref(z,-1)>100 AND z<100;

GB100short= barsfromline_shortGB<20 AND angle_EMA34<=-5 AND CCIhook_shortGB AND

(downtrend_b<6 AND (Ref(downtrend_a,-6)>=6 OR Ref(downtrend_a,-5)>=6 OR Ref(downtrend_a,-4)>=6 OR

Ref(downtrend_a,-3)>=6 OR Ref(downtrend_a,-2)>=6 OR Ref(downtrend_a,-1)>=6));

//PlotShapes(IIf(GB100short,shapeDigit4+ shapePositionAbove,shapeNone),colorRed,0,0,-60);

// Columns for exploration

Filter = (zlrlong OR famirlong OR Vtlong OR gb100long OR hfe OR mrlong OR zlrshort OR famirshort OR vtshort OR gb100short OR mrshort) AND MA(V,50)>100000; //OR ((A OR bars) AND 1)

Buy = (zlrlong OR famirlong OR Vtlong OR gb100long OR mrlong) ;// AND ((A OR bars) AND 1) ;//AND (angle_EMA34 >=15 OR angle_EMA34 <=-15);// ;

Sell= (z<Ref(z,-1) AND C<O);// OR MArketClose; ;

Short = (zlrshort OR famirshort OR Vtshort OR gb100short OR mrshort);// AND ((A OR bars) AND 1) ;//AND (angle_EMA34 <=-15 OR angle_EMA34 >=15); //;

Cover = (z>Ref(z,-1) AND C>O);// OR MArketClose;

AddColumn( IIf(zlrlong,1,IIf(zlrshort,-1,0)) ,"ZLR",1.0,colorWhite,IIf(zlrlong,colorGreen,IIf(zlrshort,colorRed,colorBlack)));

AddColumn( IIf(mrlong,1,IIf(mrShort,-1,0)) ,"MR",1.0,colorWhite,IIf(mrlong,colorGreen,IIf(mrShort,colorRed,colorBlack)));

AddColumn(IIf(famirlong,1,IIf(famirShort,-1,0)),"Famir",1.0,colorWhite,IIf(famirlong,colorGreen,IIf(famirShort,colorRed,colorBlack)));

AddColumn(IIf(vtlong,1,IIf(vtShort,-1,0)),"Vegas",1.0,colorWhite,IIf(vtlong,colorGreen,IIf(vtShort,colorRed,colorBlack)));

AddColumn(IIf(gb100long,1,IIf(gb100Short,-1,0)),"GB100",1.0,colorWhite,IIf(gb100long,colorGreen,IIf(gb100Short,colorRed,colorBlack)));

AddColumn(IIf(hfelong,1,IIf(hfeshort,-1,0)),"HFE",1.0,colorWhite,IIf(hfelong,colorGreen,IIf(hfeshort,colorRed,colorBlack)));

AddColumn(IIf(A OR bars,1,IIf(A OR bars,-1,0)),"Choppy",1.0,colorWhite,IIf(A OR bars,colorDarkYellow,IIf(A OR bars,colorDarkYellow,colorBlack)));

//Plot Sell Arrows

//Sell1=ExRem(Sell,Buy);

//Cover1=ExRem(Cover,Short);

//PlotShapes(IIf(Sell1,shapeDownArrow,shapeNone),colorLime,0,200,10);

//PlotShapes(IIf(Cover1,shapeDownArrow,shapeNone),colorRed,0,200,10);

//Signal Title

Signaltitle= WriteIf(zlrlong,EncodeColor(colorYellow) + "ZLR ",

WriteIf(zlrshort,EncodeColor(colorYellow) + "ZLR ", WriteIf(MRShort,EncodeColor(colorYellow) + "MR ",

WriteIf(MRlong,EncodeColor(colorYellow) + "MR ",

WriteIf(Famirshort,EncodeColor(colorYellow) + "FAMIR ",

WriteIf(Famirlong,EncodeColor(colorYellow) + "FAMIR ",WriteIf(HFE,EncodeColor(colorYellow) + "HFE ",WriteIf(VTlong,EncodeColor(colorYellow) + "VT ",

WriteIf(VTshort,EncodeColor(colorYellow) + "VT ",WriteIf(GB100long,EncodeColor(colorYellow) + "GB100 ",

WriteIf(Gb100short,EncodeColor(colorYellow) + "GB100 "," ")))))))))));

//Choppy Title

ChoppyTitle= WriteIf(A,EncodeColor(colorYellow) + "CHOPPY",WriteIf(bars,EncodeColor(colorYellow) + "CHOPPY",""));

//Exit Title

//Exittitle=WriteIf(Sell1,EncodeColor(colorLime) + "MLAY EXIT LONG",WriteIf(Cover1,EncodeColor(colorRed) + "MPLAY EXIT SHORT",""));

// Price Panel

Lastprice=Ref(C,-1);

Lastpricetitlehi= WriteIf(H>Ref(H,-1),EncodeColor(colorLime) + Ref(H,-1) + "  " + H , EncodeColor(colorBlack)+ Ref(H,-1) + "  " + H);

Lastpricetitlelo= WriteIf(L<Ref(L,-1),EncodeColor(colorLightOrange) + Ref(L,-1) + "  " + L , EncodeColor(colorBlack)+ Ref(L,-1) + "  " + L);

//Title

Title = "" + Name() + ", " + Interval(2) + ", " + Date() + "\n" +

EncodeColor(colorPink) + "CCI 20 = " + round(z) + " " + EncodeColor(colorDarkYellow) + "CCI 6 = " + round(z6)+ " " + EncodeColor(colorPink) + "CCI 50 = "+ round(CCI50_var) +

EncodeColor(colorWhite) + //", " + EncodeColor(colorLightOrange) +

//TitleTimeRem + EncodeColor(colorWhite) +

TitleAngleEMA34 +// EncodeColor(colorWhite) + ", " + TitleAngleLSMA25 +

TitleTrending + "\n" + Lastpricetitlehi + "\n" + EncodeColor(colorSkyblue) + C + "\n" + Lastpricetitlelo + "\n" +

EncodeColor(colorWhite)+"Signal = "+Signaltitle + ChoppyTitle; //+ EncodeColor(colorWhite) + Ctoema + Ctitle +  EncodeColor(colorWhite) + " " + angletitle + " " + "bars trending, " + "  " + " "+Exittitle;

//DennisExit

DennisExitLong= z<Ref(z,-1)AND C<O;

DennisExitShort= z>Ref(z,-1) AND C>O;

//PlotShapes(IIf(DennisExitLong,shapeSmallCircle,shapeNone),colorLime,0,200,-10);

//PlotShapes(IIf(DennisExitShort,shapeSmallCircle,shapeNone),colorRed,0,200,-10);