I am totally newbie and don't know anything about coding. I tried to write (rather search, copy paste) AFL codes which does not provide signal properly. It shows many sell, does not cover orders when target or stoploss is reached. Here is the code. Please help.
"_SECTION_BEGIN( "RSI" );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "Close", ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
Period = Param("RSI Period", 0, 0, 0, 0); // Define the lookback period for use with RSI
vRSI = RSI(8); //Get the Value of the RSI(8)
vRSI1= RSI(12); //Get the value of RSI(12)
BuySignal1 = Ref(vRSI,-1) <= 20; // Check of 1 bars ago, the value of RSI(8) was less than or equal to 20
BuySignal2 = vRSI > 20; // Check the current bar, the value of RSI(8) still keeps higher than 20
BuySignal3 = vRSI > Ref(vMFI,-1); // Value of RSI(8) should be increasing (higher than previous value)
BuySignal11= Ref(vRSI1, -1) <= 20; //Check of 1 bars ago, the value of RSI(12) was less than or equal to 20
BuySignal22= vRSI1 > 20; // Check the current bar, the value of RSI(12) still keeps higher than 20
BuySignal33 = vRSI1 > Ref(vRSI1,-1); // Value of RSI(12) should be increasing (higher than previous value)
ShortSignal1 = Ref(vRSI,-1) >= 80; // Check of 1 bars ago, the value of RSI(8) was more than or equal to 80
ShortSignal2 = vRSI < 80; // Check the current bar, the value of RSI(8) still keeps lower than 80
ShortSignal3 = vRSI < Ref(vRSI,-1); // Value of RSI(12) should be decreasing (lower than previous value)
ShortSignal11= Ref(vRSI1, -1) >= 80; //Check of 1 bars ago, the value of RSI(12) was more than or equal to 80
ShortSignal22= vRSI1 < 80; // Check the current bar, the value of RSI(12) still keeps lower than 80
ShortSignal33 = vRSI1 < Ref(vRSI1,-1); // Value of RSI(12) should be decreasing (lower than previous value)
TargetPrice = Param("TargetProfit",5,0,0,0);
StopPrice = Param("Stoploss",1,0,0,0);
SetPositionSize(1,spsShares); // Backtest Calculation for No of Points
Buy = BuySignal1 AND BuySignal2 AND BuySignal3 AND BuySignal33; // buy condition 1
Buy = BuySignal11 AND BuySignal22 AND BuySignal33 AND BuySignal3; // buy condition 2
Short = ShortSignal1 AND ShortSignal2 AND ShortSignal3 AND ShortSignal33; // Short condition 1
Short = ShortSignal11 AND ShortSignal22 AND ShortSignal33 AND ShortSignal3; // Short condition 2
Cover = Buy;
Sell = Short;
BuyPrice = ValueWhen(Buy,Close); //Enter at Open of the next candle.
TargetBuy = BuyPrice + TargetPrice;
StopBuy = BuyPrice - StopPrice;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
BuyCont = Flip(Buy,Sell);
SellCont = Flip(Sell,Buy);
ShortPrice = ValueWhen(Short,Close);
TargetShort = ShortPrice - TargetPrice;
StopShort = ShortPrice + StopPrice;
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
ShortCont = Flip(Short,Cover);
CoverCont = Flip(Cover,Short);
Cover = Cross(H,StopShort) OR Cross(TargetShort,L); //Exit if Target/Stop reached
CoverPrice = IIf(Cross(H,StopShort), StopShort, IIf(Cross(TargetShort,L), TargetShort, Close));
Sell = Cross(H,TargetPrice) OR Cross(StopPrice,L); //Exit if Target/Stop reached
SellPrice = IIf(Cross(H,TargetPrice), TargetPrice, IIf(Cross(TargetPrice,H), TargetPrice, Close));
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, Offset = -25 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -45 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -45 );
_SECTION_END();"