If anybody can create.....Need Afl for A Strong Strategy

#1
Going Long:
whenever PSAR gives buy signal, look at ADX chart, if D+ above D-, then entre buy trade.. SL as per PSAR..target 100 points..

Going Short:
whenever PSAR gives sell signal, look at ADX chart, if D- above D+, then entre Sell trade.. SL as per PSAR..target 100 points..
 

sr114

Well-Known Member
#3
Going Long:
whenever PSAR gives buy signal, look at ADX chart, if D+ above D-, then entre buy trade.. SL as per PSAR..target 100 points..

Going Short:
whenever PSAR gives sell signal, look at ADX chart, if D- above D+, then entre Sell trade.. SL as per PSAR..target 100 points..
I think u r looking for this



ribbon =
pdi()>mdi = green
pdi()<mdi()=red

so buy = cross price and psar and pdi()>mdi().
for sell = cross psar and price and pdi()< mdi()
all other are the insertion of price and Psar in the chart

rgds
subroto
 
#4
I think u r looking for this



ribbon =
pdi()>mdi = green
pdi()<mdi()=red

so buy = cross price and psar and pdi()>mdi().
for sell = cross psar and price and pdi()< mdi()
all other are the insertion of price and Psar in the chart

rgds
subroto

Pls change it into amibroker afl
 

RDutt

Active Member
#7
Sorry, i do not have this AFL, but I could make out by seeing the picture posted (created by amibroker is written at the base of picture at left side). I would also like to use it when SR sir shares it alongwith rules for it. :thumb:
 
#8
this is not my original work - but a cut and paste job
IAF = 0.02; // acceleration factor
MaxAF = 0.2; // max acceleration

psar = C; // initialize
long = 1; // assume long for initial conditions
af = IAF; // init acelleration factor
ep = Low[ 0 ]; // init extreme point
hp = High [ 0 ];
lp = Low [ 0 ];
CP=Close[0];
for( i = 2; i < BarCount; i++ )
{
if ( long )
{
psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
}
else
{
psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
}

reverse = 0;
//check for reversal
if ( long )
{
if ( Close [ i ] < psar [ i ] )
{
long = 0; reverse = 1; // reverse position to Short
psar [ i ] = hp; // SAR is High point in prev trade
lp = Close [ i ];
af = IAF;
}
}
else
{
if ( Close [ i ] > psar [ i ] )
{
long = 1; reverse = 1; //reverse position to long
psar [ i ] = lp;
hp = Close [ i ];
af = IAF;
}
}

if ( reverse == 0 )
{
if ( long )
{
if ( Close [ i ] > hp )
{
hp = Close [ i ];
af = af + IAF;
if( af > MaxAF ) af = MaxAF;
}

if( Close[ i - 1 ] < psar[ i ] ) psar[ i ] = Close[ i - 1 ];
if( Close[ i - 2 ] < psar[ i ] ) psar[ i ] = Close[ i - 2 ];
}
else
{
if ( Close [ i ] < lp )
{
lp = Close [ i ];
af = af + IAF;
if( af > MaxAF ) af = MaxAF;
}

if( Close[ i - 1 ] > psar[ i ] ) psar[ i ] = Close[ i - 1 ];
if( Close[ i - 2 ] > psar[ i ] ) psar[ i ] = Close[ i - 2 ];

}
}
}

_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();
Plot( psar, "SAR", colorRed, styleDots | styleNoLine | styleThick );
/////////////
range = Param("Periods", 14, 2, 200, 1 );
ADXi=ADX(range);
PDIi=PDI(range);
MDIi=MDI(range);
//Plot( ADXi=ADX(range), _DEFAULT_NAME(), ParamColor( "ADX color", colorBlue ), ParamStyle("ADX style", styleThick ) );
//Plot( PDIi=PDI(range), "", ParamColor( "+DI color", colorGreen ), ParamStyle("+DI style") );
//Plot( MDIi=MDI(range), "", ParamColor( "-DI color", colorRed ), ParamStyle("-DI style") );
uptrend=PDIi>MDIi;//+di greater than -di
downtrend=MDIi>PDIi;//-di greater than +di
Ribboncol=IIf(upTrend,colorGreen, IIf(downtrend,colorRed, colorBlack));
Plot(6, "", Ribboncol, styleOwnScale|styleArea|styleNoLabel, -7.5,100);

Buy1=(Cross(C,psar) );//OR Cross(Ref(C,-1),Ref(psar,-1))) ;
Sell1=(Cross(psar,H) OR Cross(Ref(psar,-1),Ref(H,-1))) ;
RES1=ValueWhen(BUY1 AND L<Ref(PSAR,-1),Ref(PSAR,-1));
SUP1=ValueWhen(Sell1 AND H>Ref(PSAR,-1),Ref(PSAR,-1));
Plot(SUP1,"SUP",colorRed,styleLine);

Plot(RES1,"RES",colorGreen,styleLine);
Sell=Cross(res1,H) OR Cross(sup1,H);//(Cross(psar,H) OR Cross(Ref(psar,-1),Ref(H,-1))) AND downtrend;
Buy=Cross(L,res1) OR Cross(L,sup1);;//(Cross(L,psar) OR Cross(Ref(L,-1),Ref(psar,-1))) AND uptrend;

PlotShapes(Sell*shapeDownArrow,colorRed);
PlotShapes(Buy*shapeUpArrow,colorGreen);
 

sr114

Well-Known Member
#9
Pls Give complete code of afl....i will be obliged
and if possible pls tell how to use it?
here is the code

HTML:
 _SECTION_BEGIN("Background_Setting");
 SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
 ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorGrey40)); 
 SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
 SetChartOptions(0,chartShowArrows|chartShowDates);
 //grid_day = Day()!=Ref(Day(),-1); 
 //Plot(grid_day,"",31,styleHistogram|styleDots|styleNoLabel|styleOwnScale);
 GraphXSpace=10;
 _SECTION_END();

 _SECTION_BEGIN("Price");

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

 _SECTION_BEGIN("Candle color");

 upbar= C > Ref(H,-1) ;
 dnbar= C < Ref(L,-1);
 
 SetBarFillColor(IIf(upbar,ParamColor("Candle UP Color", colorGreen),IIf(dnbar,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
 Plot(C,"Close",IIf(upbar,ParamColor("UP Color", colorDarkGreen),IIf(dnbar,ParamColor("Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
 _SECTION_END();

 _SECTION_END();

 _SECTION_BEGIN("SAR");
 acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
 accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
 Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
 _SECTION_END();

 _SECTION_BEGIN("Trade SYstem");
 tgt=Param("Target",50,10,100,1);

 uptrend1= ((PDI()> MDI()));
 dntrend1=((PDI()< MDI()));
 
 Plot( 2, "tf1", IIf( uptrend1, 5, 	IIf( dntrend1, 4, colorLightYellow)), styleOwnScale|styleArea|styleNoLabel, -1, 100 );

 Buy = Cross(Close,  SAR(acc,accm)) AND uptrend1;
 Sell = Cross(SAR(acc,accm), Close ) AND dntrend1;

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

 BuyPrice=ValueWhen(Buy,C,1); // L in place of C
 SellPrice=ValueWhen(Sell,C,1); // H in place of C

 trailArray = SAR( acc, accm );

  PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorBrightGreen, 0, Low,   Offset=-15);
 PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorRed, 0, High, Offset=-15);

 Title =EncodeColor(colorYellow)+"PSAR ~ [subroto] "+"\n"+
 EncodeColor(colorWhite)+  Name () + "\n" 
 +EncodeColor(colorWhite) + Date() +"" +  "\n" 
 +EncodeColor(colorWhite)+ "Op : "+ EncodeColor(colorWhite)+ O 
 +EncodeColor(colorWhite)+ "Hi : "+ EncodeColor(colorWhite)+ H 
 +EncodeColor(colorWhite)+ "Lo : "+ EncodeColor(colorWhite)+ L 
 +EncodeColor(colorWhite)+ "Cls : "+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorGold))+ C 
 +EncodeColor(colorWhite)+ "\nVolume : " + EncodeColor(colorWhite)+ numtostr (V,1.0)+ "\n\n"
 +EncodeColor(colorWhite)+ " Stop & Reverse @ : "+ EncodeColor(colorWhite)+ NumToStr(trailarray,1.2);

 _SECTION_END();
SAR here used is inbuilt - no loop is used. also SAR can be customised thru the param window

the ribbon is
up=pdi()>mdi(); color bright green
dn=pdi()<mdi(); color red

1.buy will occur when price cross the SAR from below with uptrend
2.sell will ocur when price crosses SAR from top with dntrend

no target [ for profit ] is set as in this system the trade will be reversed with the reversal of the SAR - till then ride the trend

rgds
subroto
 
Last edited:
#10
here is the code

HTML:
 _SECTION_BEGIN("Background_Setting");
 SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
 ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorGrey40)); 
 SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
 SetChartOptions(0,chartShowArrows|chartShowDates);
 //grid_day = Day()!=Ref(Day(),-1); 
 //Plot(grid_day,"",31,styleHistogram|styleDots|styleNoLabel|styleOwnScale);
 GraphXSpace=10;
 _SECTION_END();

 _SECTION_BEGIN("Price");

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

 _SECTION_BEGIN("Candle color");

 upbar= C > Ref(H,-1) ;
 dnbar= C < Ref(L,-1);
 
 SetBarFillColor(IIf(upbar,ParamColor("Candle UP Color", colorGreen),IIf(dnbar,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
 Plot(C,"Close",IIf(upbar,ParamColor("UP Color", colorDarkGreen),IIf(dnbar,ParamColor("Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
 _SECTION_END();

 _SECTION_END();

 _SECTION_BEGIN("SAR");
 acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
 accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
 Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
 _SECTION_END();

 _SECTION_BEGIN("Trade SYstem");
 tgt=Param("Target",50,10,100,1);

 uptrend1= ((PDI()> MDI()));
 dntrend1=((PDI()< MDI()));
 
 Plot( 2, "tf1", IIf( uptrend1, 5, 	IIf( dntrend1, 4, colorLightYellow)), styleOwnScale|styleArea|styleNoLabel, -1, 100 );

 Buy = Cross(Close,  SAR(acc,accm)) AND uptrend1;
 Sell = Cross(SAR(acc,accm), Close ) AND dntrend1;

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

 BuyPrice=ValueWhen(Buy,C,1); // L in place of C
 SellPrice=ValueWhen(Sell,C,1); // H in place of C

 trailArray = SAR( acc, accm );

  PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorBrightGreen, 0, Low,   Offset=-15);
 PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorRed, 0, High, Offset=-15);

 Title =EncodeColor(colorYellow)+"PSAR ~ [subroto] "+"\n"+
 EncodeColor(colorWhite)+  Name () + "\n" 
 +EncodeColor(colorWhite) + Date() +"" +  "\n" 
 +EncodeColor(colorWhite)+ "Op : "+ EncodeColor(colorWhite)+ O 
 +EncodeColor(colorWhite)+ "Hi : "+ EncodeColor(colorWhite)+ H 
 +EncodeColor(colorWhite)+ "Lo : "+ EncodeColor(colorWhite)+ L 
 +EncodeColor(colorWhite)+ "Cls : "+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorGold))+ C 
 +EncodeColor(colorWhite)+ "\nVolume : " + EncodeColor(colorWhite)+ numtostr (V,1.0)+ "\n\n"
 +EncodeColor(colorWhite)+ " Stop & Reverse @ : "+ EncodeColor(colorWhite)+ NumToStr(trailarray,1.2);

 _SECTION_END();
SAR here used is inbuilt - no loop is used. also SAR can be customised thru the param window

the ribbon is
up=pdi()>mdi(); color bright green
dn=pdi()<mdi(); color red

1.buy will occur when price cross the SAR from below with uptrend
2.sell will ocur when price crosses SAR from top with dntrend

no target [ for profit ] is set as in this system the trade will be reversed with the reversal of the SAR - till then ride the trend

rgds
subroto


What would be suitable timeframe to use this system?
 

Similar threads