Normal
[USER=45469]@CNHTractor[/USER] you can try this code, [USER=73740]@Trav.[/USER] code slightly modified for Norgate (NDU)// Market Regime Filter/* NORGATE Data Handling: -------------------------------------------------------*/#include_once "C:Formulas\Norgate Data\Norgate Data Functions.afl"//OnSecondLastBarOfDelistedSecurity = !IsNull( GetFnData( "DelistingDate" ) ) AND( BarIndex() == ( LastValue( BarIndex() ) - 1 ) OR DateTime() >= GetFnData( "DelistingDate" ) ) ;//OnLastTwoBarsOfDelistedSecurity = !IsNull( GetFnData( "DelistingDate" ) ) AND( BarIndex() >= ( LastValue( BarIndex() ) - 1 ) OR DateTime() >= GetFnData( "DelistingDate" ) );/* BACKTEST Parameters:------------------------------------------------------------------*/SetOption( "CommissionMode", 2 ); // $ per tradeSetOption( "CommissionAmount", 30 ); // $ Amount per tradeSetOption( "InitialEquity", 10000 );SetOption( "AccountMargin", 100 );PositionSize = 10000;SetPositionSize( PositionSize, spsValue );MaxPos = 20;SetOption( "MaxOpenPositions", MaxPos );SetTradeDelays( 1, 1, 1, 1 );SetOption( "AllowSameBarExit", 0 );SetOption( "SeparateLongShortRank", 1 );/* Volatility Filter:------------------------------------------------------------------*/VIXImported = Foreign( "$XVI.au", "C" ); // The S&P/ASX 200 VIX Index (XVI) calculates the amount of volatility expected in the market over the next 30 days.VIXQuiet = MA( VIXImported, 5 ) <= Percentile( MA( VIXImported, 5 ), 252, 35 ); // Current MA(VIX) ranks within Bottom 35% of last 252 daysVIXVolatile = MA( VIXImported, 5 ) > Percentile( MA( VIXImported, 5 ), 252, 35 );/* PRICE Filter:------------------------------------------------------------------*/NorgateIndex = ParamStr( "Index Code", "$XJO.au" );SectorIndexImported = Foreign( NorgateIndex, "C" );//NorgateIndex = Foreign( "$XJO.au");//SectorIndexImported = Foreign( NorgateIndex, "C" ); // Brings in sector index name XEJ, XMJ etcBullMarket = MA( SectorIndexImported, 5 ) > MA( SectorIndexImported, 252 ); // Defines if in Bull or BearBearMarket = MA( SectorIndexImported, 5 ) < MA( SectorIndexImported, 252 );VolatileBear = BearMarket AND VIXVolatile;QuietBear = BearMarket AND VIXQuiet;QuietBull = BullMarket AND VIXQuiet;VolatileBull = BullMarket AND VIXVolatile;//RegimeFilter = IIf( VolatileBear, Optimize("VolatileBear", 1000, 0, 4000, 1000), IIf( QuietBear, Optimize("QuietBear", 3000, 0, 4000, 1000),//IIf( QuietBull, Optimize("QuietBull", 0, 0, 4000, 1000), IIf( VolatileBull, Optimize("VolatileBull", 3000, 0, 4000, 1000), 0))));RegimeFilter = IIf( VolatileBear, 2000, IIf( QuietBear, 3000, IIf( QuietBull, 0, IIf( VolatileBull, 3000, 0 ) ) ) ); // Weighting to PositionScorePositionScore = ROC( Close, 100 ) + RegimeFilter;period = 30; // number of averaging periodsm = MA( Close, period ); // simple moving average_SECTION_BEGIN( "Buy / Sell" );{// BuyNorgate = NorgatePaddingStatusTimeSeries() == 0 AND NOT OnLastTwoBarsOfDelistedSecurity; Buy = Cross( Close, m ) ; // SellNorgate = OnSecondLastBarOfDelistedSecurity; Sell = Cross( m, Close ) ; Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); Short = Cover = 0; Short = ExRem( Short, Cover ); Cover = ExRem( Cover, Short );}_SECTION_BEGIN( "Exploration" );{ if( Status( "Action" ) == actionExplore ); // SetSortColumns( -5 ); Filter = 1; AddColumn( PositionScore, "Score", 1.2, colorDefault, colorDefault, 70 ); AddColumn( VIXImported, "$XVI", 1.2, colordefault, colorDefault, 50 ); AddtextColumn( NorgateIndex, "Index" ); AddColumn( VolatileBear, "Volatile Bear", 1, IIf( VolatileBear, colorGreen, colorRed ), IIf( VolatileBear, colorGreen, colorRed ), 80 ); AddColumn( QuietBear, "Quiet Bear", 1, IIf( QuietBear, colorGreen, colorRed ), IIf( QuietBear, colorGreen, colorRed ), 80 ); AddColumn( VolatileBull, "Volatile Bull", 1, IIf( VolatileBull, colorGreen, colorRed ), IIf( VolatileBull, colorGreen, colorRed ), 80 ); AddColumn( QuietBull, "Quiet Bull", 1, IIf( QuietBull, colorGreen, colorRed ), IIf( QuietBull, colorGreen, colorRed ), 80 ); AddColumn( SectorIndexImported, "Sector", 1.2, colordefault, colorDefault, 80 );}Skate.
[USER=45469]@CNHTractor[/USER] you can try this code, [USER=73740]@Trav.[/USER] code slightly modified for Norgate (NDU)
// Market Regime Filter
/* NORGATE Data Handling: -------------------------------------------------------*/
#include_once "C:Formulas\Norgate Data\Norgate Data Functions.afl"
//OnSecondLastBarOfDelistedSecurity = !IsNull( GetFnData( "DelistingDate" ) ) AND( BarIndex() == ( LastValue( BarIndex() ) - 1 ) OR DateTime() >= GetFnData( "DelistingDate" ) ) ;
//OnLastTwoBarsOfDelistedSecurity = !IsNull( GetFnData( "DelistingDate" ) ) AND( BarIndex() >= ( LastValue( BarIndex() ) - 1 ) OR DateTime() >= GetFnData( "DelistingDate" ) );
/* BACKTEST Parameters:------------------------------------------------------------------*/
SetOption( "CommissionMode", 2 ); // $ per trade
SetOption( "CommissionAmount", 30 ); // $ Amount per trade
SetOption( "InitialEquity", 10000 );
SetOption( "AccountMargin", 100 );
PositionSize = 10000;
SetPositionSize( PositionSize, spsValue );
MaxPos = 20;
SetOption( "MaxOpenPositions", MaxPos );
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "AllowSameBarExit", 0 );
SetOption( "SeparateLongShortRank", 1 );
/* Volatility Filter:------------------------------------------------------------------*/
VIXImported = Foreign( "$XVI.au", "C" ); // The S&P/ASX 200 VIX Index (XVI) calculates the amount of volatility expected in the market over the next 30 days.
VIXQuiet = MA( VIXImported, 5 ) <= Percentile( MA( VIXImported, 5 ), 252, 35 ); // Current MA(VIX) ranks within Bottom 35% of last 252 days
VIXVolatile = MA( VIXImported, 5 ) > Percentile( MA( VIXImported, 5 ), 252, 35 );
/* PRICE Filter:------------------------------------------------------------------*/
NorgateIndex = ParamStr( "Index Code", "$XJO.au" );
SectorIndexImported = Foreign( NorgateIndex, "C" );
//NorgateIndex = Foreign( "$XJO.au");
//SectorIndexImported = Foreign( NorgateIndex, "C" ); // Brings in sector index name XEJ, XMJ etc
BullMarket = MA( SectorIndexImported, 5 ) > MA( SectorIndexImported, 252 ); // Defines if in Bull or Bear
BearMarket = MA( SectorIndexImported, 5 ) < MA( SectorIndexImported, 252 );
VolatileBear = BearMarket AND VIXVolatile;
QuietBear = BearMarket AND VIXQuiet;
QuietBull = BullMarket AND VIXQuiet;
VolatileBull = BullMarket AND VIXVolatile;
//RegimeFilter = IIf( VolatileBear, Optimize("VolatileBear", 1000, 0, 4000, 1000), IIf( QuietBear, Optimize("QuietBear", 3000, 0, 4000, 1000),
//IIf( QuietBull, Optimize("QuietBull", 0, 0, 4000, 1000), IIf( VolatileBull, Optimize("VolatileBull", 3000, 0, 4000, 1000), 0))));
RegimeFilter = IIf( VolatileBear, 2000, IIf( QuietBear, 3000, IIf( QuietBull, 0, IIf( VolatileBull, 3000, 0 ) ) ) ); // Weighting to PositionScore
PositionScore = ROC( Close, 100 ) + RegimeFilter;
period = 30; // number of averaging periods
m = MA( Close, period ); // simple moving average
_SECTION_BEGIN( "Buy / Sell" );
{
// BuyNorgate = NorgatePaddingStatusTimeSeries() == 0 AND NOT OnLastTwoBarsOfDelistedSecurity;
Buy = Cross( Close, m ) ;
// SellNorgate = OnSecondLastBarOfDelistedSecurity;
Sell = Cross( m, Close ) ;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = Cover = 0;
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
}
_SECTION_BEGIN( "Exploration" );
if( Status( "Action" ) == actionExplore ); // SetSortColumns( -5 );
Filter = 1;
AddColumn( PositionScore, "Score", 1.2, colorDefault, colorDefault, 70 );
AddColumn( VIXImported, "$XVI", 1.2, colordefault, colorDefault, 50 );
AddtextColumn( NorgateIndex, "Index" );
AddColumn( VolatileBear, "Volatile Bear", 1,
IIf( VolatileBear, colorGreen, colorRed ),
IIf( VolatileBear, colorGreen, colorRed ), 80 );
AddColumn( QuietBear, "Quiet Bear", 1,
IIf( QuietBear, colorGreen, colorRed ),
IIf( QuietBear, colorGreen, colorRed ), 80 );
AddColumn( VolatileBull, "Volatile Bull", 1,
IIf( VolatileBull, colorGreen, colorRed ),
IIf( VolatileBull, colorGreen, colorRed ), 80 );
AddColumn( QuietBull, "Quiet Bull", 1,
IIf( QuietBull, colorGreen, colorRed ),
IIf( QuietBull, colorGreen, colorRed ), 80 );
AddColumn( SectorIndexImported, "Sector", 1.2, colordefault, colorDefault, 80 );
Skate.
Hello and welcome to Aussie Stock Forums!
To gain full access you must register. Registration is free and takes only a few seconds to complete.
Already a member? Log in here.