Showing posts with label AFL CODE-DOUBLE SUPERTREND. Show all posts
Showing posts with label AFL CODE-DOUBLE SUPERTREND. Show all posts

Thursday, October 10, 2024

AFL CODE-DOUBLE SUPERTREND


_SECTION_BEGIN("TF Best SuperTrend AFL");


SetChartOptions( 0, chartShowArrows | chartShowDates );

Plot( C, "Close", ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );


SetBarsRequired( 100000, 0 );


atr2 = Param( "ATR1 Factor", 3, 1, 5, 0.1 );

per2 = Param( "ATR1 Period", 8, 3, 100, 1 );

atr1 = Param( "ATR2 Factor", 5, 1, 20, 0.1 );

per1 = Param( "ATR2 Period", 8, 3, 100, 1 );



SetPositionSize( 1, spsShares );


UpBand1 = ( H + L ) / 2 + ( atr1 * ATR( per1 ) );

DnBand1 = ( H + L ) / 2 - ( atr1 * ATR( per1 ) );

indi1 = ATR( per1 );

RessArray = SuppArray = Null;

trend[0] = 1;

changeOfTrend = 0;

flag = flagh = 0;


UpBand2 = ( H + L ) / 2 + ( atr2 * ATR( per2 ) );

DnBand2 = ( H + L ) / 2 - ( atr2 * ATR( per2 ) );

indi2 = ATR( per2 );

RessArray2 = SuppArray2 = Null;

trend2[0] = 1;

changeOfTrend2 = 0;

flag2 = flagh2 = 0;



for ( i = 1; i < BarCount; i++ )

{


trend[i] = 1;

trend2[i] = 1;



if ( Close[i] > UpBand1[i-1] )

{

trend[i] = 1;


if ( trend[i-1] == -1 )

changeOfTrend = 1;

}

else

if ( Close[i] < DnBand1[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 ( Close[i] > UpBand2[i-1] )

{

trend2[i] = 1;


if ( trend2[i-1] == -1 )

changeOfTrend2 = 1;

}

else

if ( Close[i] < DnBand2[i-1] )

{

trend2[i] = -1;


if ( trend2[i-1] == 1 )

changeOfTrend2 = 1;

}

else

if ( trend2[i-1] == 1 )

{

trend2[i] = 1;

changeOfTrend2 = 0;

}

else

if ( trend2[i-1] == -1 )

{

trend2[i] = -1;

changeOfTrend2 = 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 && DnBand1[i] < DnBand1[i-1] )

{

DnBand1[i] = DnBand1[i-1];

}


if ( trend[i] < 0 && UpBand1[i] > UpBand1[i-1] )

{

UpBand1[i] = UpBand1[i-1];

}


if ( flag == 1 )

{

UpBand1[i] = ( H[i] + L[i] ) / 2 + ( atr1 * indi1[i] );;

}


if ( flagh == 1 )

{

DnBand1[i] = ( H[i] + L[i] ) / 2 - ( atr1 * indi1[i] );;

}



if ( trend2[i] < 0 && trend2[i-1] > 0 )

{

flag2 = 1;

}

else

{

flag2 = 0;

}


if ( trend2[i] > 0 && trend2[i-1] < 0 )

{

flagh2 = 1;

}

else

{

flagh2 = 0;

}


if ( trend2[i] > 0 && DnBand2[i] < DnBand2[i-1] )

{

DnBand2[i] = DnBand2[i-1];

}


if ( trend2[i] < 0 && UpBand2[i] > UpBand2[i-1] )

{

UpBand2[i] = UpBand2[i-1];

}


if ( flag2 == 1 )

{

UpBand2[i] = ( H[i] + L[i] ) / 2 + ( atr2 * indi2[i] );

}


if ( flagh2 == 1 )

{

DnBand2[i] = ( H[i] + L[i] ) / 2 - ( atr2 * indi2[i] );

}


if ( trend[i] == 1 )

{

RessArray[i] = DnBand1[i];


if ( changeOfTrend == 1 )

{

RessArray[i-1] = SuppArray[i-1];

changeOfTrend = 0;

}

}

else

if ( trend[i] == -1 )

{

SuppArray[i] = UpBand1[i];


if ( changeOfTrend == 1 )

{

SuppArray[i-1] = RessArray[i-1];

changeOfTrend = 0;

}

}


if ( trend2[i] == 1 )

{

RessArray2[i] = DnBand2[i];


if ( changeOfTrend2 == 1 )

{

RessArray2[i-1] = SuppArray2[i-1];

changeOfTrend2 = 0;

}

}

else

if ( trend2[i] == -1 )

{

SuppArray2[i] = UpBand2[i];


if ( changeOfTrend2 == 1 )

{

SuppArray2[i-1] = RessArray2[i-1];

changeOfTrend2 = 0;

}

}


}


prevH = TimeFrameGetPrice( "H", inDaily, -1 );


prevL = TimeFrameGetPrice( "L", inDaily, -1 );

Cond01 = 1;//H<PrevH;

Cond02 = 1;//L>PrevL;



Buy1 = Cross( O, Ref( RessArray, -1 ) ) AND Ref( RessArray, -1 ) > 0;

Sell1 = Cross( Ref( SuppArray, -1 ), O ) AND Ref( SuppArray, -1 ) > 0;

Buy = Buy1 AND Cond02;

Sell = ( Ref( SuppArray2, -1 ) > O AND Ref( SuppArray2, -1 ) > 0 );

Buy = ExRem( Buy, Sell );

Sell = ExRem( Sell, Buy );


Short = Sell1 AND Cond01;

Cover = ( O > Ref( RessArray2, -1 ) AND Ref( RessArray2, -1 ) > 0 ) ;

Short = ExRem( Short, Cover );

Cover = ExRem( Cover, Short );



Plot( RessArray, "First Support", ParamColor("Res1 col",colorBlue ) );

Plot( SuppArray, "First Resistance", ParamColor("Sup1 col",colorPink) );

Plot( RessArray2, "Second Support", ParamColor("Res2 col",colorGreen) );

Plot( SuppArray2, "Second Resistance", ParamColor("Sup2 col",colorRed) );


Title = NumToStr( DateTime(), formatDateTime ) + " O " + O + " H " + H + " L " + L + " C " + C +

"\nFirst Support: " + RessArray + " First Resistance: " + SuppArray + " Second Support: " + RessArray2 + " Second Resistance " + SuppArray2;



//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, 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();

👉Tải tại đây

https://drive.google.com/file/d/1U5QS9TKNLWv_5O2rzESe77g5V7-wOW_5/view?usp=drive_link

Cách sử dụng AFL  cho Amibroker  

Tải xuống tệp Amibroker AFL. 

Bây giờ hãy sao chép tệp afl và dán vào vị trí cài Amibroker  

D:\A KY PC\Win\Amibroker\Formulas\VIP free