MySAR ADX System

Responder
Avatar de Usuario
X-Trader
Administrador
Mensajes: 11459
Registrado: 06 Sep 2004 10:18
Contactar:

MySAR ADX System

Mensaje por X-Trader »

Os paso el código de esta estrategia basada en el Parabxot de Dennis Meyers.

Código: Seleccionar todo

// Downloaded From www.WiseStockTrader.com
//------------------------------------------------------------------------------
//
//  Formula Name:    MySAR ADX System
//  Author/Uploader: Abhishek Gupta
//  Date/Time Added: 2014-Mar-09
//  Level:           beginner/medium
//  Flags:           trading strategy
//
//------------------------------------------------------------------------------
//
//  This is a complete trading system using a customized SAR designed
//  by Thomas Ludwig and ADX for filtering false signals.
//  It tracks price movement and follows trend.
//
//  Uses PSAR xo by Thomas Ludwig
//  http://www.wisestocktrader.com/indicators/2313-parabxo
//
//  Written by: Abhishek Gupta
//
//------------------------------------------------------------------------------

SetBarsRequired(100);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("PSAR xo");
// http://www.wisestocktrader.com/indicators/2313-parabxo

//------------------------------------------------------------------------------
//
//  Formula Name:    ParabXO
//  Author/Uploader: Thomas Ludwig 
//  E-mail:          [email protected]
//  Date/Time Added: 2005-03-21 15:19:39
//  Origin:          
//  Keywords:        
//  Level:           medium
//  Flags:           indicator
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=448
//  Details URL:     http://www.amibroker.com/library/detail.php?id=448
//
//------------------------------------------------------------------------------
//
//  This is an enhancement of the famous Parabolic SAR indicator by Welles
//  Wilder. For more details see the remarks below.
//
//------------------------------------------------------------------------------

/////////////////////////////////
// ParabXO implemented in AFL.
//
// The code below relies heavily on the AFL code for the 
// Parabolic SAR by Tomasz Janeczko in the AB library
//
// Application: Drag & Drop.
//
// Aside from making the Accelerator Factor and its maximum 
// value changeable via the Param() function I made 2 enhancements 
// by some simple additional coding that were introduced by 
// Dennis Meyers in an article in the S&C 4/1995 issue:
//
// 1. The start value of the AF can be set independently; thus you 
//    can make the indicator react considerably faster.
// 2. The ParabXO does not reverse unless penetrated 
//    by a specified amount (called "Crossover threshold in %" below) 
//    thus preventing too many whipsaws. It can be set to 0 if 
//    you don't want to use this modification. Please note that
//    in Meyers' article he used an absolute number whereas a 
//    percentage makes more sense in my humble opinion.

// Written by: Thomas Ludwig

acc			= Param("Acceleration factor", 0.1, 0.01, 0.1, 0.01);
acc			= Optimize("Acceleration factor", acc, 0.01, 0.1, 0.01);

af_start	= Param("Starting AF value", 0.03, 0.01, 0.1, 0.01);
af_start	= Optimize("Starting AF value", af_start, 0.01, 0.1, 0.01);

af_max		= Param("Maximum AF value", 0.06, 0.01, 0.1, 0.01);
af_max		= Optimize("Maximum AF value", af_max, 0.01, 0.1, 0.01);

Ct			= Param("Crossover threshold in %", 0, 0, 1, 0.1);
Ct			= Optimize("Crossover threshold in %", Ct, 0, 1, 0.1);
Ct1=Ct/100;

IAF = acc; 
MaxAF = af_max;     // max acceleration

psar = Close;		// initialize
psar_temp	= Close;
long = 1;        // assume long for initial conditions
af = af_start;   // starting value of the acelleration factor
ep = Low[ 0 ];   // init extreme point
hp = High [ 0 ];
lp = Low [ 0 ];

for( i = 2; i < BarCount; i++ )
{
	if ( long )
	{
		psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
		psar_temp [ i ] = psar [ i ] * (1-Ct1);
	}
	else
	{
		psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
		psar_temp [ i ] = psar [ i ] * (1+Ct1);
	}

	reverse =  0;
	//check for reversal
	if ( long )
	{
		if ( Low [ i ] < psar [ i ] * (1-Ct1) )
		{
			long = 0; reverse = 1; // reverse position to Short
			psar [ i ] =  hp;       // SAR is High point in prev trade
			psar_temp [ i ]	= hp;
			lp = Low [ i ];
			af = af_start;
		}
	}
	else
	{
		if ( High [ i ] > psar [ i ] * (1+Ct1) )
		{
			long = 1; reverse = 1;        //reverse position to long
			psar [ i ] =  lp;
			psar_temp [ i ] =  lp;
			hp = High [ i ];
			af = af_start;
		}
	}

	if ( reverse == 0 )
	{
		if ( long )
		{
			if ( High [ i ] > hp ) 
			{
				hp = High [ i ]; 
				af = af + IAF; 
				if( af > MaxAF ) af = MaxAF; 
			}
             
			if( Low[ i - 1 ] < psar[ i ] ) psar[ i ] = Low[ i - 1 ];
			if( Low[ i - 2 ] < psar[ i ] ) psar[ i ] = Low[ i - 2 ];
		}
       else
		{
			if ( Low [ i ] < lp )  
			{ 
				lp = Low [ i ]; 
				af = af + IAF; 
				if( af > MaxAF ) af = MaxAF; 
			}	
				
			if( High[ i - 1 ] > psar[ i ] ) psar[ i ] = High[ i - 1 ];
			if( High[ i - 2 ] > psar[ i ] ) psar[ i ] = High[ i - 2 ];

		}
	}
}

Plot( psar, _DEFAULT_NAME(), ParamColor( "Color", colorRed ), styleDots | styleNoLine | styleThick ); 
Plot( psar_temp, _DEFAULT_NAME(), ParamColor( "Color", colorRed ), styleDots | styleNoLine | styleThick );
_SECTION_END();

_SECTION_BEGIN("ADX");
range	= Param("ADX Period", 13, 12, 25, 1);
range	= Optimize("ADX Period", range, 20, 25, 1 );
MYADXFactor	= Param("ADX Factor", 15, 12, 20, 1);
//MYADXFactor	= Optimize("ADX Factor", MYADXFactor, 15, 20, 1);
MYADX	= ADX(range);
_SECTION_END();

_SECTION_BEGIN("Trading signals");
Buy		= Cross(Open, psar_temp) AND MYADX>MYADXFactor;
Short	= Cross(psar_temp, Open) AND MYADX>MYADXFactor;
Sell	= Cross(psar_temp, Open);
Cover	= Cross(Open, psar_temp);

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

BuyPrice		= ValueWhen(Buy, Close);
ShortPrice		= ValueWhen(Short, Close);
CoverPrice		= ValueWhen(Cover, Close);
SellPrice		= ValueWhen(Sell, Close);

dist	= 1.5*ATR(10);
for (i=2; i<BarCount; i++) {
	if (Cover[i]) {
		PlotText( "\nCover short: " + CoverPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
		PlotText( "\n\nProfit: " + (ShortPrice[i]-CoverPrice[i]), i+1.5, L[ i ]-dist[i]-3, colorLime);
	} else if (Sell[i]) {
		PlotText( "\nSell bought: " + SellPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
		PlotText( "\n\nProfit: " + (SellPrice[i]-BuyPrice[i]), i+1.5, H[ i ]+dist[i]+5, colorOrange);
	}
	if(Buy[i]) {
		PlotText( "Buy: " + BuyPrice[i], i+1.5, L[ i ]-dist[i]-3, colorLime);
	} else if( Short[i]) {
		PlotText( "Short: " + ShortPrice[i], i+1.5, H[ i ]+dist[i]+5, colorOrange);
 	}
}

PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Short*shapeDownArrow, colorRed, 0, High, -28);
PlotShapes(Cover*shapeHollowUpArrow, colorGreen, 0, Low, -45);
PlotShapes(Sell*shapeHollowDownArrow, colorRed, 0, High, -45);

printf("\nSignal came " + IIf(BarsSince(Short)>BarsSince(Buy), BarsSince(Buy), BarsSince(Short)) + " bars ago");
WriteIf(BarsSince(Short)>BarsSince(Buy), "\[email protected] " + BuyPrice, "\[email protected] " + ShortPrice);
printf("Trailing SL: " + psar);

printf("\n\nPossiblities ");
printf("\nMax Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), ((O+H+L+C)/4-BuyPrice), (ShortPrice-(O+H+L+C)/4)) );
printf("\nMin Profit: " + IIf(BarsSince(Short)>BarsSince(Buy), (psar-ShortPrice), (ShortPrice-psar)));


// Write Messages
printf("\n\nLet the profit run.");
printf("\nClose a call only when trailing SL hits");
_SECTION_END();
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."

amon26
Mensajes: 1
Registrado: 03 Dic 2016 10:34

Re: MySAR ADX System

Mensaje por amon26 »

Hola. No puedo instalarlo. Me da error
Responder

Volver a “Sistemas”