.

Line Chart Clear Trend Target System - Amibroker AFL Code

Click Image To Enlarge. Please Rate And Comment.

Line Chart Clear Trend Target System

_SECTION_BEGIN("Fahed_SVE_Optimized V3");

ATRfactor = Param( "ATR multiplication", 2.8, 1, 10, 0.1 );
ATRperiod = Param( "ATR Period", 10, 1, 100 );
Trg = Param("Target", 1.5, 1, 3, 0.5);

ATRfact = Optimize("ATR multiplication",ATRfactor,1,5,0.1);
period = Optimize("ATR Period",ATRperiod,1,30,1);

if (Name() == "ABAN.NS")
{
ATRfact = 1.6;
period = 3;
}

if (Name() == "ABB.NS")
{
ATRfact = 1;
period = 1;
}

if (Name() == "ABGSHIP.NS")
{
ATRfact = 1.4;
period = 1;
}

if (Name() == "ACC.NS")
{
ATRfact = 1;
period = 16;
}

if (Name() == "ACL.NS")
{
ATRfact = 1.1;
period = 1;
}

if (Name() == "BAJAJHIND.NS")
{
ATRfact = 1.8;
period = 14;
}

if (Name() == "BALAJITEL.NS")
{
ATRfact = 2.1;
period = 4;
}

if (Name() == "BALRAMCHI.NS")
{
ATRfact = 1.2;
period = 10;
}

if (Name() == "BATAINDIA.NS")
{
ATRfact = 1;
period = 3;
}

if (Name() == "BINDALAGR.NS")
{
ATRfact = 1.7;
period = 1;
}

if (Name() == "CAIRN.NS")
{
ATRfact = 2.2;
period = 1;
}

if (Name() == "CHAMBLFER.NS")
{
ATRfact = 2.2;
period = 14;
}

if (Name() == "CIPLA.NS")
{
ATRfact = 1.1;
period = 20;
}

if (Name() == "COLPAL.NS")
{
ATRfact = 1.6;
period = 19;
}

if (Name() == "DLF.NS")
{
ATRfact = 3;
period = 4;
}

if (Name() == "EDUCOMP.NS")
{
ATRfact = 1.2;
period = 1;
}

if (Name() == "EKC.NS")
{
ATRfact = 2.3;
period = 4;
}

if (Name() == "ESSAROIL.NS")
{
ATRfact = 1.2;
period = 1;
}

if (Name() == "FINANTECH.NS")
{
ATRfact = 1;
period = 14;
}

if (Name() == "FSL.NS")
{
ATRfact = 2.1;
period = 14;
}

if (Name() == "GESHIP.NS")
{
ATRfact = 1;
period = 1;
}

if (Name() == "GITANJALI.NS")
{
ATRfact = 2.2;
period = 1;
}

if (Name() == "HCLTECH.NS")
{
ATRfact = 1.1;
period = 12;
}

if (Name() == "HDIL.NS")
{
ATRfact = 4.1;
period = 1;
}

if (Name() == "HEROHONDA.NS")
{
ATRfact = 1.8;
period = 28;
}

if (Name() == "HINDOILEX.NS")
{
ATRfact = 4.8;
period = 5;
}

if (Name() == "ICICIBANK.NS")
{
ATRfact = 1.2;
period = 13;
}

if (Name() == "IDEA.NS")
{
ATRfact = 2.2;
period = 2;
}

if (Name() == "IFCI.NS")
{
ATRfact = 1.9;
period = 14;
}

if (Name() == "INDIACEM.NS")
{
ATRfact = 2.8;
period = 13;
}

if (Name() == "INFOSYSTC.NS")
{
ATRfact = 1.2;
period = 23;
}

if (Name() == "ISPATIND.NS")
{
ATRfact = 1.2;
period = 12;
}

if (Name() == "ITC.NS")
{
ATRfact = 3.8;
period = 19;
}

if (Name() == "MARUTI.NS")
{
ATRfact = 1.9;
period = 28;
}

if (Name() == "MOSERBAER.NS")
{
ATRfact = 1.5;
period = 5;
}

if (Name() == "MRPL.NS")
{
ATRfact = 1.3;
period = 2;
}

if (Name() == "NAGARFERT.NS")
{
ATRfact = 1.2;
period = 14;
}

if (Name() == "PETRONET.NS")
{
ATRfact = 1.2;
period = 14;
}

if (Name() == "POLARIS.NS")
{
ATRfact = 1.6;
period = 11;
}

if (Name() == "PUNJLLOYD.NS")
{
ATRfact = 2.4;
period = 5;
}

if (Name() == "RANBAXY.NS")
{
ATRfact = 1.2;
period = 13;
}

if (Name() == "RELIANCE.NS")
{
ATRfact = 4.9;
period = 5;
}

if (Name() == "RENUKA.NS")
{
ATRfact = 2;
period = 16;
}

if (Name() == "RNRL.NS")
{
ATRfact = 4.9;
period = 10;
}

if (Name() == "SATYAMCOM.NS")
{
ATRfact = 4.5;
period = 10;
}

if (Name() == "SBIN.NS")
{
ATRfact = 1.1;
period = 2;
}

if (Name() == "SESAGOA.NS")
{
ATRfact = 1;
period = 13;
}

if (Name() == "STER.NS")
{
ATRfact = 3.5;
period = 1;
}

if (Name() == "SUZLON.NS")
{
ATRfact = 2;
period = 6;
}

if (Name() == "TATAMOTOR.NS")
{
ATRfact = 1.5;
period = 9;
}

if (Name() == "TATASTEEL.NS")
{
ATRfact = 1.3;
period = 1;
}

if (Name() == "TCS.NS")
{
ATRfact = 1;
period = 13;
}

if (Name() == "TTML.NS")
{
ATRfact = 1.2;
period = 21;
}

if (Name() == "UCOBANK.NS")
{
ATRfact = 1.4;
period = 14;
}

if (Name() == "ULTRACEMC.NS")
{
ATRfact = 1.3;
period = 9;
}

if (Name() == "UNITECH.NS")
{
ATRfact = 1.2;
period = 2;
}

if (Name() == "WIPRO.NS")
{
ATRfact = 3;
period = 1;
}

if (Name() == "WELPACK.BO")
{
ATRfact = 3;
period = 6;
}

if (Name() == "YESBANK.NS")
{
ATRfact = 1.2;
period = 2;
}

HiLo = IIf( ( H - L ) < 1.5 * MA( H - L, period ), H - L, 1.5 * MA( H - L, period ) );

Href = IIf( L <= Ref( H, -1 ), H - Ref( C, -1 ), ( H - Ref( C, -1 ) ) - ( L - Ref( H, -1 ) ) / 2 );
Lref = IIf( H >= Ref( L, -1 ), Ref( C, -1 ) - L, ( Ref( C, -1 ) - L ) - ( Ref( L, -1 ) - H ) / 2 );
diff1 = Max( HiLo, Href );
diff2 = Max( diff1, Lref );
ATRmod = Wilders( diff2, period );

loss = atrfact * ATRmod;
resistance = C + loss;

support = L;
trends = H;


for( i = 4; i < BarCount; i++ )
{
  if( L[ i ] >= L[ i-2 ] AND
      L[ i-1 ] >= L[ i-2 ] AND
      L[ i-3 ] >= L[ i-2 ] AND
      L[ i-4 ] >= L[ i-2 ] )
   {
    support[ i ] = L[ i - 2];
   }
  else
  if( L[ i ] > H[ i-1 ] * 1.0013 )
   {
    support[ i ] = H[ i-1 ] * 0.9945;
   }
  else
  if( L[ i ] > support[ i-1 ] * 1.1 )
   {
     support[ i ] = support[ i-1 ] * 1.05;
   }
  else
   {
     support[ i ] = support[ i-1 ];
   }

  if( H[ i ] > trends[ i-1 ] AND
      H[ i-1 ] > trends[ i-1 ] )
   {
      trends[ i ] = Max( trends[ i-1 ], support[ i ] );
   }
  else
  if( H[ i ] < trends[ i-1 ] AND
      H[ i-1 ] < trends[ i-1 ] )  
   {
      trends[ i ] = Min( trends[ i-1 ], resistance[ i ] );
   }
  else
  if( H[ i ] >= trends[ i-1 ] )
      trends[ i ] = support[ i ];
  else
      trends[ i ] = resistance[ i ];
  
}

Target = C+ (trg*(C-trends));

Plot( trends, "Trends", colorRed );
Plot( C, "Price", colorBlack, styleBar );
Plot(Target, "Target" , colorGreen);

Buy = Cross( C, trends );
Sell = Cross( trends, H );

Buy = ExRem( Buy, Sell ); // remove ex. signals
Sell = ExRem( Sell, Buy ); // remove ex. signals

PlotShapes( Buy * shapeUpArrow, colorGreen );
PlotShapes( Sell * shapeDownArrow, colorRed );
_SECTION_END();
Previous Post Next Post