AFL MA20 cross MA50



//Bismillahi wassholatu wassalamu 'ala rosulillah

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


// **** ma
MA50=MA(C,50);
Plot( MA50, "
MA50", colorBlue, ParamStyle("Style") );
MA20=MA(C,20);
Plot( MA20, "MA20", colorRed, ParamStyle("Style") );
MA100=MA(C,100);
Plot( MA100, "MA100", colorGreen, ParamStyle("Style") );
// *** ma


Hrgbeli = SelectedValue(Ref(C,0));
Maxsementara=SelectedValue(Ref(H,0));

for( i = 0; NOT(SelectedValue(Ref(MA(C,20),-i-1)) <= SelectedValue(Ref(MA(C,50),-i-1)) AND SelectedValue(Ref(MA(C,20),-i)) > SelectedValue(Ref(MA(C,50),-i))); i++ )
{
    Hrgbeli = SelectedValue(Ref(C,-i-1));
    Maxsementara = Max(Maxsementara,SelectedValue(Ref(H,-i-1)));

}
Loss = Param("persen loss",6,5,20,1);
persenlos = Hrgbeli - Hrgbeli*Loss/100;

Plot (hrgbeli, "
hargabeli", colorBlue, ParamStyle("Style")  );
Plot (persenlos, "cutloss (" +  Loss + "%)", colorRed, ParamStyle("Style") |styleNoRescale  );
Plot (Maxsementara, "best H", colorGreen, ParamStyle("Style")  );

trailing5persenDariPuncak = Maxsementara-5/100*Maxsementara; Plot (trailing5persenDariPuncak, "5% dari puncak", colorRed, styleDashed   );
trailing10persenDariPuncak = Maxsementara-10/100*Maxsementara; Plot (trailing10persenDariPuncak, "10% dari puncak", colorAqua, styleDashed );
trailing5persenDariPuncak = Maxsementara-15/100*Maxsementara; Plot (trailing5persenDariPuncak, "15% dari puncak", colorRed, styleDashed |styleNoRescale   );

bestgain = (Maxsementara-hrgbeli)/hrgbeli*100; //maksudnya adalah profit jika bisa jual di high
Currentprofit = (C-hrgbeli)/hrgbeli*100;


Plot (Currentprofit , "
Currentprofit ", colorblack, styleNoDraw |styleNoRescale );
Plot (bestgain, "best gain", colorBlack, styleNoDraw |styleNoRescale );




// *** definisikan buy n sell dan kasi awan
Buy = Cross(MA20,MA50); PlotShapes(IIf(Buy, shapeSmallCircle , shapeNone), colorBlue,0,MA50,Offset=0) ;
Sell = Cross(MA50,MA20); PlotShapes(IIf(Sell, shapeSmallCircle , shapeNone), colorRed,0,MA50,Offset=0) ;

x = IIf(MA50>MA20,MA50,MA20);
 PlotOHLC( MA50,MA50,MA20,MA20, "awan", IIf(MA50>MA20,colorGrey50, colorYellow), styleCloud | styleNoLabel | styleNoTitle  );
// *** definisikan buy n sell dan kasi awan

PlotText("BUY" , SelectedValue(BarIndex()-10) , Hrgbeli, colorBlack,colorYellow);
if (SelectedValue(Currentprofit) <25 )
{Plot (Hrgbeli+25/100*Hrgbeli, "25%", colorBlue, styleNoLabel|styleNoTitle|styleNoRescale );
PlotText("25 %" , SelectedValue(BarIndex()-10) , Hrgbeli+25/100*Hrgbeli, colorBlack,colorYellow);}
else
{if (SelectedValue(Currentprofit) <50)
{Plot (Hrgbeli+50/100*Hrgbeli, "50%", colorBlue, styleNoLabel|styleNoTitle|styleNoRescale );
PlotText("50 %" , SelectedValue(BarIndex()-10) , Hrgbeli+50/100*Hrgbeli, colorBlack,colorYellow);}
else
{PlotText("100 %" , SelectedValue(BarIndex()-10) , Hrgbeli+100/100*Hrgbeli, colorBlack,colorYellow);
Plot (Hrgbeli+100/100*Hrgbeli, "100%", colorBlue, styleNoLabel|styleNoTitle|styleNoRescale );}}




_SECTION_END();

Comments

Popular posts from this blog

Back Test. Fitur Amibroker yang Akan Menguji Seberapa Bagusnya Strategi Beli dan Jual Anda

AFL FRACTAL