nifty plus AFL

#1
_SECTION_BEGIN("Price Chart");
bgTop = ParamColor("BgTop", colorDarkBlue);
bgBot = ParamColor("BgBottom", colorDarkBlue);
SetChartBkGradientFill( bgTop ,bgBot,colorDarkGreen);
pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorBrightGreen);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorOrange);

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C,

SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));


switch (pStyle )
{

case "Solid Candle":
SetBarFillColor( ThisColor );
break;


case "Bar":
ThisStyle = styleBar;
break;

case "Line":
ThisStyle = styleLine;
ThisColor = cLine;
break;


case "Heikin-Ashi":
_C = (O+H+L+C)/4;
_O = AMA( Ref( _C, -1 ), 0.5 );
_H = Max( H, Max( _C, _O ) );
_L = Min( L, Min( _C, _O ) );

ThisColor = IIf(_C >= _O,CBull, CBear);
SetBarFillColor( ThisColor );

ThisColor = IIf(_C >= _O,cLine, cLine);
ThisTitle = "Heikin-Ashi";
break;

default:
SetBarFillColor( ThisColor );
ThisColor = cLine;

break;

}

PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);
GraphXSpace = 8;

_SECTION_END();



_SECTION_BEGIN("BandStop");
Length=Param("Length",20, 2); // Bollinger Bands Period
Deviation=Param("Deviation",2);
// Deviation was 2
MoneyRisk=Param("Money Risk", 1);

LineStyle=ParamToggle("Display line mode", "No|Yes", 1); // Display line mode: 0-no,1-yes
cUpTrendLine = ParamColor("UpTrendLine", colorGreen);
cDnTrendLine = ParamColor("DownTrendLine", colorRed);

// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);


procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
{
global UpTrendLine;
global DownTrendLine;
global smax;
global smin;

UpTrendLine=Null;
DownTrendLine=Null;
smax=Null;
smin=Null;
trend=0;


for (i=Length+1; i<BarCount; i++)
{
smax=bbtop;
smin=bbbot;
if (C>smax[i-1]) trend=1;
if (C<smin[i-1]) trend=-1;
if(trend>0 && smin<smin[i-1]) smin=smin[i-1];
if(trend<0 && smax>smax[i-1]) smax=smax[i-1];
bsmax=smax+0.5*(MoneyRisk-1)*(smax-smin);
bsmin=smin-0.5*(MoneyRisk-1)*(smax-smin);
if(trend>0 && bsmin<bsmin[i-1]) bsmin=bsmin[i-1];
if(trend<0 && bsmax>bsmax[i-1]) bsmax=bsmax[i-1];
if (trend>0)
{
UpTrendLine=bsmin;
if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1]))
{
Say("Bollinger Bands going Up");
TurnedUp=StaticVarSet("TurnedUp",1);
TurnedDown=StaticVarSet("TurnedDown",0);

}
}

if (trend<0)
{
DownTrendLine=bsmax;
if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1]))
{

TurnedUp=StaticVarSet("TurnedUp",0);
TurnedDown=StaticVarSet("TurnedDown",1);
}
} //if (trend<0)
} //for
} //procedure

bbtop=BBandTop(C,Length,Deviation);
bbbot=BBandBot(C,Length,Deviation);

CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));

DisplayStyle = styleNoLabel|styleDots|styleNoTitle;
if(LineStyle == 0) DisplayStyle |= styleNoLine;


Plot(UpTrendLine,"UPTRENDLINE",cUpTrendLine,DisplayStyle);
Plot(DownTrendLine,"DOWNTRENDLINE",cDnTrendLine,DisplayStyle) ;

PlotShapes(IIf(UpTrendSignal,shapeCircle,shapeNone ),cUpTrendLine,0,bbbot,0);
PlotShapes(IIf(DownTrendSignal,shapeCircle,shapeNone),cDnTrendLine,0,bbtop,0);
_SECTION_END();
_SECTION_BEGIN("Signal Panel");

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

showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
if (showsl == 1)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}

exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

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

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

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


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

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

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

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

}

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

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

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( ( "Attri's Research Inc. - NIFTYPlus"),10,y-158);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 70, y-22);;

}
_SECTION_END();
_SECTION_BEGIN("Moving Average");

x=Param("EMA 1",20,1,200,1);
y=Param("EMA 2", 50,1,200,1);
z=Param("EMA 3",100,1,200,1);
zz=Param("EMA 4",200,1,200,1);
EMA20= EMA(C,x);
EMA50=EMA(C,y);
EMA100= EMA(C,z);
EMA200=EMA(C,zz);

SUT=EMA(C,5)>EMA20;
SDT=EMA20>EMA(C,5);
mut= EMA20>EMA50;
mdt=EMA20<EMA50;
_SECTION_END();
_SECTION_BEGIN("Mid Term Price Trend");


MPT = IIf( mut, colorGreen, IIf( mdt, colorRed, colorYellow));
Plot( 3, "", MPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();

_SECTION_BEGIN("Short Term Price Trend");

SPT = IIf( EMA(C,5)>EMA20, colorBrightGreen, IIf( EMA20>EMA(C,5), colorPink, colorYellow));
Plot( 6, "", SPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();
 
#4
there is too many errors can u pls rectify and upload again ...


thanks

Try this. it may help u -


_SECTION_BEGIN("Price Chart");
bgTop = ParamColor("BgTop", colorDarkBlue);
bgBot = ParamColor("BgBottom", colorDarkBlue);
SetChartBkGradientFill( bgTop ,bgBot,colorDarkGreen);
pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorBrightGreen);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorOrange);

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C,

SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));


switch (pStyle )
{

case "Solid Candle":
SetBarFillColor( ThisColor );
break;


case "Bar":
ThisStyle = styleBar;
break;

case "Line":
ThisStyle = styleLine;
ThisColor = cLine;
break;


case "Heikin-Ashi":
_C = (O+H+L+C)/4;
_O = AMA( Ref( _C, -1 ), 0.5 );
_H = Max( H, Max( _C, _O ) );
_L = Min( L, Min( _C, _O ) );

ThisColor = IIf(_C >= _O,CBull, CBear);
SetBarFillColor( ThisColor );

ThisColor = IIf(_C >= _O,cLine, cLine);
ThisTitle = "Heikin-Ashi";
break;

default:
SetBarFillColor( ThisColor );
ThisColor = cLine;

break;

}

PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);
GraphXSpace = 8;

_SECTION_END();



_SECTION_BEGIN("BandStop");
Length=Param("Length",20, 2); // Bollinger Bands Period
Deviation=Param("Deviation",2);
// Deviation was 2
MoneyRisk=Param("Money Risk", 1);

LineStyle=ParamToggle("Display line mode", "No|Yes", 1); // Display line mode: 0-no,1-yes
cUpTrendLine = ParamColor("UpTrendLine", colorGreen);
cDnTrendLine = ParamColor("DownTrendLine", colorRed);

// Offset Factor
TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);


procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
{
global UpTrendLine;
global DownTrendLine;
global smax;
global smin;

UpTrendLine=Null;
DownTrendLine=Null;
smax=Null;
smin=Null;
trend=0;


for (i=Length+1; i<BarCount; i++)
{
smax=bbtop;
smin=bbbot;
if (C>smax[i-1]) trend=1;
if (C<smin[i-1]) trend=-1;
if(trend>0 && smin<smin[i-1]) smin=smin[i-1];
if(trend<0 && smax>smax[i-1]) smax=smax[i-1];
bsmax=smax+0.5*(MoneyRisk-1)*(smax-smin);
bsmin=smin-0.5*(MoneyRisk-1)*(smax-smin);
if(trend>0 && bsmin<bsmin[i-1]) bsmin=bsmin[i-1];
if(trend<0 && bsmax>bsmax[i-1]) bsmax=bsmax[i-1];
if (trend>0)
{
UpTrendLine=bsmin;
if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1]))
{
Say("Bollinger Bands going Up");
TurnedUp=StaticVarSet("TurnedUp",1);
TurnedDown=StaticVarSet("TurnedDown",0);

}
}

if (trend<0)
{
DownTrendLine=bsmax;
if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1]))
{

TurnedUp=StaticVarSet("TurnedUp",0);
TurnedDown=StaticVarSet("TurnedDown",1);
}
} //if (trend<0)
} //for
} //procedure

bbtop=BBandTop(C,Length,Deviation);
bbbot=BBandBot(C,Length,Deviation);

CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));

DisplayStyle = styleNoLabel|styleDots|styleNoTitle;
if(LineStyle == 0) DisplayStyle |= styleNoLine;


Plot(UpTrendLine,"UPTRENDLINE",cUpTrendLine,DisplayStyle);
Plot(DownTrendLine,"DOWNTRENDLINE",cDnTrendLine,DisplayStyle) ;

PlotShapes(IIf(UpTrendSignal,shapeCircle,shapeNone ),cUpTrendLine,0,bbbot,0);
PlotShapes(IIf(DownTrendSignal,shapeCircle,shapeNone),cDnTrendLine,0,bbtop,0);
_SECTION_END();
_SECTION_BEGIN("Signal Panel");

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

showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
if (showsl == 1)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}

exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

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

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

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


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

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

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

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

}

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

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

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( ( "Attri's Research Inc. - NIFTYPlus"),10,y-158);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 70, y-22);;

}
_SECTION_END();
_SECTION_BEGIN("Moving Average");

x=Param("EMA 1",20,1,200,1);
y=Param("EMA 2", 50,1,200,1);
z=Param("EMA 3",100,1,200,1);
zz=Param("EMA 4",200,1,200,1);
EMA20= EMA(C,x);
EMA50=EMA(C,y);
EMA100= EMA(C,z);
EMA200=EMA(C,zz);

SUT=EMA(C,5)>EMA20;
SDT=EMA20>EMA(C,5);
mut= EMA20>EMA50;
mdt=EMA20<EMA50;
_SECTION_END();
_SECTION_BEGIN("Mid Term Price Trend");


MPT = IIf( mut, colorGreen, IIf( mdt, colorRed, colorYellow));
Plot( 3, "", MPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();

_SECTION_BEGIN("Short Term Price Trend");

SPT = IIf( EMA(C,5)>EMA20, colorBrightGreen, IIf( EMA20>EMA(C,5), colorPink, colorYellow));
Plot( 6, "", SPT, styleArea|styleOwnScale|styleNoLabel, 0, 100);

_SECTION_END();
 

Similar threads