backtesting help

bunti_k23

Well-Known Member
#1
guys i have only 1 month of intraday data on stocks i want to backtest sum afl s if anyone have 1yr + intraday data of nifty stocks (axisbank,dlf,etc just backtest only 4-5 gud stocks)only then plz backtest following afl and post the backtesting results in the thread itself .will be helpfull for me and all guys
thank you

backtest on 3m and 5m tf.
conditions-

initial stoploss is 0.004% (put this condition only)

discretionary condition for every buy and sell signals of any afl s .to confirm valid signals (this is not coded )
buy only if the next candle breaks the high of signal candle and sell only if next candle breaks the low of signal candle.

1- system (my own system)

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


_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorWhite ), styleThick | ParamStyle("Style") | GetPriceStyle() );


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));



TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor=Optimize("Factor",4,0.1,10,0.1);
Pd=Optimize("ATR Periods",5,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

trend=1;


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

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

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

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

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

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

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

Plot(TrendUp,"Trend",colorBlue);
Plot(TrendDown,"Down",colorRed);


/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor1=Optimize("Factor1",1.5,5,10,2);
Pd1=Optimize("ATR Periods1",5,1,10,1);
Up1=(H+L)/2+(Factor1*ATR(Pd1));
Dn1=(H+L)/2-(Factor1*ATR(Pd1));
iATR1=ATR(Pd1);
TrendUp1=TrendDown1=Null;
trend1[0]=1;
changeOfTrend1=0;
flag1=flagh1=0;

for (i = 1; i <BarCount; i++) {
TrendUp1 = Null;
TrendDown1 = Null;

trend1=1;


if (Close>Up1[i-1]) {
trend1=1;
if (trend1[i-1] == -1) changeOfTrend1 = 1;

}
else if (Close<Dn1[i-1]) {
trend1=-1;
if (trend1[i-1] == 1) changeOfTrend1 = 1;
}
else if (trend1[i-1]==1) {
trend1=1;
changeOfTrend1 = 0;
}
else if (trend1[i-1]==-1) {
trend1=-1;
changeOfTrend1 = 0;
}

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

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

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

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

if (flag1==1)
{ Up1=(H+L)/2+(Factor1*iATR1);;
}
if (flagh1==1)
{ Dn1=(H+L)/2-(Factor1*iATR1);;
}
if (trend1==1) {
TrendUp1=Dn1;
if (changeOfTrend1 == 1) {
TrendUp1[i-1] = TrendDown1[i-1];
changeOfTrend1 = 0;
}
}
else if (trend1==-1) {
TrendDown1=Up1;
if (changeOfTrend1 == 1) {
TrendDown1[i-1] = TrendUp1[i-1];
changeOfTrend1 = 0;
}
}
}


//Plot(TrendUp1,"Trend",colorWhite);
//Plot(TrendDown1,"Down",colorWhite);


/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/

Buy = trend==1 AND trend1==1 ;
Short=trend==-1 AND trend1==-1;
Sell=trend1==-1;
Cover=trend1==1;

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



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


Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorWhite, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorWhite, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);


supertrend = Optimize( "supertrend", 4, 3, 4, 1 );



_SECTION_END();

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

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI() AND MACD()>Signal();
downtrend=MDI()>PDI() AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

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


_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();

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



2- system (turtle trading system)


/*
Formula Name: Turtle trading system
Author/Uploader: DrZingaro
E-mail: [email protected]
Date Added: 2009-01-12
Origin: Turtle trading experimemnt Chandelier exit based on Chuck Lebeau's work
Keywords: Trend trading
Level: Basic
Flags: System
*/
//=============================SETUP================ ======================
//Strengths: volatility-based.
//Weaknesses: lag AND since volatility increases at the end of a trend, traders exits early.
//Description: Indicator is used to keep track of a trade. Once a stop is hit, it waits for the next entry Signal (Short OR long). Use on DAILY values only.
//Algorithm: Lebeau recommends that an exits hangs from the HHV (long) OR LLV (Short) since the trade was triggered. Some traders use the Highest Close as the base for hanging the exit.

pds = 20;
MAFAST = EMA( Close, 20 );
MASLOW = EMA( Close, 40 );

DonchianUpper = HHV( Ref( H, -1 ), pds ); // Highest high value of highs in last 20 periods
DonchianLower = LLV( Ref( L, -1 ), pds ); // Lowest low value of low in last 20 periods
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, colorBlue, IIf( DnTrend, colorOrange, colorCustom11 ) );

// Plots a 20 period Donchian channel
Plot( C, "Price", Color, styleBar | styleThick );
Plot( DonchianUpper, "Donchian U", ParamColor( "DU Color", colorBlue ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianMiddle, "Donchian M", ParamColor( "DM Color", colorBrightGreen ), ParamStyle( "DM Style", styleNoLine ) );
Plot( DonchianLower, "Donchian L", ParamColor( "DL Color", colorRed ), ParamStyle( "DL Style", styleLine ) );

Title = WriteVal( DonchianUpper, 1.2 ) + WriteVal( DonchianLower, 1.2 ) + WriteVal( DonchianMiddle, 1.2 );
//=============================TRIGGERS AND ENTRIES=======================
Buy = High > Ref( HHV( High, 20 ), -1 ) AND MAFAST > MASLOW; // Enters long trade

Short = Low < Ref( LLV( Low, 20 ), -1 ) AND MAFAST < MASLOW; // Enters short trade



//=============================EXITS================ ======================
_SECTION_BEGIN( "Chandelier Exit" );

SetBarsRequired( 50, 50 );

Multiple = Param( "Multiple", 3, 0.5, 10, 0.1 ); // How many ATR’s to be allowed below the highest high since latest "buy" bar
ATRPeriods = Param( "ATR Periods", 20, 1, 50, 1 ); // How many periods to use for the ATR

stopArray = Null;
atrArray = ATR( ATRPeriods );
HHArray = Null;
LLArray = Null;
exitArray = Null;
trendDirection = 0;

for ( i = 0; i < BarCount; i++ )
{
if ( Short )
{
// we just triggered a short trade. Set up starting values
stopArray = Low + ( Multiple * atrArray );
LLArray = Low; // initialize the lowest low array
trendDirection = 0 - 1; // going short. Base bar.
}

if ( Buy )
{
// we just triggered a long trade. Set up starting values
stopArray = High - ( Multiple * atrArray );
HHArray = High; // initialize the highest high array
trendDirection = 1; // going long. Base bar flag is now set.
}

exitArray = 0;

if ( trendDirection > 0 )
{
// keep track of the highest high, highest close, highest low, etc..
if ( trendDirection > 1 )
{
// We are in the trade (2nd day or later)
if ( Low < stopArray[i-1] )
{
//stop got hit. Reset the trade.
trendDirection = 0; // OK. wait until we trigger another trade.
exitArray = 1;
}
else
{
// keep track of the HHV since trade was entered.
if ( High > HHArray[i-1] )
HHArray = High;
else
HHArray = HHArray[i-1];

// Compute the stop based on the HHV.
stopArray = HHArray - ( Multiple * atrArray );
}
}

trendDirection = trendDirection + 1;
}

if ( trendDirection < 0 )
{
// keep track of the lowest low, lowest close, lowest high, etc..
if ( trendDirection < 0 - 1 )
{
// We are in the trade (2nd day or later)
if ( High > stopArray[i-1] )
{
// our stop got hit. Reset the trade.
trendDirection = 0;
exitArray = 0 - 1;
}
else
{
// keep track of the LLV since trade was entered.
if ( Low < LLArray[i-1] )
LLArray = Low;
else
LLArray = LLArray[i-1];

// Compute the stop based on the LLV.
stopArray = LLArray + ( Multiple * atrArray );
}
}

trendDirection = trendDirection - 1;
}

if ( trendDirection == 0 )
{
stopArray = 0;
LLArray = 0;
HHArray = 0;
}
}

Sell = Cover = exitarray;

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

PlotShapes( Buy*shapeUpArrow, colorBrightGreen, 0, Low );
PlotShapes( Short*shapeDownArrow, colorRed, 0, High );
PlotShapes( abs( exitArray )*shapeHollowCircle, colorYellow, 0, ValueWhen( stopArray, stopArray, 1 ), 0 );
Plot( stopArray, "Chand", ParamColor( "Chand Color:", colorYellow ), ParamStyle( "Chand Style", styleDashed ) );

_N( Title = EncodeColor( colorYellow ) + StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}}--Turtle_System_Rev_A \n OP= %g Hi= %g Lo= %g CL= %g (%.1f%%) \n Vol= " + WriteVal( V, 1.0 ) + "\n" + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );//=cnb

//_N(Title = "LLArray: " + LLArray + ", HHArray:" + HHArray +", stopArray"+stopArray);

//PlotShapes(shapeCircle * Sell, colorRed);
//PlotShapes(shapeCircle * Cover, colorGreen);
_SECTION_END();



3-system (kbl system)


_SECTION_BEGIN("HA");


tchoice=Param("Title Selection ",2,1,2,1);

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

for( i = 0; i < BarCount; i++ )
{
if( HH ) PlotText( "HH", i, H[ i ]+dist, colorCustom12 );
if( LH ) PlotText( "LH", i, H[ i ]+dist, colorCustom12 );
if( HL ) PlotText( "HL", i, L[ i ]-dist, colorBlack );
if( LL ) PlotText( "LL", i, L[ i ]-dist, colorBlack );

}

//calculates floor pivots from previous days data & plots it on the present intraday chart.
//RED LINE = RESISTANCE
//RED DASHED LINE = MINI RESISTANCE
//BLUE LINE = SUPPORT
//BLUE DASHED LINE = MINI SUPPORT
//YELLOW DOTTED LINE = PIVOT
//RED DOTTED LINE = PREVIOUS Day High
//BLUE DOTTED LINE = PREVIOUS Day Low
//BLACK DOTTED LINE = PREVIOUS Day Close


//2 - IN - 1 PRICE CHART
Pstyle = ParamToggle("Heikin Ashi","On|Off",1);
if(Pstyle==0){
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 ) );
//PlotOHLC(HaOpen,HaHigh,HaLow,HaClose,"",IIf(HaClose > HaOpen,colorGreen,colorBrown),styleCandle);

//Sell = (abs(HaOpen -HaClose )<= ((HaHigh -HaLow )*0.1));
//Buy = (abs(HaOpen -HaClose )<= ((HaHigh -HaLow )*0.1)) ;

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

//PlotShapes( IIf( Sell, shapeDownArrow+ shapePositionAbove, shapeNone), colorCustom12 );
//Plot(EMA(HaClose,20), "", colorBlue , styleLine|styleThick );
//Plot(Wilders(H,260.6), "",colorCustom12 , styleDashed|styleThick );
//Plot(EMA(HaClose,10), "",colorTan, styleLine|styleThick );



TimeFrameSet(inHourly);
Hh=HHV (L,24);
Ll =LLV (H,24);
TimeFrameRestore();
Hh1=(TimeFrameExpand( Hh, inHourly));
Ll1=(TimeFrameExpand( Ll, inHourly));

Plot(Hh1 , "27dayssellbelclose",colorRed, 4+8+2048);
Plot(Ll1 , "27daysbuyabvclose",colorGreen, 4+8+2048);

Buy=Cross(C,LL);
Sell=Cross(HH,C);
Filter=Buy OR Sell;



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


Pivot = ParamToggle("Pivot", "weekly|monthly", 1);

if(Pivot)
{
H1 = TimeFrameGetPrice("H", inMonthly, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inMonthly, -1); // low
C1= TimeFrameGetPrice("C", inMonthly, -1); // close


}
else
{
H1 = TimeFrameGetPrice("H", inWeekly, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inWeekly, -1); // low
C1= TimeFrameGetPrice("C", inWeekly, -1); // close
}

// PIVOT Calculation
P = ( H1+ L1+ C1 )/3;
R1 = P+(H1-L1)/2-(P-C1)/2;
R2 = H1-L1+P;
R3 = H1-L1+R1;
R4 = H1-L1+R2;
R5 = H1-L1+R3;
R6 = H1-L1+R4;
R7 = H1-L1+R5;
R8 = H1-L1+R6;
R9 = H1-L1+R7;
R10 = H1-L1+R8;



S1 = P -(H1-L1)/2-(P-C1)/2;
S2 = P -(H1-L1);
S3 = S1 -(H1-L1);
S4 = S2 -(H1-L1);
S5 = S3 -(H1-L1);
S6 = S4 -(H1-L1);
S7 = S5 -(H1-L1);
S8 = S6 -(H1-L1);
S9 = S7 -(H1-L1);
S10 =S8 -(H1-L1);













// PIVOT mid points
MIDR1 = (P+R1)/2;
MIDR2 = (R1+R2)/2;
MIDR3 = (R2+R3)/2;
MIDR4 = (R3+R4)/2;
MIDR5 = (R4+R5)/2;
MIDR6 = (R5+R6)/2;
MIDR7 = (R6+R7)/2;
MIDR8 = (R7+R8)/2;
MIDR9 = (R8+R9)/2;
MIDR10 = (R9+R10)/2;




MIDS1 = (P+S1)/2;
MIDS2 = (S1+S2)/2;
MIDS3 = (S2+S3)/2;
MIDS4 = (S3+S4)/2;
MIDS5 = (S4+S5)/2;
MIDS6 = (S5+S6)/2;
MIDS7 = (S6+S7)/2;
MIDS8 = (S7+S8)/2;
MIDS9 = (S8+S9)/2;
MIDS10 = (S9+S10)/2;













n=130;
per =11.5;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Buy = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(S1==trendlineS,-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1);
Sell = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(S11==trendlineR,-1 ),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1 ),-1 ),-1 ),-1 ),-1 );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );
//PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGold, colorPink) );
dist = 2.5*ATR(10);
dist1 = 0.7*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\n Heavy Fire Up Ahead " , i, L[ i ]-dist, colorBlack, colorGreen );
//Say("Heavy Fire Up Ahead");
}
if( Sell )
{
PlotText( " Heavy Down Fall Ahead " , i, H[ i ]+dist1, colorBlack, colorRed );
//Say("Heavy Down Fall Ahead");
}
}

n=45;
per =20;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSIa(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(trendlineR , "trendlineR" ,colorRed , styleLine);
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Buy = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(S1==trendlineS,-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1);
Sell = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(S11==trendlineR,-1 ),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1 ),-1 ),-1 ),-1 ),-1 );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
// Plot the ribbon
ribboncol= IIf( BarsSince(Buy)<BarsSince(Sell), colorGreen, colorRed );
Plot( 3, "", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 );
PlotShapes(IIf(Buy, shapeSquare,shapeNone) ,colorBlue,0, Close, Offset=-10) ;
PlotShapes(IIf(Buy, shapeSmallUpTriangle,shapeNone) ,colorLime,0, Close, Offset=-10) ;
PlotShapes(IIf(Sell, shapeSquare,shapeNone),colorRed,0, Close, Offset=-1) ;
PlotShapes(IIf(Sell, shapeSmallDownTriangle,shapeNone),colorLime,0, Close, Offset=-1) ;
PlotShapes( Buy * shapeNone + Sell * shapeNone, IIf( Buy, colorBlue, colorPink) );
dist = 0.8*ATR(10);
dist1 = 2*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy )
{
PlotText( "\nHNI Buy 10 Lots @" + C[ i ] + "\nTGT= " + (C*1.0045) + "\nSL= " + (C*0.9970), i, L[ i ]-dist, colorGreen, colorBlack );
}
if( Sell )
{
PlotText( "HNI Sell 10 Lots @" + C[ i ] + "\nT= " + (C*0.995) + "\nSL= " + (C*1.0025), i, H[ i ]+dist1, colorRed, colorBlack );
}
}




_SECTION_END();






Uphigh = HHV(C,90);
downhigh = LLV (C, 40);
//Buy = C>= Uphigh;
//Sell = C<= downhigh;
Buy = ExRem (Buy,Sell);
Sell = ExRem (Sell,Buy);


_SECTION_BEGIN("BACK COLOR");
SetChartBkGradientFill( ParamColor("BgTop", colorPlum),

ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorPlum));

Title = (EncodeColor(colorGold)+Day() + EncodeColor(colorWhite) + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorWhite)+",Open "+Open +" , High "+H+" , Low "+L+" , Close "+C+" "+"{{VALUES}}");

BuyPrice = Open;
SellPrice = Open;

Derived=WMA(WMA(WMA(((H+L)/2)+(O-C),92),1),1);
i=WMA(Derived,3);
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5;
Lower=(Derived-StDev(Derived,7))-ATR(2)/1;

color=IIf(BarsSince(Cross(Lower,Low))>
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed);
Plot(C,"",color,64);



//WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,","");
//WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",","");
//WriteIf( sss ,"No trading signals today.","") ;



SetBarsRequired( 600, 0 );

GraphXSpace = 8;
SetChartOptions( 0, chartShowArrows | chartShowDates );


//============== TITLE ==============

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGold) );
Hor=Param("Horizontal Position",970,1,1200,1);
Ver=Param("Vertical Position",50,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( colorWhite );
GfxSetTextColor(ParamColor("Color",colorBlack) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );

_SECTION_END();




_SECTION_BEGIN("Price Line");
dp= Param("dps",3,0,1000,1);
PriceLineColor=ParamColor("PriceLineColor",colorOrange);
PriceLevel = ParamField("PriceField", field = 3 );
PriceLeve2 = ParamField("PriceField", field = dp );
Daysback = Param("Bars Back",1,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));

side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorGold );

}

_SECTION_END();





































/****************/
/* */
/* ALERT OUTPUT */
/* */
/****************/

TxtX = Param("Text Left", 600, 0, 1000, 10);
TxtY = Param("Text Top", 60, 1, 650, 10);

GfxSelectFont("Tahoma", 14, 700 );
GfxSetBkMode(1);

if(LastValue(Buy) OR SelectedValue(Buy))
{
GfxSetTextColor(colorGold);
GfxTextOut("Waiting For Next Signal", TxtX, TxtY);
Say("");
}

else if(LastValue(Sell) OR SelectedValue(Sell))
{
GfxSetTextColor(colorGold);
GfxTextOut("Waiting For Next Signal", TxtX, TxtY);
Say("");
}

else
{
GfxSetTextColor(colorGold);
GfxTextOut("Waiting For Next Signal ", TxtX, TxtY);
GfxTextOut("", TxtX, TxtY);
}
_SECTION_BEGIN("sys");

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



_SECTION_END();




_SECTION_BEGIN("Background text");
C11=ParamColor("up panel",colorBlack );
C12=ParamColor("dn panel",colorBlack );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",8,1,30,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSelectFont("Tahoma", 12, 500, False, False, 0);
GfxSetTextColor(colorCustom12);
GfxSetTextAlign( 6 );
GfxSelectFont("Tahoma", 15, 600, False, False, 0);
GfxSetTextColor(colorWhite);
GfxSetTextAlign( 6 );

GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorBrightGreen);

GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorRed);




pricechange=(C-Ref(C,-1))*100/Ref(C,-1);
changeponit=C-Ref(C,-1);
Vlp=Param("Volume lookback period",15,10,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;

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

GfxGradientRect( 1, 1, 1400, 40, colorViolet, colorBlack);
GfxSetBkMode(0);
GfxSelectFont( "Georgia", 18, 800, False );
GfxSetTextColor( colorGold );
GfxTextOut( "General ", x+600, y+10 );
GfxSelectFont( "Tahoma", 16, 800, False );
GfxSetTextColor( colorGold );
GfxTextOut( Name(), x+100, y+10 );
GfxSelectFont( "Century Gothic", 15, 100, False );
GfxSetTextColor( colorGold );
GfxTextOut( Date(), x+1000, y+10 );
GfxSelectFont( "Comic Sans MS", 15, 500, False );
GfxSetTextColor( colorYellow );
GfxTextOut( Interval(2), x+275, y+10 );
//------------------------------------------------------------ H, L, O, C----------------------
GfxGradientRect( 1, 40, 1400, 55, colorViolet, colorBlack );
GfxSetBkMode(0);
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "High:"+WriteVal(H,1.2), x+100, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Low:"+WriteVal(L,1.2), x+200, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Open:"+WriteVal(O,1.2), x+300, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Close:"+WriteVal(C,1.2), x+400, y+40 );
GfxSelectFont( "comic sans ms", 12, 100, False );
//-----------------------------------------------------------Valume-------------------------------


// set criteria to scan for big stock only;
BigStock = MA( V, 10 ) * MA( C, 10 ) > 100;

//---------------Color------------------------
per1 = 6;
per2 = 2;
Om = MA( O, per1 );
hm = MA( H, per1 );
lm = MA( L, per1 );
Cm = MA( C, per1 );

// 1. Heiken Ashi
HACLOSE = ( Om + Hm + Lm + Cm ) / 4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );


Of = MA( Haopen, per2 );
Cf = MA( Haclose, per2 );
Lf = IIf( haOpen < haClose, MA( Halow, per2 ), MA( Hahigh, per2 ) );
Hf = IIf( haOpen < haClose, MA( Hahigh, per2 ), MA( Halow, per2 ) );
//Color = IIf( Cf > Of, colorGreen, colorRed );


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

TrailStop = HHV( C - 2 * ATR( 10 ), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR( 10 );

/* **********************************
Code to automatically identify pivots
********************************** */

// -- what will be our lookback range for the hh and ll?
farback = 140; //How Far back to go
nBars = 12; //Number of bars

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

// -- More for future use, not necessary for basic plotting
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;

// -- looking back from the current bar, how many bars
// back were the hhv and llv values of the previous
// n bars, etc.?
aHHVBars = HHVBars( O, nBars );
aLLVBars = LLVBars( O, nBars );
aHHV = HHV( O, nBars );
aLLV = LLV( O, nBars );

// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of
// _Trace output will show a value of 0
aVisBars = Status( "barvisible" );
nLastVisBar = LastValue( Highest( IIf( aVisBars, BarIndex(), 0 ) ) );
_TRACE( "Last visible bar: " + nLastVisBar );

// -- Initialize value of curTrend
curBar = ( BarCount - 1 );
curTrend = "";

if ( aLLVBars[curBar] < aHHVBars[curBar] )
{
curTrend = "D";
}
else
{
curTrend = "U";
}

// -- Loop through bars. Search for
// entirely array-based approach
// in future version
for ( i = 0; i < BarCount; i++ )
{
curBar = ( BarCount - 1 ) - i;
// -- Have we identified a pivot? If trend is down...

if ( aLLVBars[curBar] < aHHVBars[curBar] )
{
// ... and had been up, this is a trend change
if ( curTrend == "U" )
{
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}

// -- or current trend is up
}
else
{
if ( curTrend == "D" )
{
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}

// -- If curTrend is up...else...
}

// -- loop through bars
}

// -- 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++;
}
}

//============== EXPLORATION ==============
Buy = Cover = BigStock AND aLPivs == 1;

Sell = Short = BigStock AND aHPivs == 1;

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

//============== Plot price ==============
n = 15;

a = C > ( MA( H, n ) + MA( L, n ) ) / 2;// then Buy next bar at market;

b = C < ( MA( H, n ) + MA( L, n ) ) / 2;// then Sell Short next bar at market;

state = IIf( BarsSince( a ) < BarsSince( b ), 1, 0 );

Longs = state == 1;

shorts = state == 0;



4-system (intraday afl)


_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);

SetBarsRequired(sbrAll,sbrAll);

SetBarFillColor(IIf(C>O,ParamColor("Bar Up Color", colorBrightGreen),IIf(C<=O,ParamColor("Bar Down Color", colorRed),colorLightGrey)));

Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color", colorBlack),IIf(C<=O,ParamColor("Shadow Down Color", colorBlack),colorLightGrey)),64,0,0,0);

SetChartBkColor(ParamColor("Panel Color ",colorDarkGrey));

SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("Lower Chart",colorDarkGrey));

GraphXSpace=Param("GraphXSpace",20,-10,25,1);



_SECTION_BEGIN("Ravi's EMA's");

EMA1 = EMA(H,34);

EMA2 = EMA(L,34);

EMA3 = EMA(C,34);



Plot( EMA1, "EMA1" ,ParamColor( "Color1", colorRed ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );

Plot( EMA2, "EMA2" ,ParamColor( "Color2", colorGreen ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );

Plot( EMA3, "EMA3" ,ParamColor( "Color3", colorBlue ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );

_SECTION_END();



_SECTION_BEGIN("Ravitrend");

procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice)

{

global buffer_line_down;

global buffer_line_up;

buffer_line_down = Null;

buffer_line_up = Null;



PHASE_NONE = 0;

PHASE_BUY = 1;

PHASE_SELL = -1;



phase=PHASE_NONE;

band_upper = 0;band_lower = 0;



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

{

band_upper = CalcPrice + ATR_Multiplier * tr;

band_lower = CalcPrice - ATR_Multiplier * tr;



if(phase==PHASE_NONE)

{

buffer_line_up = CalcPrice;

buffer_line_down = CalcPrice;

}

if(phase!=PHASE_BUY && Close>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1]))

{

phase = PHASE_BUY;

buffer_line_up = band_lower;

buffer_line_up[i-1] = buffer_line_down[i-1];

}

if(phase!=PHASE_SELL && Close<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))

{

phase = PHASE_SELL;

buffer_line_down = band_upper;

buffer_line_down[i-1] = buffer_line_up[i-1];

}

if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )

{

if(band_lower>buffer_line_up[i-1])

{

buffer_line_up = band_lower;

}

else

{

buffer_line_up = buffer_line_up[i-1];

}

}

if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )

{

if(band_upper<buffer_line_down[i-1])

{

buffer_line_down = band_upper;

}

else

{

buffer_line_down = buffer_line_down[i-1];

}

}

}

}



TrendMode = ParamToggle("TrendMode","Off|On",1);

ATR_Multiplier = Param("ATR_Multiplier",.01,0.1,1,0.1);

ATR_Period = Param( "ATR_Period",1,1,1,1);

tr = ATR(ATR_Period);



CalcPrice = (H+L)/2;

calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice);



Plot(buffer_line_up,"\ntu",ColorRGB(28,134,238),styleThick);

Plot(buffer_line_down,"\ntd",ColorRGB(205,51,51),styleThick);



Plot( 2,"",IIf(buffer_line_up,colorGreen,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

Plot( 4,"",IIf(buffer_line_down,colorRed,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();



TimeFrameSet(inDaily);

DayHigh = LastValue(H);

DayLow = LastValue(L);

TimeFrameRestore();



Title = Date() + ", Op=" + Open + ", Hi=" + High + ", Lo=" + Low + ", LTP=" + Close + ", Change= " + SelectedValue( ROC( C, 1 ) ) + "%" + "\n Today`s High=" + DayHigh + ", Today`s Low=" + DayLow + " © " ;





prev=AMA2(C,1,0);

d=IIf(C>Ref(Max(Max(H,Ref(H,-10)),Max(Ref(H,-5),Ref(H,-7.5))),-1),Min(Min(L,Ref(L,-10)),Min(Ref(L,-5),Ref(L,-7.5))),

IIf(C<Ref(Min(Min(L,Ref(L,-10)),Min(Ref(L,-5),Ref(L,-7.5))),-1),Max(Max(H,Ref(H,-10)),Max(Ref(H,-5),Ref(H,-7.5))),PREV));

a=Cross(Close,d);

b=Cross(d,Close);

state=IIf(BarsSince(a)<BarsSince(b),1,0);

s=state>Ref(state,-1);

ss=state<Ref(state,-1);

sss=state==Ref(state,-1);

col=IIf(state == 1 ,51,IIf(state ==0,4,1));

Plot(C,"",Col,60);

Buy = s;

Sell = ss;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-5);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-10);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-7.5);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=10);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=15);

PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-12.5);

///WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,","");

////WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",","");

///WriteIf( sss ,"No trading signals today.","") ;





dist = 2*ATR(5);

dist1 = 5*ATR(5);

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

{

if( Buy )

{

PlotText( "\nBuy:" + L[ i ] + "\nT= " + (L*1.005) + "\nSL= " + (L*0.9975), i, L[ i ]-dist, colorGreen, colorWhite );

}

if( Sell )

{

PlotText( "Sell:" + H[ i ] + "\nT= " + (H*0.995) + "\nSL= " + (H*1.0025), i, H[ i ]+dist1, colorRed, colorWhite );

}

}





Filter = s OR sss OR sss ;

AddColumn(C,"close",1.2);

AddColumn( IIf( s, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (s,colorYellow, colorPink ));

AddColumn( IIf( Ss, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (Ss,colorPink, colorWhite ));

AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));





_SECTION_BEGIN("trend");

uptrend=PDI(20)>MDI(10)AND Signal(29)<MACD(13);

downtrend=MDI(10)>PDI(20)AND Signal(29)>MACD(13);

Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",

IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */

styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();



Buy = s AND a AND uptrend ;

Short = ss AND b AND downtrend ;

Sell = ss AND b AND downtrend ;

Cover = s AND a AND uptrend ;



Buy=ExRem(Buy,Sell);

Sell=ExRem(Sell,Buy);

Cover=ExRem(Cover,Short);

Short=ExRem(Short,Cover);



Filter=Buy OR Sell;

Filter= Cover OR Short;



AddColumn( Buy, "Buy", 1);

AddColumn(Sell, "Sell", 1);

AddColumn(Close,"Close",1.2);

AddColumn(Volume,"Volume",1.0);





// Plot the Buy and Sell arrows.

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);

PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);



5-system (emabased 50)


_SECTION_BEGIN("MA Cross");

//Modified SH's 315 Strategy by Santhosh2010
// Traderji id :Santhosh2010




e1=EMA(C,3);
e2=EMA(H,50);
e3=EMA(L,50);

Plot(e1,"",colorYellow,styleDashed |styleThick);
Plot(e2,"",colorLightYellow,styleDots );
Plot(e3,"",colorLightYellow,styleDots );

Buy=Cross(e1,e2);
Sell=Cross(e3,e1);
Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);

/*
Heikin-Ashi(Koma-Ashi) with Moving Average Type
*/
SetChartOptions(0,chartShowArrows|chartShowDates);

// Calculate Moving Average
MAPeriod = Param("MA Period", 15, 1, 100);
MAOpen = EMA(Open, MAPeriod);
MAHigh = EMA(High, MAPeriod);
MALow = EMA(Low, MAPeriod);
MAClose = EMA(Close, MAPeriod);

HaClose = (MAOpen + MAHigh + MALow + MAClose) / 4;
HaOpen = AMA(Ref(HaClose, -1), 0.5);

// for graph collapse
for(i = 0; i <= MAPeriod; i++) HaClose = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen = (HaOpen[i - 1] + HaClose[i - 1]) / 2;
}
*/

HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));

// outs comments
"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = "+ Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = "+ HaClose;

// Plot graphs
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} HaOpen %g, HaHigh %g,
HaLow %g, HaClose %g (%.1f%%) {{VALUES}}",
HaOpen, HaHigh, HaLow, HaClose, SelectedValue(ROC( HaClose, 1))));
PlotOHLC(HaOpen, HaHigh, HaLow, HaClose, _DEFAULT_NAME(), ParamColor("Color",
colorBlack), styleCandle);

_SECTION_BEGIN("Colour Tap");
SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));
_SECTION_END();


Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover=Buy;
Short=Sell;
PlotShapes(IIf(Buy,shapeUpArrow ,shapeNone),colorWhite,0,L,-35);
PlotShapes(IIf(Sell,shapeDownArrow , shapeNone),colorWhite,0,H,-35);
_SECTION_END();

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


_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();



6-system (emabased)

_SECTION_BEGIN("MA Cross");

//Modified SH's 315 Strategy by Santhosh2010
// Traderji id :Santhosh2010




e1=EMA(C,3);
e2=EMA(H,15);
e3=EMA(L,15);

Plot(e1,"",colorYellow,styleDashed |styleThick);
Plot(e2,"",colorLightYellow,styleDots );
Plot(e3,"",colorLightYellow,styleDots );

Buy=Cross(e1,e2);
Sell=Cross(e3,e1);
Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);
SetBarFillColor(Col);
Plot(C,"Close",Col,64);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover=Buy;
Short=Sell;
PlotShapes(IIf(Buy,shapeUpArrow ,shapeNone),colorGreen,0,L,-35);
PlotShapes(IIf(Sell,shapeDownArrow , shapeNone),colorRed,0,H,-35);
_SECTION_END();

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


_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();


7-system (my system with adx)


_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorWhite ), styleThick | ParamStyle("Style") | GetPriceStyle() );


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

PositionSize = 350000;

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor=Optimize("Factor",4,0.1,10,0.1);
Pd=Optimize("ATR Periods",5,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

trend=1;


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

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

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

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

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

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

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

Plot(TrendUp,"Trend",colorBlue);
Plot(TrendDown,"Down",colorRed);


/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor1=Optimize("Factor1",1.5,5,10,2);
Pd1=Optimize("ATR Periods1",5,1,10,1);
Up1=(H+L)/2+(Factor1*ATR(Pd1));
Dn1=(H+L)/2-(Factor1*ATR(Pd1));
iATR1=ATR(Pd1);
TrendUp1=TrendDown1=Null;
trend1[0]=1;
changeOfTrend1=0;
flag1=flagh1=0;

for (i = 1; i <BarCount; i++) {
TrendUp1 = Null;
TrendDown1 = Null;

trend1=1;


if (Close>Up1[i-1]) {
trend1=1;
if (trend1[i-1] == -1) changeOfTrend1 = 1;

}
else if (Close<Dn1[i-1]) {
trend1=-1;
if (trend1[i-1] == 1) changeOfTrend1 = 1;
}
else if (trend1[i-1]==1) {
trend1=1;
changeOfTrend1 = 0;
}
else if (trend1[i-1]==-1) {
trend1=-1;
changeOfTrend1 = 0;
}

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

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

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

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

if (flag1==1)
{ Up1=(H+L)/2+(Factor1*iATR1);;
}
if (flagh1==1)
{ Dn1=(H+L)/2-(Factor1*iATR1);;
}
if (trend1==1) {
TrendUp1=Dn1;
if (changeOfTrend1 == 1) {
TrendUp1[i-1] = TrendDown1[i-1];
changeOfTrend1 = 0;
}
}
else if (trend1==-1) {
TrendDown1=Up1;
if (changeOfTrend1 == 1) {
TrendDown1[i-1] = TrendUp1[i-1];
changeOfTrend1 = 0;
}
}
}

//Plot(TrendUp1,"Trend",colorWhite);
//Plot(TrendDown1,"Down",colorWhite);


/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/

d=ADX(10);
d1=Ref(d,-1);
Buy = trend==1 AND trend1==1 AND d>d1 AND d>0;
Short=trend==-1 AND trend1==-1 AND d>d1 AND d>0;

//Buy = trend==1 AND trend1==1 ;
//Short=trend==-1 AND trend1==-1 ;
Sell=trend1==-1;
Cover=trend1==1;

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



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


Title = EncodeColor(colorWhite)+ "ST BY AK & JW PRODUCTIONS" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorBlack) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorWhite, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorWhite, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);

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

_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;
Plot(C,"",colorWhite,styleCandle);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();

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


res=HHV(High,4);
sup=LLV(Low,4);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), colorWhite, styleStaircase);


8-system (unknown)

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

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("Ichimoku");
prds = Param( "Standard Line Periods", 13, 5, 26, 1 );
turn = Param( "Turning Line Periods", 3, 3, 10, 1 );
delay = Param( "Delayed Line Periods", 12, 4, 25, 1 );
span = Param( "Spans Periods", 16, 10, 52, 1 );

TL = ( HHV( H, turn ) + LLV( L, turn ) ) / 2;
SL = ( HHV( H, prds ) + LLV( L, prds ) ) / 2;
DL = Ref( C, delay );
Sp1 = ( SL + TL ) / 2;
Sp2 = ( HHV( H, span ) + LLV( L, span ) ) / 2;

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

Plot( C, "Close", colorBlack, styleNoTitle | GetPriceStyle() );
Plot( SL, "SL", colorRed, styleThick | styleNoLabel );
Plot( TL, "TL", colorGreen, styleThick | styleNoLabel );
color = IIf( Sp1 > Sp2, ParamColor( "Span1 Color", ColorRGB( 0, 255, 0 ) ), ParamColor( "Span2 Color", ColorRGB( 255, 104, 32 ) ) );
PlotOHLC ( Sp1, Sp1, Sp2, Sp2, "Cloud", Color, styleCloud | styleNoLabel, Null, Null, delay, -2 );
_SECTION_END();


//Magfied Market Price
GfxSetTextAlign( 6 );// left alignment
FS=Param("Font Size",15,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode(0); // transparent
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
Hor=Param("Horizonta Position",860,1,1200,1);
Ver=Param("Vertica Position",27,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
FS2=Param("Font Size2",15,11,100,1);
GfxSelectFont("Times New Roman", FS2,11, 700, True );
GfxSetBkMode( colorGreen );
Hor1=Param("Horizontal Position",835,1,1200,1);
Ver1=Param("Vertical Position",7,1,830,1);
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor1 , Ver1+45 );

dec = (Param("Decimals",2,0,7,1)/10)+1;

Title =EncodeColor(255)+ "Muneshwaraya Namaha" + " - " + Name() + " " + EncodeColor(30) + Date() +
" " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(255)+ " Open = "+ EncodeColor(30)+ WriteVal(O,dec) +
EncodeColor(255)+ " High = "+ EncodeColor(30)+ WriteVal(H,dec) +
EncodeColor(255)+ " Low = "+ EncodeColor(30)+ WriteVal(L,dec) +
EncodeColor(255)+ " Close = "+ EncodeColor(35)+ WriteVal(C,dec)+
EncodeColor(255)+ " Volume = "+ EncodeColor(30)+ WriteVal(V,1) ;

_SECTION_BEGIN("Pivot Trading System");

// User defined parameters.

GraphXSpace = 10; //defines how much extra space should be added above and below graph line (in percent).

dist = 0.25*ATR(10);
Capital=Param("Total capital",100000,10000,1000000,1000);
drawdown=Param("Max. loss per trade as % of Capital", 1.0,0.5,25.0,0.1);
room=Param("Room for S/L as % of Pivot value",0.0015,0.0001,0.025,0.001);

PH= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

PL= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


phfilter=PH+(room*PH);
plfilter=PL-(room*PL);

for (a=4;a<BarCount;a++)
{
if ((H[a-2] >= H[a-4]) AND
(H[a-2] >= H[a-3]) AND
(H[a-2] >= H[a-1]) AND
(H[a-2] >= H[a]))
PlotText("", a-2, H[a-2], colorGreen);

if ((L[a-2] <= L[a-4]) AND
(L[a-2] <= L[a-3]) AND
(L[a-2] <= L[a-1]) AND
(L[a-2] <= L[a]))
PlotText("", a-2, L[a-2]-dist[a-2], colorRed);
}

//Condition for buy : Enter when Close crosses latest pivot high.
Buy = C> (PH+(room*PH));

initialStopBuy=Ref(PL,2)-(Ref(PL,2)*room/100);
trailStopBuy=IIf(C>PH,Ref(initialStopBuy,-1),initialStopBuy);

newStopBuy=trailStopBuy;

BuyLimitCapital=int(Capital/C);
SLbuy=round(C-initialStopBuy);
BuyLimitSL=int((Capital*drawdown)/(100*SLbuy));

//Condition for sell : Exit when previous pivot low is cracked.
Sell = C< (PL-(room*PL));

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

Short = Sell;
Cover = Buy;

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


shape = Buy * shapeCircle + Sell * shapeCircle;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );

_SECTION_END();


_SECTION_BEGIN("Macd coloured price");
//============================================candle sticks=======================

a = Param("fast macd period",3,1,100,1);
b = Param("slow macd period",34,1,100,1);

Up_MACD_TRIX = MACD( a, b ) > Ref(MACD(a,b),-1);

Down_MACD_TRIX = MACD( a, b ) < Ref(MACD(a,b),-1);

Colormacd = IIf(Up_MACD_TRIX,colorLime,IIf(Down_MACD_TRIX,colorRed,colorCustom12));


PlotOHLC( Open, High, Low, Close, "", Colormacd, styleBar );

_SECTION_END();


_SECTION_END();
 
Last edited:

pareshR

Well-Known Member
#2
guys i have only 1 month of intraday data on stocks i want to backtest sum afl s if anyone have 1yr + intraday data of nifty stocks (axisbank,dlf,etc just backtest only 4-5 gud stocks)only then plz backtest following afl and post the backtesting results in the thread itself .will be helpfull for me and all guys
thank you

backtest on 3m and 5m tf.
conditions-


_SECTION_END();


Hello

" yet i not found " HOLLY GRILL afl "

1- Most of Afls are good but when market range bound then its performance are not good..

2- i also tried so many afls but no use, so better stick with one/two Afls that u trust on it.

3- b4 i joined so many Tips providers, they charges 8-10K/month but just @50-60% accuracy..

thx
 

bunti_k23

Well-Known Member
#3
Hello

" yet i not found " HOLLY GRILL afl "

1- Most of Afls are good but when market range bound then its performance are not good..

2- i also tried so many afls but no use, so better stick with one/two Afls that u trust on it.

3- b4 i joined so many Tips providers, they charges 8-10K/month but just @50-60% accuracy..

thx
brother thanks for the reply ,iam just confused which system shd i follow .even i made one , i know all the facts i will pick 1 from these systems . i just want to know the backtesting results(not net profit obviously) i want to know how wrong and how much right trades taken by the system etc etc.....
 

pareshR

Well-Known Member
#4
brother thanks for the reply ,iam just confused which system shd i follow .even i made one , i know all the facts i will pick 1 from these systems . i just want to know the backtesting results(not net profit obviously) i want to know how wrong and how much right trades taken by the system etc etc.....

Hello

Yes, u r right..

select max 2 Afls and open with one screen
compare it with diff diff parameters,
select any one scripts, note down that parameters,

after that go for 2nd, 3rd .... scripts


http://www.traderji.com/amibroker/94785-amibroker-ib.html also good

thx
 

toptrader

Active Member
#5
I would be careful to examine the afl only with 2 months, I find difficulty with 2 years, let alone with two months you will only misleading results; you need at least 4-5 years of historical intraday data
 

pareshR

Well-Known Member
#6
I would be careful to examine the afl only with 2 months, I find difficulty with 2 years, let alone with two months you will only misleading results; you need at least 4-5 years of historical intraday data

Hi

Yes. very true
but main prob with where to get 4-5 years of historical intraday data!!

if you have/ you know link etc then pls provide axis, icici, tatamot, tatasteel, rinfra, rcap

thx
 

bunti_k23

Well-Known Member
#7
#10
let me break down the posts into their constituent afls

and check them one by one



1- system (my own system)
Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorWhite ), styleThick | ParamStyle("Style") | GetPriceStyle() );


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));



TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor=Optimize("Factor",4,0.1,10,0.1);
Pd=Optimize("ATR Periods",5,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

trend[i]=1;


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

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

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

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

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

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

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

Plot(TrendUp,"Trend",colorBlue);
Plot(TrendDown,"Down",colorRed);


/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor1=Optimize("Factor1",1.5,5,10,2);
Pd1=Optimize("ATR Periods1",5,1,10,1);
Up1=(H+L)/2+(Factor1*ATR(Pd1));
Dn1=(H+L)/2-(Factor1*ATR(Pd1));
iATR1=ATR(Pd1);
TrendUp1=TrendDown1=Null;
trend1[0]=1;
changeOfTrend1=0;
flag1=flagh1=0;

for (i = 1; i <BarCount; i++) {
TrendUp1[i] = Null;
TrendDown1[i] = Null;

trend1[i]=1;


if (Close[i]>Up1[i-1]) {
trend1[i]=1;
if (trend1[i-1] == -1) changeOfTrend1 = 1;

}
else if (Close[i]<Dn1[i-1]) {
trend1[i]=-1;
if (trend1[i-1] == 1) changeOfTrend1 = 1;
}
else if (trend1[i-1]==1) {
trend1[i]=1;
changeOfTrend1 = 0;
}
else if (trend1[i-1]==-1) {
trend1[i]=-1;
changeOfTrend1 = 0;
}

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

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

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

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

if (flag1==1)
{ Up1[i]=(H[i]+L[i])/2+(Factor1*iATR1[i]);;
}
if (flagh1==1)
{ Dn1[i]=(H[i]+L[i])/2-(Factor1*iATR1[i]);;
}
if (trend1[i]==1) {
TrendUp1[i]=Dn1[i];
if (changeOfTrend1 == 1) {
TrendUp1[i-1] = TrendDown1[i-1];
changeOfTrend1 = 0;
}
}
else if (trend1[i]==-1) {
TrendDown1[i]=Up1[i];
if (changeOfTrend1 == 1) {
TrendDown1[i-1] = TrendUp1[i-1];
changeOfTrend1 = 0;
}
}
}


//Plot(TrendUp1,"Trend",colorWhite);
//Plot(TrendDown1,"Down",colorWhite);


/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/

Buy = trend==1 AND trend1==1 ;
Short=trend==-1 AND trend1==-1;
Sell=trend1==-1;
Cover=trend1==1;

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



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


Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorWhite, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorWhite, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);


supertrend = Optimize( "supertrend", 4, 3, 4, 1 );



_SECTION_END();

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

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI() AND MACD()>Signal();
downtrend=MDI()>PDI() AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

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


_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();

////////////////////
2- system (turtle trading system)

Code:
/*
Formula Name: Turtle trading system
Author/Uploader: DrZingaro
E-mail: [email protected]
Date Added: 2009-01-12
Origin: Turtle trading experimemnt Chandelier exit based on Chuck Lebeau's work
Keywords: Trend trading
Level: Basic
Flags: System
*/
//=============================SETUP================ ======================
//Strengths: volatility-based.
//Weaknesses: lag AND since volatility increases at the end of a trend, traders exits early.
//Description: Indicator is used to keep track of a trade. Once a stop is hit, it waits for the next entry Signal (Short OR long). Use on DAILY values only.
//Algorithm: Lebeau recommends that an exits hangs from the HHV (long) OR LLV (Short) since the trade was triggered. Some traders use the Highest Close as the base for hanging the exit.

pds = 20;
MAFAST = EMA( Close, 20 );
MASLOW = EMA( Close, 40 );

DonchianUpper = HHV( Ref( H, -1 ), pds ); // Highest high value of highs in last 20 periods
DonchianLower = LLV( Ref( L, -1 ), pds ); // Lowest low value of low in last 20 periods
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, colorBlue, IIf( DnTrend, colorOrange, colorCustom11 ) );

// Plots a 20 period Donchian channel
Plot( C, "Price", Color, styleBar | styleThick );
Plot( DonchianUpper, "Donchian U", ParamColor( "DU Color", colorBlue ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianMiddle, "Donchian M", ParamColor( "DM Color", colorBrightGreen ), ParamStyle( "DM Style", styleNoLine ) );
Plot( DonchianLower, "Donchian L", ParamColor( "DL Color", colorRed ), ParamStyle( "DL Style", styleLine ) );

Title = WriteVal( DonchianUpper, 1.2 ) + WriteVal( DonchianLower, 1.2 ) + WriteVal( DonchianMiddle, 1.2 );
//=============================TRIGGERS AND ENTRIES=======================
Buy = High > Ref( HHV( High, 20 ), -1 ) AND MAFAST > MASLOW; // Enters long trade

Short = Low < Ref( LLV( Low, 20 ), -1 ) AND MAFAST < MASLOW; // Enters short trade



//=============================EXITS================ ======================
_SECTION_BEGIN( "Chandelier Exit" );

SetBarsRequired( 50, 50 );

Multiple = Param( "Multiple", 3, 0.5, 10, 0.1 ); // How many ATR’s to be allowed below the highest high since latest "buy" bar
ATRPeriods = Param( "ATR Periods", 20, 1, 50, 1 ); // How many periods to use for the ATR

stopArray = Null;
atrArray = ATR( ATRPeriods );
HHArray = Null;
LLArray = Null;
exitArray = Null;
trendDirection = 0;

for ( i = 0; i < BarCount; i++ )
{
if ( Short[i] )
{
// we just triggered a short trade. Set up starting values
stopArray[i] = Low[i] + ( Multiple * atrArray[i] );
LLArray[i] = Low[i]; // initialize the lowest low array
trendDirection = 0 - 1; // going short. Base bar.
}

if ( Buy[i] )
{
// we just triggered a long trade. Set up starting values
stopArray[i] = High[i] - ( Multiple * atrArray[i] );
HHArray[i] = High[i]; // initialize the highest high array
trendDirection = 1; // going long. Base bar flag is now set.
}

exitArray[i] = 0;

if ( trendDirection > 0 )
{
// keep track of the highest high, highest close, highest low, etc..
if ( trendDirection > 1 )
{
// We are in the trade (2nd day or later)
if ( Low[i] < stopArray[i-1] )
{
//stop got hit. Reset the trade.
trendDirection = 0; // OK. wait until we trigger another trade.
exitArray[i] = 1;
}
else
{
// keep track of the HHV since trade was entered.
if ( High[i] > HHArray[i-1] )
HHArray[i] = High[i];
else
HHArray[i] = HHArray[i-1];

// Compute the stop based on the HHV.
stopArray[i] = HHArray[i] - ( Multiple * atrArray[i] );
}
}

trendDirection = trendDirection + 1;
}

if ( trendDirection < 0 )
{
// keep track of the lowest low, lowest close, lowest high, etc..
if ( trendDirection < 0 - 1 )
{
// We are in the trade (2nd day or later)
if ( High[i] > stopArray[i-1] )
{
// our stop got hit. Reset the trade.
trendDirection = 0;
exitArray[i] = 0 - 1;
}
else
{
// keep track of the LLV since trade was entered.
if ( Low[i] < LLArray[i-1] )
LLArray[i] = Low[i];
else
LLArray[i] = LLArray[i-1];

// Compute the stop based on the LLV.
stopArray[i] = LLArray[i] + ( Multiple * atrArray[i] );
}
}

trendDirection = trendDirection - 1;
}

if ( trendDirection == 0 )
{
stopArray[i] = 0;
LLArray[i] = 0;
HHArray[i] = 0;
}
}

Sell = Cover = exitarray;

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

PlotShapes( Buy*shapeUpArrow, colorBrightGreen, 0, Low );
PlotShapes( Short*shapeDownArrow, colorRed, 0, High );
PlotShapes( abs( exitArray )*shapeHollowCircle, colorYellow, 0, ValueWhen( stopArray, stopArray, 1 ), 0 );
Plot( stopArray, "Chand", ParamColor( "Chand Color:", colorYellow ), ParamStyle( "Chand Style", styleDashed ) );

_N( Title = EncodeColor( colorYellow ) + StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}}--Turtle_System_Rev_A \n OP= %g Hi= %g Lo= %g CL= %g (%.1f%%) \n Vol= " + WriteVal( V, 1.0 ) + "\n" + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );//=cnb

//_N(Title = "LLArray: " + LLArray + ", HHArray:" + HHArray +", stopArray"+stopArray);

//PlotShapes(shapeCircle * Sell, colorRed);
//PlotShapes(shapeCircle * Cover, colorGreen);
_SECTION_END();
3-system (kbl system)

Code:
_SECTION_BEGIN("HA");


tchoice=Param("Title Selection ",2,1,2,1);

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

for( i = 0; i < BarCount; i++ )
{
if( HH[i] ) PlotText( "HH", i, H[ i ]+dist[i], colorCustom12 );
if( LH[i] ) PlotText( "LH", i, H[ i ]+dist[i], colorCustom12 );
if( HL[i] ) PlotText( "HL", i, L[ i ]-dist[i], colorBlack );
if( LL[i] ) PlotText( "LL", i, L[ i ]-dist[i], colorBlack );

}

//calculates floor pivots from previous days data & plots it on the present intraday chart.
//RED LINE = RESISTANCE
//RED DASHED LINE = MINI RESISTANCE
//BLUE LINE = SUPPORT
//BLUE DASHED LINE = MINI SUPPORT
//YELLOW DOTTED LINE = PIVOT
//RED DOTTED LINE = PREVIOUS Day High
//BLUE DOTTED LINE = PREVIOUS Day Low
//BLACK DOTTED LINE = PREVIOUS Day Close


//2 - IN - 1 PRICE CHART
Pstyle = ParamToggle("Heikin Ashi","On|Off",1);
if(Pstyle==0){
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 ) );
//PlotOHLC(HaOpen,HaHigh,HaLow,HaClose,"",IIf(HaClos e > HaOpen,colorGreen,colorBrown),styleCandle);

//Sell = (abs(HaOpen -HaClose )<= ((HaHigh -HaLow )*0.1));
//Buy = (abs(HaOpen -HaClose )<= ((HaHigh -HaLow )*0.1)) ;

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

//PlotShapes( IIf( Sell, shapeDownArrow+ shapePositionAbove, shapeNone), colorCustom12 );
//Plot(EMA(HaClose,20), "", colorBlue , styleLine|styleThick );
//Plot(Wilders(H,260.6), "",colorCustom12 , styleDashed|styleThick );
//Plot(EMA(HaClose,10), "",colorTan, styleLine|styleThick );



TimeFrameSet(inHourly);
Hh=HHV (L,24);
Ll =LLV (H,24);
TimeFrameRestore();
Hh1=(TimeFrameExpand( Hh, inHourly));
Ll1=(TimeFrameExpand( Ll, inHourly));

Plot(Hh1 , "27dayssellbelclose",colorRed, 4+8+2048);
Plot(Ll1 , "27daysbuyabvclose",colorGreen, 4+8+2048);

Buy=Cross(C,LL);
Sell=Cross(HH,C);
Filter=Buy OR Sell;



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


Pivot = ParamToggle("Pivot", "weekly|monthly", 1);

if(Pivot)
{
H1 = TimeFrameGetPrice("H", inMonthly, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inMonthly, -1); // low
C1= TimeFrameGetPrice("C", inMonthly, -1); // close


}
else
{
H1 = TimeFrameGetPrice("H", inWeekly, -1); // yesterdays high
L1 = TimeFrameGetPrice("L", inWeekly, -1); // low
C1= TimeFrameGetPrice("C", inWeekly, -1); // close
}

// PIVOT Calculation
P = ( H1+ L1+ C1 )/3;
R1 = P+(H1-L1)/2-(P-C1)/2;
R2 = H1-L1+P;
R3 = H1-L1+R1;
R4 = H1-L1+R2;
R5 = H1-L1+R3;
R6 = H1-L1+R4;
R7 = H1-L1+R5;
R8 = H1-L1+R6;
R9 = H1-L1+R7;
R10 = H1-L1+R8;



S1 = P -(H1-L1)/2-(P-C1)/2;
S2 = P -(H1-L1);
S3 = S1 -(H1-L1);
S4 = S2 -(H1-L1);
S5 = S3 -(H1-L1);
S6 = S4 -(H1-L1);
S7 = S5 -(H1-L1);
S8 = S6 -(H1-L1);
S9 = S7 -(H1-L1);
S10 =S8 -(H1-L1);













// PIVOT mid points
MIDR1 = (P+R1)/2;
MIDR2 = (R1+R2)/2;
MIDR3 = (R2+R3)/2;
MIDR4 = (R3+R4)/2;
MIDR5 = (R4+R5)/2;
MIDR6 = (R5+R6)/2;
MIDR7 = (R6+R7)/2;
MIDR8 = (R7+R8)/2;
MIDR9 = (R8+R9)/2;
MIDR10 = (R9+R10)/2;




MIDS1 = (P+S1)/2;
MIDS2 = (S1+S2)/2;
MIDS3 = (S2+S3)/2;
MIDS4 = (S3+S4)/2;
MIDS5 = (S4+S5)/2;
MIDS6 = (S5+S6)/2;
MIDS7 = (S6+S7)/2;
MIDS8 = (S7+S8)/2;
MIDS9 = (S8+S9)/2;
MIDS10 = (S9+S10)/2;













n=130;
per =11.5;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSI a(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Buy = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(S1==tr endlineS,-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1);
Sell = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Re f(Ref(Ref(Ref(Ref(S11==trendlineR,-1 ),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1 ),-1 ),-1 ),-1 ),-1 );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );
//PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGold, colorPink) );
dist = 2.5*ATR(10);
dist1 = 0.7*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] )
{
PlotText( "\n Heavy Fire Up Ahead " , i, L[ i ]-dist[i], colorBlack, colorGreen );
//Say("Heavy Fire Up Ahead");
}
if( Sell[i] )
{
PlotText( " Heavy Down Fall Ahead " , i, H[ i ]+dist1[i], colorBlack, colorRed );
//Say("Heavy Down Fall Ahead");
}
}

n=45;
per =20;
x = Cum(1);
s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n));
s11=IIf(RSIa(H,n)<Max(RSIa(C,n),RSIa(O,n)),Max(RSI a(C,n),RSIa(O,n)),RSIa(H,n));
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
//Plot(trendlineR , "trendlineR" ,colorRed , styleLine);
//Plot(ValueWhen( (S1==trendlineS ), L),"", colorGreen, styleDashed|styleNoRescale|styleThick);
//Plot(ValueWhen((S11==trendlineR ), H),"", colorRed, styleDashed|styleNoRescale|styleThick);
Buy = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(S1==tr endlineS,-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1);
Sell = Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Ref(Re f(Ref(Ref(Ref(Ref(S11==trendlineR,-1 ),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1),-1 ),-1 ),-1 ),-1 ),-1 );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
// Plot the ribbon
ribboncol= IIf( BarsSince(Buy)<BarsSince(Sell), colorGreen, colorRed );
Plot( 3, "", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 );
PlotShapes(IIf(Buy, shapeSquare,shapeNone) ,colorBlue,0, Close, Offset=-10) ;
PlotShapes(IIf(Buy, shapeSmallUpTriangle,shapeNone) ,colorLime,0, Close, Offset=-10) ;
PlotShapes(IIf(Sell, shapeSquare,shapeNone),colorRed,0, Close, Offset=-1) ;
PlotShapes(IIf(Sell, shapeSmallDownTriangle,shapeNone),colorLime,0, Close, Offset=-1) ;
PlotShapes( Buy * shapeNone + Sell * shapeNone, IIf( Buy, colorBlue, colorPink) );
dist = 0.8*ATR(10);
dist1 = 2*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] )
{
PlotText( "\nHNI Buy 10 Lots @" + C[ i ] + "\nTGT= " + (C[i]*1.0045) + "\nSL= " + (C[i]*0.9970), i, L[ i ]-dist[i], colorGreen, colorBlack );
}
if( Sell[i] )
{
PlotText( "HNI Sell 10 Lots @" + C[ i ] + "\nT= " + (C[i]*0.995) + "\nSL= " + (C[i]*1.0025), i, H[ i ]+dist1[i], colorRed, colorBlack );
}
}




_SECTION_END();






Uphigh = HHV(C,90);
downhigh = LLV (C, 40);
//Buy = C>= Uphigh;
//Sell = C<= downhigh;
Buy = ExRem (Buy,Sell);
Sell = ExRem (Sell,Buy);


_SECTION_BEGIN("BACK COLOR");
SetChartBkGradientFill( ParamColor("BgTop", colorPlum),

ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorPlum));

Title = (EncodeColor(colorGold)+Day() + EncodeColor(colorWhite) + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorWhite)+",Open "+Open +" , High "+H+" , Low "+L+" , Close "+C+" "+"{{VALUES}}");

BuyPrice = Open;
SellPrice = Open;

Derived=WMA(WMA(WMA(((H+L)/2)+(O-C),92),1),1);
i=WMA(Derived,3);
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5;
Lower=(Derived-StDev(Derived,7))-ATR(2)/1;

color=IIf(BarsSince(Cross(Lower,Low))>
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed);
Plot(C,"",color,64);



//WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,","");
//WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",","");
//WriteIf( sss ,"No trading signals today.","") ;



SetBarsRequired( 600, 0 );

GraphXSpace = 8;
SetChartOptions( 0, chartShowArrows | chartShowDates );


//============== TITLE ==============

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGold) );
Hor=Param("Horizontal Position",970,1,1200,1);
Ver=Param("Vertical Position",50,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( colorWhite );
GfxSetTextColor(ParamColor("Color",colorBlack) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );

_SECTION_END();




_SECTION_BEGIN("Price Line");
dp= Param("dps",3,0,1000,1);
PriceLineColor=ParamColor("PriceLineColor",colorOr ange);
PriceLevel = ParamField("PriceField", field = 3 );
PriceLeve2 = ParamField("PriceField", field = dp );
Daysback = Param("Bars Back",1,10,500,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",style Line|styleDashed|styleNoTitle|styleNoLabel|styleTh ick,maskAll));

side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist[i], colorGold );

}

_SECTION_END();





































/****************/
/* */
/* ALERT OUTPUT */
/* */
/****************/

TxtX = Param("Text Left", 600, 0, 1000, 10);
TxtY = Param("Text Top", 60, 1, 650, 10);

GfxSelectFont("Tahoma", 14, 700 );
GfxSetBkMode(1);

if(LastValue(Buy) OR SelectedValue(Buy))
{
GfxSetTextColor(colorGold);
GfxTextOut("Waiting For Next Signal", TxtX, TxtY);
Say("");
}

else if(LastValue(Sell) OR SelectedValue(Sell))
{
GfxSetTextColor(colorGold);
GfxTextOut("Waiting For Next Signal", TxtX, TxtY);
Say("");
}

else
{
GfxSetTextColor(colorGold);
GfxTextOut("Waiting For Next Signal ", TxtX, TxtY);
GfxTextOut("", TxtX, TxtY);
}
_SECTION_BEGIN("sys");

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



_SECTION_END();




_SECTION_BEGIN("Background text");
C11=ParamColor("up panel",colorBlack );
C12=ParamColor("dn panel",colorBlack );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",8,1,30,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSelectFont("Tahoma", 12, 500, False, False, 0);
GfxSetTextColor(colorCustom12);
GfxSetTextAlign( 6 );
GfxSelectFont("Tahoma", 15, 600, False, False, 0);
GfxSetTextColor(colorWhite);
GfxSetTextAlign( 6 );

GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorBrightGreen);

GfxSelectFont("Tahoma", 12, 400, False, False, 0);
GfxSetTextColor(colorRed);




pricechange=(C-Ref(C,-1))*100/Ref(C,-1);
changeponit=C-Ref(C,-1);
Vlp=Param("Volume lookback period",15,10,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;

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

GfxGradientRect( 1, 1, 1400, 40, colorViolet, colorBlack);
GfxSetBkMode(0);
GfxSelectFont( "Georgia", 18, 800, False );
GfxSetTextColor( colorGold );
GfxTextOut( "General ", x+600, y+10 );
GfxSelectFont( "Tahoma", 16, 800, False );
GfxSetTextColor( colorGold );
GfxTextOut( Name(), x+100, y+10 );
GfxSelectFont( "Century Gothic", 15, 100, False );
GfxSetTextColor( colorGold );
GfxTextOut( Date(), x+1000, y+10 );
GfxSelectFont( "Comic Sans MS", 15, 500, False );
GfxSetTextColor( colorYellow );
GfxTextOut( Interval(2), x+275, y+10 );
//------------------------------------------------------------ H, L, O, C----------------------
GfxGradientRect( 1, 40, 1400, 55, colorViolet, colorBlack );
GfxSetBkMode(0);
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "High:"+WriteVal(H,1.2), x+100, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Low:"+WriteVal(L,1.2), x+200, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Open:"+WriteVal(O,1.2), x+300, y+40 );
GfxSelectFont( "Areal", 9, 200, False );
GfxSetTextColor( colorWhite );
GfxTextOut( "Close:"+WriteVal(C,1.2), x+400, y+40 );
GfxSelectFont( "comic sans ms", 12, 100, False );
//-----------------------------------------------------------Valume-------------------------------


// set criteria to scan for big stock only;
BigStock = MA( V, 10 ) * MA( C, 10 ) > 100;

//---------------Color------------------------
per1 = 6;
per2 = 2;
Om = MA( O, per1 );
hm = MA( H, per1 );
lm = MA( L, per1 );
Cm = MA( C, per1 );

// 1. Heiken Ashi
HACLOSE = ( Om + Hm + Lm + Cm ) / 4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );


Of = MA( Haopen, per2 );
Cf = MA( Haclose, per2 );
Lf = IIf( haOpen < haClose, MA( Halow, per2 ), MA( Hahigh, per2 ) );
Hf = IIf( haOpen < haClose, MA( Hahigh, per2 ), MA( Halow, per2 ) );
//Color = IIf( Cf > Of, colorGreen, colorRed );


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

TrailStop = HHV( C - 2 * ATR( 10 ), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR( 10 );

/* **********************************
Code to automatically identify pivots
********************************** */

// -- what will be our lookback range for the hh and ll?
farback = 140; //How Far back to go
nBars = 12; //Number of bars

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

// -- More for future use, not necessary for basic plotting
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;

// -- looking back from the current bar, how many bars
// back were the hhv and llv values of the previous
// n bars, etc.?
aHHVBars = HHVBars( O, nBars );
aLLVBars = LLVBars( O, nBars );
aHHV = HHV( O, nBars );
aLLV = LLV( O, nBars );

// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of
// _Trace output will show a value of 0
aVisBars = Status( "barvisible" );
nLastVisBar = LastValue( Highest( IIf( aVisBars, BarIndex(), 0 ) ) );
_TRACE( "Last visible bar: " + nLastVisBar );

// -- Initialize value of curTrend
curBar = ( BarCount - 1 );
curTrend = "";

if ( aLLVBars[curBar] < aHHVBars[curBar] )
{
curTrend = "D";
}
else
{
curTrend = "U";
}

// -- Loop through bars. Search for
// entirely array-based approach
// in future version
for ( i = 0; i < BarCount; i++ )
{
curBar = ( BarCount - 1 ) - i;
// -- Have we identified a pivot? If trend is down...

if ( aLLVBars[curBar] < aHHVBars[curBar] )
{
// ... and had been up, this is a trend change
if ( curTrend == "U" )
{
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}

// -- or current trend is up
}
else
{
if ( curTrend == "D" )
{
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}

// -- If curTrend is up...else...
}

// -- loop through bars
}

// -- 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++;
}
}

//============== EXPLORATION ==============
Buy = Cover = BigStock AND aLPivs == 1;

Sell = Short = BigStock AND aHPivs == 1;

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

//============== Plot price ==============
n = 15;

a = C > ( MA( H, n ) + MA( L, n ) ) / 2;// then Buy next bar at market;

b = C < ( MA( H, n ) + MA( L, n ) ) / 2;// then Sell Short next bar at market;

state = IIf( BarsSince( a ) < BarsSince( b ), 1, 0 );

Longs = state == 1;

shorts = state == 0;
4-system (intraday afl)

Code:
_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);

SetBarsRequired(sbrAll,sbrAll);

SetBarFillColor(IIf(C>O,ParamColor("Bar Up Color", colorBrightGreen),IIf(C<=O,ParamColor("Bar Down Color", colorRed),colorLightGrey)));

Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color", colorBlack),IIf(C<=O,ParamColor("Shadow Down Color", colorBlack),colorLightGrey)),64,0,0,0);

SetChartBkColor(ParamColor("Panel Color ",colorDarkGrey));

SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("Lower Chart",colorDarkGrey));

GraphXSpace=Param("GraphXSpace",20,-10,25,1);



_SECTION_BEGIN("Ravi's EMA's");

EMA1 = EMA(H,34);

EMA2 = EMA(L,34);

EMA3 = EMA(C,34);



Plot( EMA1, "EMA1" ,ParamColor( "Color1", colorRed ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );

Plot( EMA2, "EMA2" ,ParamColor( "Color2", colorGreen ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );

Plot( EMA3, "EMA3" ,ParamColor( "Color3", colorBlue ), ParamStyle("Style", styleDashed|styleThick) | styleNoRescale );

_SECTION_END();



_SECTION_BEGIN("Ravitrend");

procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendM ode,CalcPrice)

{

global buffer_line_down;

global buffer_line_up;

buffer_line_down = Null;

buffer_line_up = Null;



PHASE_NONE = 0;

PHASE_BUY = 1;

PHASE_SELL = -1;



phase=PHASE_NONE;

band_upper = 0;band_lower = 0;



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

{

band_upper = CalcPrice[i] + ATR_Multiplier * tr[i];

band_lower = CalcPrice[i] - ATR_Multiplier * tr[i];



if(phase==PHASE_NONE)

{

buffer_line_up[i] = CalcPrice[i];

buffer_line_down[i] = CalcPrice[i];

}

if(phase!=PHASE_BUY && Close[i]>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1]))

{

phase = PHASE_BUY;

buffer_line_up[i] = band_lower;

buffer_line_up[i-1] = buffer_line_down[i-1];

}

if(phase!=PHASE_SELL && Close[i]<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))

{

phase = PHASE_SELL;

buffer_line_down[i] = band_upper;

buffer_line_down[i-1] = buffer_line_up[i-1];

}

if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )

{

if(band_lower>buffer_line_up[i-1])

{

buffer_line_up[i] = band_lower;

}

else

{

buffer_line_up[i] = buffer_line_up[i-1];

}

}

if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )

{

if(band_upper<buffer_line_down[i-1])

{

buffer_line_down[i] = band_upper;

}

else

{

buffer_line_down[i] = buffer_line_down[i-1];

}

}

}

}



TrendMode = ParamToggle("TrendMode","Off|On",1);

ATR_Multiplier = Param("ATR_Multiplier",.01,0.1,1,0.1);

ATR_Period = Param( "ATR_Period",1,1,1,1);

tr = ATR(ATR_Period);



CalcPrice = (H+L)/2;

calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendM ode,CalcPrice);



Plot(buffer_line_up,"\ntu",ColorRGB(28,134,238),st yleThick);

Plot(buffer_line_down,"\ntd",ColorRGB(205,51,51),s tyleThick);



Plot( 2,"",IIf(buffer_line_up,colorGreen,colorBlack),sty leOwnScale|styleArea|styleNoLabel, -0.5, 100 );

Plot( 4,"",IIf(buffer_line_down,colorRed,colorBlack),sty leOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();



TimeFrameSet(inDaily);

DayHigh = LastValue(H);

DayLow = LastValue(L);

TimeFrameRestore();



Title = Date() + ", Op=" + Open + ", Hi=" + High + ", Lo=" + Low + ", LTP=" + Close + ", Change= " + SelectedValue( ROC( C, 1 ) ) + "%" + "\n Today`s High=" + DayHigh + ", Today`s Low=" + DayLow + " © " ;





prev=AMA2(C,1,0);

d=IIf(C>Ref(Max(Max(H,Ref(H,-10)),Max(Ref(H,-5),Ref(H,-7.5))),-1),Min(Min(L,Ref(L,-10)),Min(Ref(L,-5),Ref(L,-7.5))),

IIf(C<Ref(Min(Min(L,Ref(L,-10)),Min(Ref(L,-5),Ref(L,-7.5))),-1),Max(Max(H,Ref(H,-10)),Max(Ref(H,-5),Ref(H,-7.5))),PREV));

a=Cross(Close,d);

b=Cross(d,Close);

state=IIf(BarsSince(a)<BarsSince(b),1,0);

s=state>Ref(state,-1);

ss=state<Ref(state,-1);

sss=state==Ref(state,-1);

col=IIf(state == 1 ,51,IIf(state ==0,4,1));

Plot(C,"",Col,60);

Buy = s;

Sell = ss;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-5);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-10);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-7.5);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=10);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=15);

PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-12.5);

///WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,","");

////WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",","");

///WriteIf( sss ,"No trading signals today.","") ;





dist = 2*ATR(5);

dist1 = 5*ATR(5);

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

{

if( Buy[i] )

{

PlotText( "\nBuy:" + L[ i ] + "\nT= " + (L[i]*1.005) + "\nSL= " + (L[i]*0.9975), i, L[ i ]-dist[i], colorGreen, colorWhite );

}

if( Sell[i] )

{

PlotText( "Sell:" + H[ i ] + "\nT= " + (H[i]*0.995) + "\nSL= " + (H[i]*1.0025), i, H[ i ]+dist1[i], colorRed, colorWhite );

}

}





Filter = s OR sss OR sss ;

AddColumn(C,"close",1.2);

AddColumn( IIf( s, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (s,colorYellow, colorPink ));

AddColumn( IIf( Ss, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (Ss,colorPink, colorWhite ));

AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));





_SECTION_BEGIN("trend");

uptrend=PDI(20)>MDI(10)AND Signal(29)<MACD(13);

downtrend=MDI(10)>PDI(20)AND Signal(29)>MACD(13);

Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",

IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */

styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();



Buy = s AND a AND uptrend ;

Short = ss AND b AND downtrend ;

Sell = ss AND b AND downtrend ;

Cover = s AND a AND uptrend ;



Buy=ExRem(Buy,Sell);

Sell=ExRem(Sell,Buy);

Cover=ExRem(Cover,Short);

Short=ExRem(Short,Cover);



Filter=Buy OR Sell;

Filter= Cover OR Short;



AddColumn( Buy, "Buy", 1);

AddColumn(Sell, "Sell", 1);

AddColumn(Close,"Close",1.2);

AddColumn(Volume,"Volume",1.0);





// Plot the Buy and Sell arrows.

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);

PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);

5-system (emabased 50)

Code:
_SECTION_BEGIN("MA Cross");

//Modified SH's 315 Strategy by Santhosh2010
// Traderji id :Santhosh2010




e1=EMA(C,3);
e2=EMA(H,50);
e3=EMA(L,50);

Plot(e1,"",colorYellow,styleDashed |styleThick);
Plot(e2,"",colorLightYellow,styleDots );
Plot(e3,"",colorLightYellow,styleDots );

Buy=Cross(e1,e2);
Sell=Cross(e3,e1);
Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);

/*
Heikin-Ashi(Koma-Ashi) with Moving Average Type
*/
SetChartOptions(0,chartShowArrows|chartShowDates);

// Calculate Moving Average
MAPeriod = Param("MA Period", 15, 1, 100);
MAOpen = EMA(Open, MAPeriod);
MAHigh = EMA(High, MAPeriod);
MALow = EMA(Low, MAPeriod);
MAClose = EMA(Close, MAPeriod);

HaClose = (MAOpen + MAHigh + MALow + MAClose) / 4;
HaOpen = AMA(Ref(HaClose, -1), 0.5);

// for graph collapse
for(i = 0; i <= MAPeriod; i++) HaClose[i] = Null;
/*
// same
// HaOpen = (Ref(HaOpen, -1) + Ref(HaClose, -1)) / 2;
HaOpen[ 0 ] = HaClose[ 0 ];
for(i = 1; i < BarCount; i++) {
HaOpen[i] = (HaOpen[i - 1] + HaClose[i - 1]) / 2;
}
*/

HaHigh = Max(MAHigh, Max(HaClose, HaOpen));
HaLow = Min(MALow, Min(HaClose, HaOpen));

// outs comments
"BarIndex = " + BarIndex();
"Open = " + Open;
"High = " + High;
"Low = " + Low;
"Close = "+ Close;
"HaOpen = " + HaOpen;
"HaHigh = " + HaHigh;
"HaLow = " + HaLow;
"HaClose = "+ HaClose;

// Plot graphs
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} HaOpen %g, HaHigh %g,
HaLow %g, HaClose %g (%.1f%%) {{VALUES}}",
HaOpen, HaHigh, HaLow, HaClose, SelectedValue(ROC( HaClose, 1))));
PlotOHLC(HaOpen, HaHigh, HaLow, HaClose, _DEFAULT_NAME(), ParamColor("Color",
colorBlack), styleCandle);

_SECTION_BEGIN("Colour Tap");
SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));
_SECTION_END();


Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover=Buy;
Short=Sell;
PlotShapes(IIf(Buy,shapeUpArrow ,shapeNone),colorWhite,0,L,-35);
PlotShapes(IIf(Sell,shapeDownArrow , shapeNone),colorWhite,0,H,-35);
_SECTION_END();

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


_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();
6-system (emabased)

Code:
_SECTION_BEGIN("MA Cross");

//Modified SH's 315 Strategy by Santhosh2010
// Traderji id :Santhosh2010




e1=EMA(C,3);
e2=EMA(H,15);
e3=EMA(L,15);

Plot(e1,"",colorYellow,styleDashed |styleThick);
Plot(e2,"",colorLightYellow,styleDots );
Plot(e3,"",colorLightYellow,styleDots );

Buy=Cross(e1,e2);
Sell=Cross(e3,e1);
Buysetup=Flip(Buy,Sell);
Shortsetup=Flip(Sell,Buy);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);
SetBarFillColor(Col);
Plot(C,"Close",Col,64);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Cover=Buy;
Short=Sell;
PlotShapes(IIf(Buy,shapeUpArrow ,shapeNone),colorGreen,0,L,-35);
PlotShapes(IIf(Sell,shapeDownArrow , shapeNone),colorRed,0,H,-35);
_SECTION_END();

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


_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;


for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();
7-system (my system with adx)

Code:
_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorWhite ), styleThick | ParamStyle("Style") | GetPriceStyle() );


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

PositionSize = 350000;

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor=Optimize("Factor",4,0.1,10,0.1);
Pd=Optimize("ATR Periods",5,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

trend[i]=1;


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

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

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

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

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

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

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

Plot(TrendUp,"Trend",colorBlue);
Plot(TrendDown,"Down",colorRed);


/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor1=Optimize("Factor1",1.5,5,10,2);
Pd1=Optimize("ATR Periods1",5,1,10,1);
Up1=(H+L)/2+(Factor1*ATR(Pd1));
Dn1=(H+L)/2-(Factor1*ATR(Pd1));
iATR1=ATR(Pd1);
TrendUp1=TrendDown1=Null;
trend1[0]=1;
changeOfTrend1=0;
flag1=flagh1=0;

for (i = 1; i <BarCount; i++) {
TrendUp1[i] = Null;
TrendDown1[i] = Null;

trend1[i]=1;


if (Close[i]>Up1[i-1]) {
trend1[i]=1;
if (trend1[i-1] == -1) changeOfTrend1 = 1;

}
else if (Close[i]<Dn1[i-1]) {
trend1[i]=-1;
if (trend1[i-1] == 1) changeOfTrend1 = 1;
}
else if (trend1[i-1]==1) {
trend1[i]=1;
changeOfTrend1 = 0;
}
else if (trend1[i-1]==-1) {
trend1[i]=-1;
changeOfTrend1 = 0;
}

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

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

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

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

if (flag1==1)
{ Up1[i]=(H[i]+L[i])/2+(Factor1*iATR1[i]);;
}
if (flagh1==1)
{ Dn1[i]=(H[i]+L[i])/2-(Factor1*iATR1[i]);;
}
if (trend1[i]==1) {
TrendUp1[i]=Dn1[i];
if (changeOfTrend1 == 1) {
TrendUp1[i-1] = TrendDown1[i-1];
changeOfTrend1 = 0;
}
}
else if (trend1[i]==-1) {
TrendDown1[i]=Up1[i];
if (changeOfTrend1 == 1) {
TrendDown1[i-1] = TrendUp1[i-1];
changeOfTrend1 = 0;
}
}
}

//Plot(TrendUp1,"Trend",colorWhite);
//Plot(TrendDown1,"Down",colorWhite);


/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/
/*================================================= ================================================== ================================================== ===================*/

d=ADX(10);
d1=Ref(d,-1);
Buy = trend==1 AND trend1==1 AND d>d1 AND d>0;
Short=trend==-1 AND trend1==-1 AND d>d1 AND d>0;

//Buy = trend==1 AND trend1==1 ;
//Short=trend==-1 AND trend1==-1 ;
Sell=trend1==-1;
Cover=trend1==1;

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



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


Title = EncodeColor(colorWhite)+ "ST BY AK & JW PRODUCTIONS" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorBlack) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorWhite, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorWhite, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);

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

_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;
Plot(C,"",colorWhite,styleCandle);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();

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


res=HHV(High,4);
sup=LLV(Low,4);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);

Plot(tsl, _DEFAULT_NAME(), colorWhite, styleStaircase);
8-system (unknown)

Code:
_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();

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoLabel;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("Ichimoku");
prds = Param( "Standard Line Periods", 13, 5, 26, 1 );
turn = Param( "Turning Line Periods", 3, 3, 10, 1 );
delay = Param( "Delayed Line Periods", 12, 4, 25, 1 );
span = Param( "Spans Periods", 16, 10, 52, 1 );

TL = ( HHV( H, turn ) + LLV( L, turn ) ) / 2;
SL = ( HHV( H, prds ) + LLV( L, prds ) ) / 2;
DL = Ref( C, delay );
Sp1 = ( SL + TL ) / 2;
Sp2 = ( HHV( H, span ) + LLV( L, span ) ) / 2;

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

Plot( C, "Close", colorBlack, styleNoTitle | GetPriceStyle() );
Plot( SL, "SL", colorRed, styleThick | styleNoLabel );
Plot( TL, "TL", colorGreen, styleThick | styleNoLabel );
color = IIf( Sp1 > Sp2, ParamColor( "Span1 Color", ColorRGB( 0, 255, 0 ) ), ParamColor( "Span2 Color", ColorRGB( 255, 104, 32 ) ) );
PlotOHLC ( Sp1, Sp1, Sp2, Sp2, "Cloud", Color, styleCloud | styleNoLabel, Null, Null, delay, -2 );
_SECTION_END();


//Magfied Market Price
GfxSetTextAlign( 6 );// left alignment
FS=Param("Font Size",15,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode(0); // transparent
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
Hor=Param("Horizonta Position",860,1,1200,1);
Ver=Param("Vertica Position",27,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
FS2=Param("Font Size2",15,11,100,1);
GfxSelectFont("Times New Roman", FS2,11, 700, True );
GfxSetBkMode( colorGreen );
Hor1=Param("Horizontal Position",835,1,1200,1);
Ver1=Param("Vertical Position",7,1,830,1);
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor1 , Ver1+45 );

dec = (Param("Decimals",2,0,7,1)/10)+1;

Title =EncodeColor(255)+ "Muneshwaraya Namaha" + " - " + Name() + " " + EncodeColor(30) + Date() +
" " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(255)+ " Open = "+ EncodeColor(30)+ WriteVal(O,dec) +
EncodeColor(255)+ " High = "+ EncodeColor(30)+ WriteVal(H,dec) +
EncodeColor(255)+ " Low = "+ EncodeColor(30)+ WriteVal(L,dec) +
EncodeColor(255)+ " Close = "+ EncodeColor(35)+ WriteVal(C,dec)+
EncodeColor(255)+ " Volume = "+ EncodeColor(30)+ WriteVal(V,1) ;

_SECTION_BEGIN("Pivot Trading System");

// User defined parameters.

GraphXSpace = 10; //defines how much extra space should be added above and below graph line (in percent).

dist = 0.25*ATR(10);
Capital=Param("Total capital",100000,10000,1000000,1000);
drawdown=Param("Max. loss per trade as % of Capital", 1.0,0.5,25.0,0.1);
room=Param("Room for S/L as % of Pivot value",0.0015,0.0001,0.025,0.001);

PH= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

PL= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


phfilter=PH+(room*PH);
plfilter=PL-(room*PL);

for (a=4;a<BarCount;a++)
{
if ((H[a-2] >= H[a-4]) AND
(H[a-2] >= H[a-3]) AND
(H[a-2] >= H[a-1]) AND
(H[a-2] >= H[a]))
PlotText("", a-2, H[a-2], colorGreen);

if ((L[a-2] <= L[a-4]) AND
(L[a-2] <= L[a-3]) AND
(L[a-2] <= L[a-1]) AND
(L[a-2] <= L[a]))
PlotText("", a-2, L[a-2]-dist[a-2], colorRed);
}

//Condition for buy : Enter when Close crosses latest pivot high.
Buy = C> (PH+(room*PH));

initialStopBuy=Ref(PL,2)-(Ref(PL,2)*room/100);
trailStopBuy=IIf(C>PH,Ref(initialStopBuy,-1),initialStopBuy);

newStopBuy=trailStopBuy;

BuyLimitCapital=int(Capital/C);
SLbuy=round(C-initialStopBuy);
BuyLimitSL=int((Capital*drawdown)/(100*SLbuy));

//Condition for sell : Exit when previous pivot low is cracked.
Sell = C< (PL-(room*PL));

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

Short = Sell;
Cover = Buy;

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


shape = Buy * shapeCircle + Sell * shapeCircle;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );

_SECTION_END();


_SECTION_BEGIN("Macd coloured price");
//============================================candle sticks=======================

a = Param("fast macd period",3,1,100,1);
b = Param("slow macd period",34,1,100,1);

Up_MACD_TRIX = MACD( a, b ) > Ref(MACD(a,b),-1);

Down_MACD_TRIX = MACD( a, b ) < Ref(MACD(a,b),-1);

Colormacd = IIf(Up_MACD_TRIX,colorLime,IIf(Down_MACD_TRIX,colo rRed,colorCustom12));


PlotOHLC( Open, High, Low, Close, "", Colormacd, styleBar );

_SECTION_END();


_SECTION_END();
 
Last edited:

Similar threads