Dear All,
I tried to combine "Modified SH's 315" AFL with "Supertrend" AFL . Here is the code.
COURTESY : Mr.SH, Mr.Santhosh and Mr.Mangatha
Help Needed :
* Last Buy or Sell Signal not showing in chart
* If i try to scroll chart from right to left then last signal (Buy or Sell arrow) was hided from chart. CAN ANYONE SOLVE THIS PROBLEM
* I don't know how the chart image file add in this form. kindly help .
Method:
======
Chart Time : 30 Min
=========
Supertrend 30 minutes shows buy signal and 315 cross over also shows buy signal then enter long.
Supertrend 30 minutes shows Sell signal and 315 cross over also shows Sell signal then enter Short.
Supertrend 30 minutes shows sell signal. but 315 cross over shows buy signal. but if you wait for supertrend buy signal, after the confirmation, we can take long position in 315 crossover. then, we will be end in profit.
if supertrend 30 minutes does not show the buy signal, 315 crossover creates the whipsaws.
By such comparison, we can avoid whipsaws in the 315 strategy
I tried to combine "Modified SH's 315" AFL with "Supertrend" AFL . Here is the code.
COURTESY : Mr.SH, Mr.Santhosh and Mr.Mangatha
PHP:
_SECTION_BEGIN("Modified 315 with Supertrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
Factor=Param("Factor",2,1,10,0.1);
Pd=Param("ATR Periods",10,1,100,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-1; 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",colorGreen);
Plot(TrendDown,"Down",colorRed);
t1 = TrendUp;
t2 = TrendDown;
Buy1 = trend==1;
Sell1=trend==-1;
//Modified SH's 315 Strategy by 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 );
b1=Cross(e1,e2);
s1=Cross(e3,e1);
Buysetup=Flip(b1,s1);
Shortsetup=Flip(s1,b1);
trend=IIf(BarsSince(Buysetup)<BarsSince(Shortsetup ),1,0);
Col=IIf(trend==1,colorGreen,4);
SetBarFillColor(Col);
Plot(C,"Close",Col,64);
Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorWhite) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+" BuySetup: "+Buysetup+" ShortSetup: "+Shortsetup+" TrendUp: "+t1+" TrendDown: "+t2+"\n"+ EncodeColor(colorLime)+
Buy = Buysetup==1 AND Buysetup>Trenddown;
Sell =Shortsetup==1 AND Shortsetup>TrendUp;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
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, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
//Ribbon show Supertrend Method
ribboncol= IIf( BarsSince(Buy1)<BarsSince(Sell1), colorGreen, colorRed );
Plot( 3, "", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 );
GraphXSpace = 12;
_SECTION_END();
* Last Buy or Sell Signal not showing in chart
* If i try to scroll chart from right to left then last signal (Buy or Sell arrow) was hided from chart. CAN ANYONE SOLVE THIS PROBLEM
* I don't know how the chart image file add in this form. kindly help .
Method:
======
Chart Time : 30 Min
=========
Supertrend 30 minutes shows buy signal and 315 cross over also shows buy signal then enter long.
Supertrend 30 minutes shows Sell signal and 315 cross over also shows Sell signal then enter Short.
Supertrend 30 minutes shows sell signal. but 315 cross over shows buy signal. but if you wait for supertrend buy signal, after the confirmation, we can take long position in 315 crossover. then, we will be end in profit.
if supertrend 30 minutes does not show the buy signal, 315 crossover creates the whipsaws.
By such comparison, we can avoid whipsaws in the 315 strategy
Last edited: