Tuesday, 16 September 2014

Auto Support Resistance advance trend lines for Amibroker (AFL)

Auto Support Resistance advance trend lines for Amibroker (AFL)




_SECTION_BEGIN("Advanced Trend Lines");
function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 1.5, 0.01, 100. ,0.01);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes");
Lines = Param("Lines?", 1, 1, BarCount-2);
DrawR = ParamList("Resistance Points", "Off|High to High|High to Low", 1);
DrawS = ParamList("Support Points", "Off|Low to Low|Low to High", 1);
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1);
AllOrDownR = ParamToggle("Resistance Direction", "All|Down");
AllOrUpS = ParamToggle("Support Direction", "All|Up");
ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer = Param("S/R Percentage", 3, 1);
SRBack = Param("S/R Back", 5, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
Plot(Main, "", IIf(C>O,colorGreen, colorRed), styleCandle);
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorBlue),
styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorRed,colorRed),
styleLine|styleThick);
}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorBlue),
styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorRed,colorRed),
styleLine|styleThick);
}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}

if(ShowTDP)
{
PlotShapes(TD_Supply(H)*shapeSmallCircle, colorRed, 0, H, H*.001);
PlotShapes(TD_Demand(L)*shapeSmallCircle, colorGreen, 0, L, -L*.001);
}
if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed),
styleLine|styleDashed|styleThick);
x0 = GetXResistance(H, SRPer, i);
y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed),
styleLine|styleDashed|styleThick);

}
}
Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+",Close: "+C+StrFormat(" (%.2f %.2f\%)", C-Ref(C, -1), SelectedValue(ROC(C,
1)))+str;

_SECTION_END();

buy at low sell at high for Amibroker (AFL)

buy at low sell at high for Amibroker (AFL)














_SECTION_BEGIN("FastStoch FullStochK");

pds = Param("Periods",13,2,20);


slw = Param("Slow StochK",3,1,14); ;


slwd = Param("Slow StochD",3,1,14);


ob = Param("Overbought",83,65,88);


os = Param("Oversold",24,20,50);


FSK = 100*(C-LLV(L,pds))/(HHV(H,pds)-LLV(L,pds)); // FASTSTOCHK

FLSK = MA( FSK, slw ); // FULLSTOCHK

FLSD = MA( FLSK, slwd ); // FULLSTOCHD

MaxGraph = 6;
Graph0 = FSK;
Graph0Color = ParamColor("Fast K",colorGreen);
Graph1 = FLSK;
Graph1Color = ParamColor("Full K",colorRed);
Graph2 = FLSD;
Graph2Color =  ParamColor("Full D",colorAqua);
Graph0Style = ParamStyle("FastStoch K",styleThick,maskAll);
Graph1Style = ParamStyle("FullStoch K",styleThick,maskAll);
Graph2Style = ParamStyle("FullStoch D",styleThick,maskAll);
Graph3 = FLSD;
Graph3BarColor =
IIf (Graph3 > ob, colorRed,
IIf (Graph3 < os, colorBrightGreen, colorGrey40));
Graph4 = ob;
Graph4Color = 4;
Graph5 = os;
Graph5Color = colorBrightGreen;
Graph3Style =ParamStyle("BAR 1",styleHistogram | styleThick,maskHistogram );
Graph4Style = Graph5Style =1;// ParamStyle("style");

Title = Name()+" - "+FullName()+
EncodeColor(Graph0Color)+"   FastStochK="+
StrFormat("%1.4g ",fsk)+EncodeColor(Graph1Color)+
"  FullStochK="+StrFormat("%1.4g ",flsk)+
EncodeColor(Graph2Color)+"  FullStochD="+
StrFormat("%1.4g ",flsd);

whengoup = FLSD < os AND Cross(FSK,os) AND FLSK >= Ref(FLSK,-1) AND FLSD >= Ref(FLSD,-1) OR  Cross(FLSD,os) AND //...next line
FSK >= Ref(FSK,-1) AND FLSK >= Ref(FLSK,-1) ;

whengodown = IIf(BarsSince(Cross(os,FSK))==1 AND FLSK < os ,1,0) OR Cross(os,FSK) AND FLSK < Ref(FLSK,-1) OR FLSK < ob //...next line
AND FLSK > os AND FLSK <= Ref(FLSK,-1) OR FSK > ob AND FLSK > ob AND FLSD > ob AND FSK < Ref(FSK,-1) AND FLSK < Ref(FLSK,-1) //...next line
AND FLSD <= Ref(FLSD,-1) OR FSK > ob AND FLSK > ob AND FLSD > ob AND Cross(ob,FLSK);

Buy = whengoup;
Sell = whengodown;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
_SECTION_END();_SECTION_BEGIN("Stochastic");

periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
myStochD=StochD( periods , Ksmooth, DSmooth );
myStochK=StochK( periods , Ksmooth);
Overbought=80;
Oversold=20;

Buy = Cross(myStochK, myStochD );
Sell = Cross( myStochD, myStochK );

Plot( myStochD, "Stochastic %D"+_PARAM_VALUES(), ParamColor( "ColorD", colorRed ), ParamStyle("StyleD") );
Plot( myStochK, "Stochastic %K", ParamColor( "ColorK", colorGreen ), ParamStyle("StyleK") );

PlotShapes(IIf(Sell, shapeHollowDownArrow , shapeNone), colorRed);
PlotShapes(IIf(Buy, shapeHollowUpArrow , shapeNone), colorBlue);

Plot(Overbought,"Overbought Level",colorRed);
Plot(Oversold,"Oversold Level",colorGreen);


PlotOHLC( myStochK,myStochK,50,myStochK, "", colorRed, styleCloud | styleClipMinMax, 20, 80 );
PlotOHLC( myStochD,myStochD,50,myStochD, "", colorYellow, styleCloud | styleClipMinMax, 20, 80 );

PlotOHLC( Null,myStochD,myStochK,Null, "", colorBlue, styleCloud);


_SECTION_END();

Auto Plot HH HL LL for Amibroker (AFL)





Auto Plot HH HL LL for Amibroker (AFL)



Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
    if ( HH[i] )
        PlotText( "HH", i, H[ i ] + dist[i], colorYellow );

    if ( LH[i] )
        PlotText( "LH", i, H[ i ] + dist[i], colorYellow );

    if ( HL[i] )
        PlotText( "HL", i, L[ i ] - dist[i], colorPink );

    if ( LL[i] )
        PlotText( "LL", i, L[ i ] - dist[i], colorPink );

}
_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),

ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorDarkTeal )); 
_SECTION_END();


_SECTION_BEGIN("The_Beast_2");
SetBarsRequired(10000,10000); 
Prd1=Param("ATR Period 1-20",4,1,20,1);
Prd2=Param("LookBack Period 1-20",7,1,20,1);
Green=HHV(LLV(L,Prd1)+ATR(Prd1),Prd2); 

RED=LLV(HHV(H,Prd1)-ATR(Prd1),Prd2); 


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 ) ); 
Color = IIf(C>Green ,colorBrightGreen,IIf(C < RED,colorRed,colorWhite)); 

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", color, styleCandle,styleThick );

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{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 )) ));


_SECTION_END();

_SECTION_BEGIN("Trailing_Stop_Short");
stoplossPercentage = Param("Stoploss Percentage", 5, 2, 10);
lookbackPeriod = Param("Lookback period", 10, 5, 30);
Plot(HHV(C,lookbackPeriod) - HHV(C,lookbackPeriod) * (stoplossPercentage / 100), "Trailing stoploss", ParamColor( "Color", colorCycle ),ParamStyle("Style",styleLine|Stylehidden ,maskAll));
_SECTION_END();

_SECTION_BEGIN("Trailing_Stop_Long");

mf = Param("ATR multiplier",3,1,3,0.25); 
ap=Param("ATR Period",10,5,30,1);
Lb=Param("Lookback Period",20,10,40,1);
ps=ParamToggle("Use last low pivot","Use,Dont",1);


t1=HHV(C,Lb);
t2=(mf*ATR(ap)); 
t3=Trough(C,2,1);
t4=t1-t2;
t5=Min(t4,t3);

if(ps)
{
t6 = t1-t2;
}
else
{
t6=t5;
}

initial=t6; 
stop[ 0 ] = Close[ 0 ]; 

for( i = 1 ; i < BarCount; i++) 
if( Close[ i ] > stop[ i - 1]) 
temp = t6[ i ]; 
if( temp > stop[ i - 1 ] ) stop[ i ] = temp; 
else stop[ i ] = stop[ i - 1 ]; 
else 
stop[ i ] = initial[ i ]; 


Plot(stop,"ATR Stop",ParamColor( "Color", colorSeaGreen ),ParamStyle("Style",styleLine|Stylehidden,maskAll));











_SECTION_BEGIN("Pivot_Finder");



farback=Param("How Far back to go",100,0,5000,10);
nBars = Param("Number of bars", 12, 5, 40);


GraphXSpace=7;



aHPivs = H - H;

aLPivs = L - L;


aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;



aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);



aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);



curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}



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

curBar = (BarCount - 1) - i;



if (aLLVBars[curBar] < aHHVBars[curBar]) {



if (curTrend == "U") {

curTrend = "D";



curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}



} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}



}



}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aLPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nLPivs; j++) {

aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];

aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];

}

aLPivLows[0] = candPrc;

aLPivIdxs[0] = candIdx;

nLPivs++;

}

}

// -- Dump inventory of high pivots for debugging



for (k=0; k<nHPivs; k++) {

_TRACE("High pivot no. " + k

+ " at barindex: " + aHPivIdxs[k] + ", "

+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}



// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeSmallSquare, shapeNone), colorCustom12, 0, H, 25);

PlotShapes(

IIf(aLPivs==1, shapeSmallSquare , shapeNone), colorOrange, 0, L, -20);

_SECTION_BEGIN("Graphics");
GrpPrm=Param("Graphic Space",1,0,10);
GraphXSpace=GrpPrm;
_SECTION_END();

_SECTION_BEGIN("Analysis");
M1=EMA(((2*EMA(C,29/2))-EMA(C,29)),2);
M2=EMA(((2*EMA(C,29/2))-EMA(C,29)),5);
Buy     = Cross(M1, M2) ;
Sell    = Cross(M2, M1) ;

Buy     = ExRem(Buy, Sell);
Sell    = ExRem(Sell, Buy);
mycolor = IIf(M1 > M2, colorLime, colorRed);
shape   = Buy * shapeUpArrow + Sell * shapeDownArrow ;


PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
dist = 1.5*ATR(20);
for( i = 0; i < BarCount; i++ ) {
       if( Buy[i] ) PlotText( "Buy\n@" + Close[i], i, Low[i] - dist[i], colorGreen );
       if( Sell[i] ) PlotText( "sell\n@" + Close[i], i, Low[i] + dist[i], colorRed );
}

Plot( Close, "Close", mycolor, styleNoTitle );
_SECTION_END();

The Beast With Auto Buy Signal for Amibroker (AFL)


The Beast With Auto Buy Signal for Amibroker (AFL)





_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),

ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorDarkTeal ));
_SECTION_END();


_SECTION_BEGIN("The_Beast_2");
SetBarsRequired(10000,10000);
Prd1=Param("ATR Period 1-20",4,1,20,1);
Prd2=Param("LookBack Period 1-20",7,1,20,1);
Green=HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);

RED=LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);


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 ) );
Color = IIf(C>Green ,colorBrightGreen,IIf(C < RED,colorRed,colorWhite));

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", color, styleCandle,styleThick );

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{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 )) ));


_SECTION_END();

_SECTION_BEGIN("Trailing_Stop_Short");
stoplossPercentage = Param("Stoploss Percentage", 5, 2, 10);
lookbackPeriod = Param("Lookback period", 10, 5, 30);
Plot(HHV(C,lookbackPeriod) - HHV(C,lookbackPeriod) * (stoplossPercentage / 100), "Trailing stoploss", ParamColor( "Color", colorCycle ),ParamStyle("Style",styleLine|Stylehidden ,maskAll));
_SECTION_END();

_SECTION_BEGIN("Trailing_Stop_Long");

mf = Param("ATR multiplier",3,1,3,0.25);
ap=Param("ATR Period",10,5,30,1);
Lb=Param("Lookback Period",20,10,40,1);
ps=ParamToggle("Use last low pivot","Use,Dont",1);


t1=HHV(C,Lb);
t2=(mf*ATR(ap));
t3=Trough(C,2,1);
t4=t1-t2;
t5=Min(t4,t3);

if(ps)
{
t6 = t1-t2;
}
else
{
t6=t5;
}

initial=t6;
stop[ 0 ] = Close[ 0 ];

for( i = 1 ; i < BarCount; i++)
{
if( Close[ i ] > stop[ i - 1])
{
temp = t6[ i ];
if( temp > stop[ i - 1 ] ) stop[ i ] = temp;
else stop[ i ] = stop[ i - 1 ];
}
else
stop[ i ] = initial[ i ];

}

Plot(stop,"ATR Stop",ParamColor( "Color", colorSeaGreen ),ParamStyle("Style",styleLine|Stylehidden,maskAll));

_SECTION_END();

_SECTION_BEGIN("Trailing_Lines");
Plot(LLV(HHV(H,5)-ATR(5),8),"",ParamColor( "Color Line 0", colorDarkGreen ),ParamStyle("Style Line 0",styleLine,maskAll));
Plot(LLV(HHV(H,5)-ATR(5),7),"",ParamColor( "Color Line 1", colorDarkGrey),ParamStyle("styleLine 1",styleLine,maskAll));
Plot(LLV(HHV(H,5)-ATR(5),6),"",ParamColor( "Color Line 2", colorDarkGrey ),ParamStyle("Style Line 2",styleLine,maskAll));
Plot(LLV(HHV(H,5)-ATR(5),5),"",ParamColor( "Color Line 3", colorDarkGrey),ParamStyle("Style Line 3",styleLine,maskAll));
Plot(LLV(HHV(H,5)-ATR(5),4),"",ParamColor( "Color Line 4", colorDarkGrey ),ParamStyle("Style Line 4",styleLine,maskAll));
Plot(LLV(HHV(H,5)-ATR(5),3),"",ParamColor( "Color Line 5", colorDarkYellow ),ParamStyle("Style Line 5",styleLine,maskAll));

_SECTION_END();









_SECTION_BEGIN("Pivot_Finder");



farback=Param("How Far back to go",100,0,5000,10);
nBars = Param("Number of bars", 12, 5, 40);


GraphXSpace=7;



aHPivs = H - H;

aLPivs = L - L;


aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;



aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);



aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);



curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}



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

curBar = (BarCount - 1) - i;



if (aLLVBars[curBar] < aHHVBars[curBar]) {



if (curTrend == "U") {

curTrend = "D";



curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}



} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}



}



}



curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nHPivs; j++) {

aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-

(j+1)];

aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];

}

aHPivHighs[0] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aLPivs[candIdx] = 1;

// ...and then rearrange elements in the

// pivot information arrays

for (j=0; j<nLPivs; j++) {

aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];

aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];

}

aLPivLows[0] = candPrc;

aLPivIdxs[0] = candIdx;

nLPivs++;

}

}

// -- Dump inventory of high pivots for debugging



for (k=0; k<nHPivs; k++) {

_TRACE("High pivot no. " + k

+ " at barindex: " + aHPivIdxs[k] + ", "

+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}



// -- OK, let's plot the pivots using arrows

PlotShapes(

IIf(aHPivs==1, shapeSmallSquare, shapeNone), colorCustom12, 0, H, 25);

PlotShapes(

IIf(aLPivs==1, shapeSmallSquare , shapeNone), colorOrange, 0, L, -20);

_SECTION_BEGIN("Graphics");
GrpPrm=Param("Graphic Space",1,0,10);
GraphXSpace=GrpPrm;
_SECTION_END();

_SECTION_BEGIN("Analysis");
M1=EMA(((2*EMA(C,29/2))-EMA(C,29)),2);
M2=EMA(((2*EMA(C,29/2))-EMA(C,29)),5);
Buy     = Cross(M1, M2) ;
Sell    = Cross(M2, M1) ;

Buy     = ExRem(Buy, Sell);
Sell    = ExRem(Sell, Buy);
mycolor = IIf(M1 > M2, colorLime, colorRed);
shape   = Buy * shapeUpArrow + Sell * shapeDownArrow ;


PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
dist = 1.5*ATR(20);
for( i = 0; i < BarCount; i++ ) {
       if( Buy[i] ) PlotText( "Buy\n@" + Close[i], i, Low[i] - dist[i], colorGreen );
       if( Sell[i] ) PlotText( "sell\n@" + Close[i], i, Low[i] + dist[i], colorRed );
}

Plot( Close, "Close", mycolor, styleNoTitle );
_SECTION_END();

Monday, 15 September 2014

All in one has Patterns Wave, MACD, Candle Details, Guppy Movement, Support-Resistance, BB, Pivot indicator. One can easily determine the trend

All in one has Patterns Wave, MACD, Candle Details, Guppy Movement, Support-Resistance, BB, Pivot indicator.
One can easily determine the trend

Here is a screenshot of how the indicator looks:






_SECTION_BEGIN("Patterns Wave");
Change = Param("Wave Period",6,0,100,1);
WaveLineColor = ParamColor("Wave Color", colorWhite );
procedure PlotShapeAt( x, y, shape, shift )
{
PlotShapes( IIf( BarIndex() == x, shape, 0 ), WaveLineColor, 0, y, shift );
}
WavePattern=ParamToggle("Wave","No|Yes",0);
if(WavePattern)
{
bi = BarIndex();
sbi = SelectedValue( bi );
GraphXSpace = 2;
Plot( Zig( C, Change ), "", WaveLineColor, ParamStyle("Wave Style", styleThick|styleNoLabel|styleNoTitle) );
upshift = 15;
if( SelectedValue( PeakBars( C, Change ) < TroughBars( C, Change ) ) )
{
pt1 = PeakBars( C, Change, 1 ) == 0 ;
pt2 = TroughBars( C, Change, 1 ) == 0 ;
}
else
{
pt1 = TroughBars( C, Change, 1 ) == 0 ;
pt2 = PeakBars( C, Change, 1 ) == 0 ;
upshift = -upshift;
}
bpt1 = SelectedValue( ValueWhen( pt1, bi ) );
bpt2 = SelectedValue( ValueWhen( pt2, bi ) );
bpt3 = SelectedValue( ValueWhen( pt1, bi, 2 ) );
bpt4 = SelectedValue( ValueWhen( pt2, bi, 2 ) );
bpt5 = SelectedValue( ValueWhen( pt1, bi, 3 ) );
bpt6 = SelectedValue( ValueWhen( pt2, bi, 3 ) );
PlotShapeAt( bpt1, C, shapeDigit5, upshift );
PlotShapeAt( bpt2, C, shapeDigit4, -upshift );
PlotShapeAt( bpt3, C, shapeDigit3, upshift );
PlotShapeAt( bpt4, C, shapeDigit2, -upshift );
PlotShapeAt( bpt5, C, shapeDigit1, upshift );
}
_SECTION_END();

_SECTION_BEGIN("MACD Fill");

PeriodEMA = 13;
MACDIndicatorRange = 50;

VolumeFilter = Param( "Volume MA filter", 100000, 50000, 500000, 100000 );
Timeframe = Interval(2);

if( Timeframe == "5-day" || Timeframe == "Weekly" ) {
VolumeFilter = VolumeFilter * 5;
}
else if( Timeframe == "Monthly") {
VolumeFilter = VolumeFilter * 20;
}
else if( Timeframe != "Daily" ) {
VolumeFilter = 0;
}

MACDDivMinWidth = Param("Divergence min width", 4, 1, 10, 1 );

HistMinWidth = Param("Histogram min width", 4, 1, 10, 1 );
PeriodEMA = Optimize( "PeriodEMA ", 13, 5, 23, 1 );

OpenPositions = 10;
ATRPeriod = 5;
InitialCapital = 100000;
PeriodFast = Param( "Fast EMA", 8, 2, 200, 1 );
PeriodSlow = Param( "Slow EMA", 17, 2, 200, 1 );
PeriodSignal = Param( "Signal EMA", 9, 2, 200, 1 );
MACDInd = MACD(PeriodFast, PeriodSlow );
SigInd = Signal(PeriodFast, PeriodSlow , PeriodSignal );
HistInd = MACDInd - SigInd ;
_N( macdStr = WriteVal( PeriodFast, 1.0 )+","+WriteVal( PeriodSlow , 1.0 ) );
_N( sigStr = macdStr + ","+WriteVal( PeriodSignal , 1.0 ) );

// Get displayed min and max value of MACD and MACD-H, to rescale it for better visibility
scMACDMax = LastValue(HHV(Max(MACDInd, sigInd),
BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) )));
scMACDMin = LastValue(LLV(Min(MACDInd, sigInd),
BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) )));
scaleMACD = Max( abs(scMACDMax), abs(scMACDMin) );
scHistMax = LastValue(HHV(HistInd,
BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) )));
scHistMin = LastValue(LLV(HistInd,
BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) )));
scaleHist = Max( abs(scHistMax), abs(scHistMin) );
_SECTION_END();


_SECTION_BEGIN("Candle Detail");
Candletype=ParamList("Candle Type","Candle|Haikin",1);
UpCandle = ParamColor("Up Color", colorBrightGreen );
DownCandle = ParamColor("Down Color", colorRed );
Consolidation = ParamColor("Consolidation", colorWhite );

MACDColorUp = ParamColor("MACD Up", colorDarkGreen );
MACDColorDown = ParamColor("MACD Down", colorDarkRed );
Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",8,1,20,1);


if(Candletype=="Candle")
{
CandleColor = IIf(O > C, DownCandle, UpCandle);
Plot( Close, "Price", CandleColor, styleCandle );
}
else if(Candletype=="Haikin")
{
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.3 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.3 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

BrightGreen=HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
BrightRed=LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

xDiff = (HaHigh - Halow) * IIf(StrFind(Name(),"JPY"),100,10000);
barcolor = IIf(C>BrightGreen ,UpCandle,IIf(C < BrightRed,DownCandle,Consolidation));

SetBarFillColor( IIf(MACDInd >SigInd, MACDColorUp,MACDColorDown) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
}
_SECTION_END();

_SECTION_BEGIN("Guppy");
Guppy=ParamToggle("Guyyp","No|Yes",0);
if(Guppy)
{
Plot( EMA( C, 30 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
Plot( EMA( C, 35 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
Plot( EMA( C, 40 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
Plot( EMA( C, 45 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
Plot( EMA( C, 50 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
Plot( EMA( C, 55 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
Plot( EMA( C, 60 ),"", ParamColor( "Color", colorYellow ), ParamStyle("Chart Style", styleLine|styleNoLabel) );
}
_SECTION_END();

_SECTION_BEGIN("Support-Resistance");
SupRes=ParamToggle("Sup-Res","No|Yes",1);
SupResA = Param("Sup-Res A Period",20,0,100,1);
SupResB = Param("Sup-Res B Period",25,0,100,1);

Res1 = ParamColor("Resistance High", colorRed );
Res2 = ParamColor("Resistance Low", colorDarkRed );
Sup1 = ParamColor("Support High", colorDarkGreen );
Sup2 = ParamColor("Support Low", colorBrightGreen );
if(SupRes)
{
MaxGraph = 12;
BuyOffSet = SupResA;//Optimize("BuyOffSet",18,15,20,1);
SellOffset = BuyOffSet;//Optimize("SellOffset",2,2,14,2);
RegLength = 5;//Optimize("RegLength",5, 2,11,2);
BuyATRPeriod = 2;//Optimize("BuyATRPeriod",2,2,5,1);
SellATRPeriod = BuyATRPeriod;//Optimize("SellATRPeriod",4,2,11,2);
ATRMultiplier = 0.5;//Optimize("ATRMultiplier",1,0.7,1.25,.05);
SuppA = HHV(H-ATRMultiplier*ATR(BuyATRPeriod),BuyOffset); /* RED */
RessB = LLV(L+ATRMultiplier*ATR(SellATRPeriod),SellOffset); /* GREEN */
Plot(SuppA,"",sup1,ParamStyle("Sup-Res A Style", styleDashed|styleNoTitle) );
Plot(RessB,"",res2,ParamStyle("Sup-Res A Style", styleDashed|styleNoTitle) );

nn=SupResB;
mmm=100;
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);
Plot(Hh,"",Res1, ParamStyle("Sup-Res B Style", styleThick|styleNoTitle) );
Plot(Ll,"",Sup2, ParamStyle("Sup-Res B Style", styleThick|styleNoTitle) ) ;
}
_SECTION_END();

_SECTION_BEGIN("BB");
BBand=ParamToggle("B.Band","No|Yes",0);
if(BBand)
{
pr1=Param( "Period1",20,0,100,1);
pr2=Param( "Period2",2,0,100,1);
BBColor = ParamColor( "Band Color", colorGrey50 );
Cloud = ParamColor( "Cloud", colorDarkGrey );
Style = styleNoRescale | styleNoLabel |styleDashed;
BBT=BBandTop(C,pr1,pr2);
BBB=BBandBot(C,pr1,pr2);
topcond = (Cross(BBT,C)OR C>BBT)AND Ref(C, -1)> BBT;
botcond = ( Cross(C,BBB))AND Ref(C, -1 < BBB);
Plot( BBT, "BBTop" + _PARAM_VALUES(), BBColor, ParamStyle("BBand Style", styleLine|styleNoLabel|styleNoTitle) );
Plot( BBB, "BBBot" + _PARAM_VALUES(), BBColor, ParamStyle("BBand Style", styleLine|styleNoLabel|styleNoTitle) );
PlotOHLC( BBT,BBT,BBB,BBB, "", Cloud,styleCloud|styleNoLabel );
}
_SECTION_END();

_SECTION_BEGIN("Pivot");
nBars = Param("Number of bars", 12, 5, 40);
bShowTCZ = Param("Show TCZ", 1, 0, 1);
nExploreBarIdx = 0;
nExploreDate = 0;
nCurDateNum = 0;
DN = DateNum();
DT = DateTime();
bTCZLong = False;
bTCZShort = False;
nAnchorPivIdx = 0;
ADX8 = ADX(8);
if(Status("action")==1) {
bDraw = True;
bUseLastVis = 1;
} else {
bDraw = False;
bUseLastVis = False;
bTrace = 1;
nExploreDate = Status("rangetodate");
for (i=LastValue(BarIndex());i>=0;i--) {
nCurDateNum = DN[i];
if (nCurDateNum == nExploreDate) {
nExploreBarIdx = i;
}
}
}
GraphXSpace=7;
if (bDraw) {
}
aHPivs = H - H;
aLPivs = L - L;
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
aAddedHPivs = H - H;
aAddedLPivs = L - L;
aLegVol = H - H;
aRetrcVol = H - H;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
nLastVisBar = LastValue(
Highest(IIf(Status("barvisible"), BarIndex(), 0)));
curBar = IIf(nlastVisBar > 0 AND bUseLastVis, nlastVisBar,
IIf(Status("action")==4 AND nExploreBarIdx > 0, nExploreBarIdx,
LastValue(BarIndex())));
curTrend = "";
if (aLLVBars[curBar] < aHHVBars[curBar])
curTrend = "D";
else
curTrend = "U";
if (curBar >= 120) {
for (i=0; i<120; i++) {
curBar = IIf(nlastVisBar > 0 AND bUseLastVis,
nlastVisBar-i,
IIf(Status("action")==4 AND nExploreBarIdx > 0,
nExploreBarIdx-i,
LastValue(BarIndex())-i));
if (aLLVBars[curBar] < aHHVBars[curBar]) {
if (curTrend == "U") {
curTrend = "D";
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
}
}
}
curBar =
IIf(nlastVisBar > 0 AND bUseLastVis,
nlastVisBar,
IIf(Status("action")==4 AND nExploreBarIdx > 0,
nExploreBarIdx,
LastValue(BarIndex()))
);
if (nHPivs >= 2 AND nLPivs >= 2) {
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
nLastHOrLPivIdx = Max(lastLPIdx, lastHPIdx);
nAddPivsRng = curBar - nLastHOrLPivIdx;
aLLVAfterLastPiv = LLV(L, nAddPivsRng);
nLLVAfterLastPiv = aLLVAfterLastPiv[curBar];
aLLVIdxAfterLastPiv = LLVBars(L, nAddPivsRng);
nLLVIdxAfterLastPiv = curBar - aLLVIdxAfterLastPiv[curBar];
aHHVAfterLastPiv = HHV(H, nAddPivsRng);
nHHVAfterLastPiv = aHHVAfterLastPiv[curBar];
aHHVIdxAfterLastPiv = HHVBars(H, nAddPivsRng);
nHHVIdxAfterLastPiv = curBar - aHHVIdxAfterLastPiv[curBar];
if (lastHPIdx > lastLPIdx) {


if (aHPivHighs[0] < aHPivHighs[1]) {

if (nLLVAfterLastPiv < aLPivLows[0] AND
(nLLVIdxAfterLastPiv - lastHPIdx - 1) >= 1
AND nLLVIdxAfterLastPiv != curBar ) {


aLPivs[nLLVIdxAfterLastPiv] = 1;
aAddedLPivs[nLLVIdxAfterLastPiv] = 1;


for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = nLLVAfterLastPiv;
aLPivIdxs[0] = nLLVIdxAfterLastPiv;
nLPivs++;


}


} else {

if (nLLVAfterLastPiv > aLPivLows[0] AND
(nLLVIdxAfterLastPiv - lastHPIdx - 1) >= 1
AND nLLVIdxAfterLastPiv != curBar ) {


aLPivs[nLLVIdxAfterLastPiv] = 1;
aAddedLPivs[nLLVIdxAfterLastPiv] = 1;


for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = nLLVAfterLastPiv;
aLPivIdxs[0] = nLLVIdxAfterLastPiv;
nLPivs++;


}

}


} else {

if (aHPivHighs[0] < aHPivHighs[1]) {

if (nHHVAfterLastPiv < aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= 1
AND nHHVIdxAfterLastPiv != curBar ) {


aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 1;


for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nhPivs-(j+1)];
}
aHPivHighs[0] = nHHVAfterLastPiv;
aHPivIdxs[0] = nHHVIdxAfterLastPiv;
nHPivs++;


}


} else {


if (nHHVAfterLastPiv > aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= 1
AND nHHVIdxAfterLastPiv != curBar ) {


aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 1;


for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nhPivs-(j+1)];
}
aHPivHighs[0] = nHHVAfterLastPiv;
aHPivIdxs[0] = nHHVIdxAfterLastPiv;
nHPivs++;


}

}

}


}



if (bDraw) {
PivotEntry = ParamColor( "Entry Color", colorBrightGreen );
PivotEntry2 = ParamColor( "Entry Color2", colorYellow );
PivotExit = ParamColor( "Exit Color", colorRed );
PivotExit2 = ParamColor( "Exit Color2", colorYellow );

PlotShapes(
IIf(aHPivs==1, shapeSquare, shapeNone),
PivotExit, 0, High, Offset=30);
PlotShapes(
IIf(aAddedHPivs==1, shapeSquare, shapeNone),
PivotExit2, 0, High, Offset=30);
PlotShapes(
IIf(aLPivs==1, shapeSquare , shapeNone),
PivotEntry, 0, Low, Offset=-30);
PlotShapes(
IIf(aAddedLPivs==1, shapeSquare , shapeNone),
PivotEntry2, 0, Low, Offset=-30);

PlotShapes(
IIf(aHPivs==1, shapeSquare, shapeNone),
colorBlack, 0, High, Offset=35);
PlotShapes(
IIf(aAddedHPivs==1, shapeSquare, shapeNone),
colorBlack, 0, High, Offset=35);
PlotShapes(
IIf(aLPivs==1, shapeSquare , shapeNone),
colorBlack, 0, Low, Offset=-35);
PlotShapes(
IIf(aAddedLPivs==1, shapeSquare , shapeNone),
colorBlack, 0, Low, Offset=-35);
}


risk = 0;
profInc = 0;
nLeg0Pts = 0;
nLeg0Bars = 0;
nLeg0Vol = 0;
nLeg1Pts = 0;
nLeg1Bars = 0;
nLeg1Vol = 0;
nLegBarsDiff = 0;
nRtrc0Pts = 0;
nRtrc0Bars = 0;
nRtrc0Vol = 0;
nRtrc1Pts = 0;
nRtrc1Bars = 0;
nRtrc1Vol = 0;

minRtrc = 0;
maxRtrc = 0;
minLine = 0;
maxLine = 0;
triggerLine = 0;
firstProfitLine = 0;
triggerInc = 0;
triggerPrc = 0;
firstProfitPrc = 0;
retrcPrc = 0;
retrcBar = 0;
retrcBarIdx = 0;
retrcRng = 0;
aRetrcPrc = H-H;
aRetrcPrcBars = H-H;
aRetrcClose = C;
retrcClose = 0;


if (nHPivs >= 2 AND
nLPivs >=2 AND
aHPivHighs[0] > aHPivHighs[1] AND
aLPivLows[0] > aLPivLows[1]) {

tcz500 =
(aHPivHighs[0] -
(.5 * (aHPivHighs[0] - aLPivLows[1])));

tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[0] - aLPivLows[1])));

tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));

retrcRng = curBar - aHPivIdxs[0];
aRetrcPrc = LLV(L, retrcRng);
aRetrcPrcBars = LLVBars(L, retrcRng);

retrcPrc = aRetrcPrc[curBar];
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];

// -- bTCZLong setup?
bTCZLong = (

// -- Are retracement levels arranged in
// tcz order?

// .500 is above .786 for long setups
tcz500 >= (tcz786 * (1 - .005))
AND
// .681 is below .786 for long setups
tcz618 <= (tcz786 * (1 + .005))
AND

// -- Is the low in the tcz range
// -- Is the close >= low of tcz range
// and low <= high of tcz range
retrcClose >= ((1 - .01) * tcz618)
AND
retrcPrc <= ((1 + .01) * tcz500)
);

// -- risk would be high of signal bar minus low of zone
//risk = 0;

// -- lower highs and lower lows
} else if (nHPivs >= 2 AND nLPivs >=2
AND aHPivHighs[0] < aHPivHighs[1]
AND aLPivLows[0] < aLPivLows[1]) {

tcz500 =
(aHPivHighs[1] -
(.5 * (aHPivHighs[1] - aLPivLows[0])));

tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[1] - aLPivLows[0])));

tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));

retrcRng = curBar - aLPivIdxs[0];
aRetrcPrc = HHV(H, retrcRng);
retrcPrc = aRetrcPrc[curBar];
aRetrcPrcBars = HHVBars(H, retrcRng);
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];

bTCZShort = (
// -- Are retracement levels arranged in
// tcz order?

// .500 is below .786 for short setups
tcz500 <= (tcz786 * (1 + .005))
AND
// .681 is above .786 for short setups
tcz618 >= (tcz786 * (1 - .005))
AND

// -- Is the close <= high of tcz range
// and high >= low of tcz range
retrcClose <= ((1 + .01) * tcz618)
AND
retrcPrc >= ((1 - .01) * tcz500)
);

// -- Risk would be top of zone - low of signal bar
//risk = 0;
}

// -- Show zone if present
if (bTCZShort OR bTCZLong) {

// -- Be prepared to see symmetry
if (bTCZShort) {
if (aLPivIdxs[0] > aHPivIdxs[0]) {
// -- Valuable, useful symmetry information
nRtrc0Pts = aHPivHighs[0] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[0] - aLPivIdxs[1] + 1;
nRtrc1Pts = retrcPrc - aLPivLows[0];
nRtrc1Bars = retrcBarIdx - aLPivIdxs[0] + 1;
} else {
nRtrc0Pts = aHPivHighs[1] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[1] - aLPivIdxs[1] + 1;
nRtrc1Pts = aHPivHighs[0] - aLPivLows[0];
nRtrc1Bars = aHPivIdxs[0] - aLPivIdxs[0] + 1;
}
} else { // bLongSetup
if (aLPivIdxs[0] > aHPivIdxs[0]) {
nRtrc0Pts = aHPivHighs[0] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[0] - aLPivIdxs[1] + 1;
nRtrc1Pts = retrcPrc - aLPivLows[0];
nRtrc1Bars = retrcBarIdx - aLPivIdxs[0] + 1;
} else {
nRtrc0Pts = aHPivHighs[1] - aLPivLows[0];
nRtrc0Bars = aLPivIdxs[0] - aHPivIdxs[1] + 1;
nRtrc1Pts = aHPivHighs[0] - aLPivLows[0];
nRtrc1Bars = aLPivIdxs[0] - aHPivIdxs[0] + 1;
}
}

if (bShowTCZ) {
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz500, curBar, tcz500 , 0),
"tcz500", colorPaleBlue, styleLine|styleNoTitle|Stylehidden);
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz618, curBar, tcz618, 0),
"tcz618", colorPaleBlue, styleLine|styleNoTitle|styleHidden);
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz786, curBar, tcz786, 0),
"tcz786", colorTurquoise, styleLine|styleNoTitle|StyleHidden);
}

// -- if (bShowTCZ)
}

if (bDraw) {
Title = Name() + " (" + StrLeft(FullName(), 10) +
") ATR: " + NumToStr(ATR(1), 4.2) + " ( " +
NumToStr((C - Ref(C, -1)), 4.2) + " / " +
NumToStr((((C - Ref(C, -1)) / Ref(C, -1)) * 100), 2.1) + "% ) " +
WriteVal( SelectedValue( DateTime() ), formatDateTime) +

// "Risk: " + WriteVal(risk, 2.1) + "% \n" +

WriteVal(nRtrc1Pts, 2.1) + " \n" +

WriteVal(nRtrc1Bars, 2.0);
}

// **************************
// END INDICATOR CODE
// **************************
_SECTION_END();

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

_SECTION_BEGIN("Beta Adjusted Trailing Stops by Southwind");
//Concept from Bulkowski’s Stop Placement


dif=Ref(High,0)-Ref(Low,0);
dif1=Ref(High,-1)-Ref(Low,-1);
dif2=Ref(High,-2)-Ref(Low,-2);
dif3=Ref(High,-3)-Ref(Low,-3);
dif4=Ref(High,-4)-Ref(Low,-4);
dif5=Ref(High,-5)-Ref(Low,-5);
dif6=Ref(High,-6)-Ref(Low,-6);
dif7=Ref(High,-7)-Ref(Low,-7);
dif8=Ref(High,-8)-Ref(Low,-8);
dif9=Ref(High,-9)-Ref(Low,-9);
dif10=Ref(High,-10)-Ref(Low,-10);
dif11=Ref(High,-11)-Ref(Low,-11);
dif12=Ref(High,-12)-Ref(Low,-12);
dif13=Ref(High,-13)-Ref(Low,-13);
dif14=Ref(High,-14)-Ref(Low,-14);
dif15=Ref(High,-15)-Ref(Low,-15);

Sumdif=(dif+dif1+dif2+dif3+dif4+dif5+dif6+dif7+dif8+dif9+dif10+dif11+dif12+dif13+dif14+dif15)/16;

mp = Param("Multiplier",2,0.25,5,0.25);
Sumdifml=(Sumdif*1);
Sumdifml2=(Sumdif*1.6);
Sumdifml3=(Sumdif*mp);

Betastops=HHV(C,20) - Sumdifml;
Betastops2=HHV(C,15) - Sumdifml2;


//BetastopsO=Ref(L,-1)-sumdifml;
//Plot(betastopsO,"BATS",ParamColor("", colorGreen) ,ParamStyle("",styleLine|styleThick|styleStaircase,maskAll));
Plot(Betastops, "A", ParamColor( "Color", colorYellow ),ParamStyle("Style",styleThick,maskAll));
Plot(Betastops2, "B", ParamColor( "Color2", colorGold ),ParamStyle("Style2",styleThick,maskAll));

//Plot(Sumdifml,"DifferenceX",3,styleNoLine |styleNoLabel);
//Plot(sumdif,"AvgDifference",25,styleNoLine |styleNoLabel);
//Plot(dif10,"AvgDifference1",26,styleNoLine |styleNoLabel);
_SECTION_END();

50 50 Trading System By TradersZone for Amibroker (AFL)


50 50 Trading System By TradersZone for Amibroker (AFL)


_N(Title = StrFormat(EncodeColor( colorGold) + "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
    SetChartOptions(0,chartShowArrows|chartShowDates);

   
    SetChartBkColor(ColorRGB(23,23,23));

 
    priceStyle = IIf( (Interval(0) == -900), styleLine, styleBar);

   
    if (BeginValue(BarIndex()) != 0 AND EndValue(BarIndex()) != BarCount-1) {
    range = EndValue(BarIndex())-BeginValue(BarIndex());
    Title += StrFormat("\nRange Bars: %g", range);
    }

    CandleBorder = ParamColor("Candle Border Color", colorBlack );
    UpCandleColor = ParamColor("Up Candle Color", colorGreen );
    DownCandleColor = ParamColor("Down Candle Color", colorRed );


    Graph0BarColor = IIf( C > O,UpCandleColor ,DownCandleColor);

    Plot( C, "Close", CandleBorder, styleNoTitle | ParamStyle("Style") | priceStyle );





x = TEMA(Close,12);
y = TEMA(Close,20);
Z= TEMA(Close,50);
Buy=Cross(x,y );
Sell=Cross(y, x);

SUPERBUY=Cross(Y,Z);
SUPERSELL=Cross(Z,Y);
PlotShapes( SUPERBUY * shapeHollowCircle, colorWhite, 0);
PlotShapes( SUPERSELL * shapeHollowCircle, colorBlue, 0);
PlotShapes( Buy * shapeUpTriangle, colorBrightGreen, 0);
PlotShapes( Sell * shapeDownTriangle, colorRed, 0);



dist = 1.9*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorGreen );
if( Sell[i] ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist[i], colorRed, colorYellow );
if( SUPERBUY[i] ) PlotText( "SUPERSELL\n@" + C[ i ], i, L[ i ]-dist[i], colorWhite );
if( SUPERSELL[i] ) PlotText( "SUPERBUY\n@" + C[ i ], i, H[ i ]+dist[i], colorBlue, colorYellow );

}

Sunday, 14 September 2014

Entry Signal, colorBlue, ExitSignal, colorRed, for Amibroker (AFL)

Entry Signal, colorBlue, ExitSignal, colorRed, for Amibroker (AFL)






_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow));
SetChartBkColor(ParamColor("BackGround Color", colorDarkGrey));

Wilders1 = Wilders(H,3);
Wilders2 = Wilders(L,3);
Wilders3 = Wilders(C,3);

Plot( Wilders1, "EMA1" ,ParamColor( "Color1", colorRed ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );
Plot( Wilders2, "EMA2" ,ParamColor( "Color2", colorGreen ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );
Plot( Wilders3, "EMA3" ,ParamColor( "Color3", colorBlue ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );
TimeFrameSet(inHourly);
DayHigh = LastValue(H);
DayLow = LastValue(L);
TimeFrameRestore();

SetChartOptions(0,chartShowArrows|chartShowDates);
Title = EncodeColor(colorYellow)+ Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorSkyblue) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Open-"+O+"  "+"High-"+H+"  "+"Low-"+L+"  "+"Close-"+C+"  "+ "Volume= "+ WriteVal(V);



P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( Wilders( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

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


SetChartOptions(0,chartShowArrows|chartShowDates);
Title = EncodeColor(colorYellow)+ Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorSkyblue) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Open-"+O+"  "+"High-"+H+"  "+"Low-"+L+"  "+"Close-"+C+"  "+ "Volume= "+ WriteVal(V);




EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );

Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorRed, colorGrey50 ));


Plot( C, "Price", Color, styleCandle | styleThick );

Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );

GfxSetBkMode( 1 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));

GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));

GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));

GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);

SWING MULTIPLE MOVING AVERAGES WITH ZIGZAG

SWING  MULTIPLE MOVING AVERAGES WITH ZIGZAG




_SECTION_BEGIN("Set Chart");
SetChartBkGradientFill(ParamColor("Inner panel upper", colorBlack), ParamColor("Inner panel lower", colorBlack));
Title =EncodeColor(colorYellow)+ "SWING"+ "-- " + EncodeColor(colorRed)+ "MULTIPLE"+ " "+ EncodeColor(colorBrightGreen)+"MOVING AVERAGES WITH ZIGZAG" +"\n" + EncodeColor(colorWhite)+ "CNBONDRE"+ " - " + FullName() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " +EncodeColor(colorCustom11)+ Date() +" - "+"-" +EncodeColor(colorAqua) +"  Op="+O+" "+"  Hi="+H+" "+"  Lo="+L+" "+"  Cl="+C+" "+  "  Ch= "+ WriteVal( ROC( C, 1 ),1.2)+"%" + "   Vol="+ WriteVal(V)+"\n";


StyleList= ParamList("Chart Style", "Candle,Bar");
style =IIf(StyleList== "Candle",styleCandle, styleBar=128);
GreenBar = IIf(C > O, True, False);
RedBar = IIf(C < O, True, False);
BarColor = IIf(GreenBar, colorWhite, IIf(RedBar, colorWhite, colorWhite));
PlotOHLC(O, H, L, C, "", BarColor, style );
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
m=MA( P, Periods );
_SECTION_END();

_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
s= EMA( P, Periods );
_SECTION_END();



PlotText(" Ch= "+WriteVal(ROC(C,1),1.2)+"%",BarCount,LastValue(C),42);
numBars = BarsSince(DateNum()!=Ref(DateNum(),-1))+1;
PlotText(" \n dm = "+WriteVal    ((m-s)/Ref((m-s),-1))      ,BarCount,LastValue(C),42);

_SECTION_BEGIN("Fill Color");
Cloudswitch = ParamToggle("Fill Color","On,Off");
dynamic_color = IIf( m > s, ParamColor("Down Color", colorSeaGreen ), ParamColor("Up Color", colorOrange ));
PlotOHLC( IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,s),IIf(Cloudswitch,-1e10,m), "", dynamic_color, styleNoLabel | styleCloud );
_SECTION_END();

A Nice formula for Amibroker (AFL)

A Nice formula for Amibroker (AFL)





_SECTION_BEGIN("MA Diff");
T=26;
KMA=((C-MA(C,T))/MA(C,T))*100;
Graph0=KMA;
Graph0Style=2+4;
Graph0BarColor=IIf(KMA>0,5,4);
GraphXSpace=5;

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//------------------------------------------------------------------------------

_SECTION_BEGIN("ZIG-ZAG");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();

_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);


Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Cond3 = Zig(C,z)>Ref(Zig(C,z),-4);
Buy = Cond1 AND Cond3;

Cond4 = Cross(Signal(r1,r2,r3),MACD(r1,r2));

Cond6 = Zig(C,z)<Ref(Zig(C,z),-4);
Sell = Cond4 AND Cond6;
Trigger = WriteIf(Buy, "Buy", "") + WriteIf(Sell, "Sell", "");

_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault));
FG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault));

if(Status("action") == actionIndicator)
{
Plot(C, "", colorGrey50, styleBar);
//PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorBlue, 0,L, Offset=-60);
//PlotShapes(IIf(Sell, shapeCircle, shapeNone),colorBlue, 0,H, Offset=-30);

}

//------------------------------------------------------------------------------------------------
if(Status("action") == actionExplore)

Filter = Buy OR Sell;
SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol", 77, FG, BG, 120);
AddColumn(DateTime(), "Date", formatDateTime, FG, BG, 100);
AddColumn(TimeNum() ,"Time",1);
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn(V, "Volume");
AddColumn(Ref(V,-1),"P-Vol");
AddColumn(V/Ref(V,-1)*100,"Increase in Vol");
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );

shape = Buy * shapeHollowUpTriangle + Sell * shapeHollowDownTriangle;

PlotShapes( shape, IIf( Buy, colorBlue, colorBlue ), 0, IIf( Buy, Low, High ) );

GraphXSpace = 7;

GraphXSpace = 7;
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();


_SECTION_BEGIN("Background text");
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("Tahoma", 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));
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("", 10, 500, False, False, 0);

_SECTION_BEGIN("Trading");

SetChartBkColor(ParamColor("BackGround Color", colorLightGrey));
pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
pShowMarkers = ParamToggle("Show Markers", "No|Yes", 1);
synch=ParamToggle("Synchronize buy/short with foreign index", "No|Yes", 1);
Volmin=Param("Volume minimum",5000,0,10000000,50);
Volmax=Param("Volume maximum",1000000,0,10000000,50);
priceRL=Param("Price Range Min",150,1,20000,1);
priceRH=Param("Price Range Max",3000,1,20000,1);
PercChangemin=Param("Percentage Change Min set", -25, -100, 100, 0.1);
PercChangemax=Param("Percentage Change Max set", 25, -100, 100, 0.1);
PerctakeProfit=Param("Take Profit Percent Set",0.6,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent Set",0.25,0.2,5,0.1);

PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);
Bars  = 0;
xpdh  = 90;

{
Plot_Range = (TimeNum() >= 85500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range   = (TimeNum() >= 085500 AND TimeNum()<= 093000) AND (DateNum()==LastValue(DateNum()));

FH_Prices  = High * FH_Range;
FH_Marker  = BarsSince(FH_Range>0);

Num_Bars   = 36000 / Interval(1);

TimeFrameSet(inDaily);
TOP_        = Open;
PDH_        = Ref(High,-1);
PDL_        = Ref(Low,-1);
PDO_        = Ref(Open,-1);
PDC_        = Ref(Close,-1);
PDM_        = (PDH_+PDL_)/2;
TimeFrameRestore();

isAll = True;
isRth =  TimeNum() >= 085400 AND TimeNum() <= 093000;
isdRth =  TimeNum() >= 085400 AND TimeNum() <= 160000;

aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);

TOP         = TimeFrameExpand(TOP_,inDaily,expandFirst);
PDH         = TimeFrameExpand(PDH_,inDaily,expandFirst);
PDL         = TimeFrameExpand(PDL_,inDaily,expandFirst);
PDO         = TimeFrameExpand(PDO_,inDaily,expandFirst);
PDC         = TimeFrameExpand(PDC_,inDaily,expandFirst);
PDM         = TimeFrameExpand(PDM_,inDaily,expandFirst);
FHH        = Ref(HHV(High*FH_Range,Num_Bars),-FH_Marker);
FHL = TimeFrameCompress( aRthL, inDaily, compressLow );
FHL = TimeFrameExpand( FHL, inDaily, expandFirst );
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );


FC1=((PDH-PDL)*0.433);
FC2=((PDH-PDL)*0.7666);
FC3=((PDH-PDL)*1.355);
FC4=(FHH-FHL);

A=IIf((FC4<=FC1+PDH*0.005),FC1,0);
B=IIf((FC4<=FC2+PDH*0.005 AND FC4>FC1+PDH*0.005),FC2,0);
Cl=IIf((FC4<=FC3 AND FC4>FC2+PDH*0.005),FC3,0);
AF=(A+B+Cl);


_SECTION_BEGIN ("foreign Index bar graph");
Vr=ParamList("Index",List = "DSEX,^NSEBANK,^CNXIT,^NSMIDCP,RELIANCE.NS,SBIN.NS",0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
BG3=HHV(LLV(HaL,4)+ATR(4),8);
BR3=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>BG3 ,colorBrightGreen,IIf(Hac < BR3,colorRed,colorGrey50));
Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
RestorePriceArrays();
_SECTION_END();

BuyPrice=(DayL+AF);
BuyTP1=(BuyPrice+(BuyPrice*(PerctakeProfit/100)));
BuyTP2=(C>=BuyTP1);
SellPrice=(DayH-AF);
SellTP1=(SellPrice-(SellPrice*(PerctakeProfit/100)));
SellTP2=(C<=SellTP1);
percchange=(((C-TOP)/TOP)*100);
Vol=(V>=Volmin AND V<=Volmax);
Percentage=(percchange>=PercChangemin AND percchange<=PercChangemax);
prc=(C>=priceRL AND C<=priceRH);
BuyStop1=(BuyPrice-(BuyPrice*(PercStoploss/100)));
BuyStop2=IIf((BuyStop1<=SellPrice) AND SellPrice<=BuyPrice,SellPrice,BuyStop1);
SellStop1=(SellPrice+(SellPrice*(PercStoploss/100)));
SellStop2=IIf((SellStop1>=BuyPrice) AND SellPrice<=BuyPrice, BuyPrice,SellStop1);

BuyStop=IIf((Buy AND NOT BuyTP2),BuyStop2,Null);
BuyTP=IIf(Buy AND NOT BuyStop,BuyTP2,Null);

Bars       = BarsSince(TimeNum() >= 85400 AND TimeNum() < 092900);
x0         = BarCount-LastValue(Bars);
x1         = BarCount-1;
TOP_Line   = LineArray(x0,LastValue(TOP),x1,LastValue(TOP),0);
PDH_Line   = LineArray(x0,LastValue(PDH),x1,LastValue(PDH),0);
PDL_Line   = LineArray(x0,LastValue(PDL),x1,LastValue(PDL),0);
PDC_Line   = LineArray(x0,LastValue(PDC),x1,LastValue(PDC),0);
PDM_Line   = LineArray(x0,LastValue(PDM),x1,LastValue(PDM),0);
FHH_Line   = LineArray(x0,LastValue(FHH),x1,LastValue(FHH),0);
FHL_Line   = LineArray(x0,LastValue(FHL),x1,LastValue(FHL),0);
BuyPriceline=LineArray(x0,LastValue(BuyPrice),x1,LastValue(BuyPrice),0);
BuyStopline=LineArray(x0,LastValue(BuyStop2),x1,LastValue(BuyStop2),0);
BuyTPline=LineArray(x0,LastValue(BuyTP1),x1,LastValue(BuyTP1),0);
SellPriceline=LineArray(x0,LastValue(SellPrice),x1,LastValue(SellPrice),0);
SellStopline=LineArray(x0,LastValue(SellStop2),x1,LastValue(SellStop2),0);
SellTPline=LineArray(x0,LastValue(SellTP1),x1,LastValue(SellTP1),0);
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue(DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue(DayL),0);


Plot(IIf(pShowtradeLines,BuyStopline,Null),"BuyStop",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Short Here",colorRed,styleDots|styleNoRescale);
//PlotShapes(IIf(pShowMarkers AND Buy, shapeHollowUpArrow, Null), colorDarkGreen, 0,L,Offset=-30);

if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "Trading System" + " - " +  Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
 "  - " + Date() +" - "+ EncodeColor(colorYellow) + "-Open="+WriteVal(O,1) + EncodeColor(colorYellow) + "- High= "+ WriteVal(H,1)+ EncodeColor(colorYellow) + "- Low= "+ WriteVal(L,1)+ EncodeColor(colorYellow) + "- Close= "+ WriteVal(C,1)+ EncodeColor(colorYellow) + "- Vol= "+ WriteVal(V,1)+("\n")
 +WriteIf(Percchange, " % Change =  "+(Percchange)+"  ","")+" Previous DayHigh="+WriteVal(PDH,1)+", Previous DayLow="+WriteVal(PDL,1)+", Today High="+WriteVal(DayH,1)+", Todays Low="+WriteVal(DayL,1)+
WriteIf(Hac>BG3,EncodeColor(colorBrightGreen)+"+Up",
WriteIf(Hac<BR3,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >")));

GfxSetOverlayMode( mode = 0 );
GfxSelectPen( colorLightBlue, 3 );
GfxSelectSolidBrush( colorLightYellow );
GfxRoundRect( 20, 55, 180, 175, 15, 15 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 10, 700, False );
GfxSetTextColor( colorBrown );
GfxSetTextAlign(0);
GfxTextOut( WriteIf(SellPrice, "TRP level:  "+(SellPrice),""), 30, 60);
GfxTextOut( WriteIf(BuyPrice, "Buy Above:  "+(BuyPrice),""), 30, 75);
GfxTextOut( WriteIf(BuyStop2, "Long SL:  "+(BuyStop2),""), 30, 90);
GfxTextOut( WriteIf(BuyTP1 , "Long Target 1:  "+(BuyTP1),""), 30, 105);
GfxTextOut( WriteIf(SellPrice, "Sell Below:  "+(SellPrice),""), 30, 120);
GfxTextOut( WriteIf(SellStop2, "Short SL:  "+(SellStop2),""), 30, 135);
GfxTextOut( WriteIf(SellTP1, "Short Target:  "+(SellTP1),""), 30, 150);

AddColumn(V,"Volume",1.0);
AddColumn(Percchange,"Change %",1.2);
AddColumn(BuyPrice,"Buy at",1.2);
AddColumn(BuyStop,"Buy Stop at",1.2);
AddColumn(BuyTP1,"Buy Profit at",1.2);
AddColumn(SellPrice,"Short at",1.2);
AddColumn(SellTP1,"Short profit at",1.2);

}

_SECTION_END();

_SECTION_BEGIN("short signal");  
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 ) );
BG2=HHV(LLV(Low,4)+ATR(4),8);
BR2=LLV(HHV(High,4)-ATR(4),8);
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
k =  Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=HaClose;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * 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];
   }
  }
 }
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
//dist = 1.5*ATR(15);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy@" + O[ i ], i, L[ i ]-Trend[i], colorDarkBlue, colorYellow );
if( Sell[i] ) PlotText( "Sell@" +H[ i ], i-4, L[ i ]+Trend[i], colorRed, colorYellow );
}

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,halow,-30);
PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorWhite, 0,hahigh,-15);
PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),colorWhite, 0,halow,-15);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,hahigh,-30);
//-----------end--------------

_SECTION_BEGIN("Signal Panel");

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

showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
if (showsl == 1)
{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 @ " + O, 1 );
AlertIf( Sell, "", "SELL @ " + O, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = O[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 = O[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);

}

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
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( ( "Signal Panel"),100,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)), 70, y-22);;

}
_SECTION_END();

TRADING RULES

TRADING RULES 

1. Book profits when ever it is reasonable.

2. Apply strict STOP LOSS /trailing stop loss. 

3. Be with the trend. Avoid trading if trend is not clear.

4. Do not time the market.

5. Do not trade with greed or fear.

6. Your INTEREST is your winning key.

7. 
CALCULATION on every stage,time,condition always. 

8. INVESTOR, TRADER  understands this words.

9. Respect for self, Respect for own decision.

10.
This is UNFINISHED BUSINESS so relax any situation. 

AMIBROKER AFL is simple MY TREND FOLLOW STRATEGY AFL

 AMIBROKER AFL is simple MY TREND FOLLOW STRATEGY AFL





SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{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 )) ));

trendup = IIf(MACD(12,26) > 0 AND MACD(12,26) > Signal(12,26,9), colorGreen, colorWhite);
trendcolor = IIf(MACD(12,26) < 0 AND MACD(12,26) < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleCandle | styleThick );



sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;

shape = RSIup * shapeNone + RSIdown * shapeNone;
PlotShapes(shape, IIf( RSIup, colorBrightGreen, colorRed ), 0, IIf( RSIup, Low, High ) );

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 )));
}
_SECTION_END();




DayH = TimeFrameGetPrice("H", inDaily, -1)*(1+0.0005);  DayHI = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1)*(1-0.0005);  DayLI = LastValue (DayL,1); // yesterdays low
DayC = TimeFrameGetPrice("C", inDaily, -1);   // yesterdays close
DayO = TimeFrameGetPrice("O", inDaily);   // current day open


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

YHL = ParamToggle("Yesterday HI LO","Hide|Show",1);
if(YHL==1) {

}


FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorBrightGreen) );
Hor=Param("Horizontal Position",940,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+"  ("+xx+"%)", Hor , Ver+45 );



_SECTION_END();




DayH = TimeFrameGetPrice("H", inHourly, -1);  DayHI = LastValue (DayH,1);// hourly high
DayL = TimeFrameGetPrice("L", inHourly, -1);  DayLI = LastValue (DayL,1); // hourly low
DayC = TimeFrameGetPrice("C", inHourly, -1);   // yesterdays close
DayO = TimeFrameGetPrice("O", inHourly);   // current day open


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

YHL = ParamToggle("Yesterday HI LO","Hide|Show",1);
if(YHL==1) {
 
}

_SECTION_BEGIN("MOHAN CROSSOVER");


P = ParamField("Price field",-1);
Periods1 = Param("Periods1", 5, 2, 300, 1, 10 );
Periods2 = Param("Periods2", 20, 2, 300, 1, 10 );
Plot( MA( P, Periods1 ), StrFormat(_SECTION_NAME()+"(%g)", Periods1), ParamColor( "Color1", colorRed ), ParamStyle("Style") );
Plot( MA( P, Periods2 ), StrFormat(_SECTION_NAME()+"(%g)", Periods2), ParamColor( "Color2", colorBlue ), ParamStyle("Style") );
Buy = Cross( MA( P, Periods1 ), MA( P, Periods2 ) );
Sell = Cross(MA( P,Periods2 ), MA( P, Periods1 ) );
Display= ParamToggle("Display","Off|On",0);

PlotOHLC( Null,MA( P, Periods1 ),MA( P, Periods2 ),Null, "", IIf(MA( P, Periods1 )>MA( P, Periods2 ) ,colorDarkGreen,colorDarkRed), styleCloud);

Color = IIf( MA(p,periods1) > MA(p,periods2) , colorLime, IIf( MA(p,periods2) > MA(p,periods1), colorRed, colorGrey50 ));
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 30 );

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();



_SECTION_BEGIN("MOHAN MACD");
r = Param( "TSI period 'R':", 7, 1, 100, 1 );
s = Param( "TSI period 'S':", 27, 1, 100, 1 );
u = Param( "TSI period 'U':", 1, 1, 100, 1 );
sig = Param( "Signal period:", 7, 1, 100, 1 );

Mtm = C - Ref ( C, -1 );
AbsMtm = abs ( Mtm );
Num_T = EMA ( EMA( EMA ( Mtm, r ), s ), u );
Den_T = EMA ( EMA( EMA ( AbsMtm, r ), s ), u);

TSI = 100 * Nz ( Num_T / Den_T );
TSIL = 100 * Nz ( Num_T / Den_T );

//Green TSIL Line=Rising; Red TSIL Line=Falling
col = IIf( TSIL > Ref( TSIL, -1 ), colorGreen, colorRed );
//Plot( TSIL, "TSI("+r+","+s+","+u+")", col, styleLine | styleThick);
//Green EMA TSI,sig Line=Rising; Red EMA TSI,sig Line=Falling
col = IIf( EMA(TSI,sig) > Ref( EMA(TSI,sig), -1 ), colorGreen, colorRed );
//Plot( EMA(TSI,sig), "", col, styleThick);
Histcol= IIf(TSI>0,colorLime,colorRed) ;
//Plot( TSI, "", histcol, ParamStyle("Histogram style", styleThick |styleHistogram | styleNoLabel, maskHistogram ) );
//Plot(0,"",ParamColor( "ColorZero", colorBrown ),styleLine);

//Title = "MOHAN MACD";
_SECTION_END();

_SECTION_BEGIN("MACDval");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );


dynamic_color = IIf( MACD() > 0, colorGreen, colorRed);
MACD_trend = IIf( MACD() >= 0, 0.5, -0.5);
//Plot( 2, "ribbon",IIf( MACD_trend>=0, colorLime, colorRed ), styleOwnScale|styleArea|styleNoLabel, 0, 100 );