AmiBroker Code for TransDow System

1,077 views

I have been trying to replicate ETF HQ’s TransDow strategy. It is a neat idea, and the simplicity appeals to me. Beyond that, I’ve been working with AmiBroker to get better at coding in multiple time frames. Because this strategy uses weekly closes, I thought it would be good practice. The problem is that I cannot get my results to be any where near ETF HQ’s results. My guess is that my code has an error, but for the life of me, I cannot figure it out.

After emailing with ETF HQ, I was able to determine that their coding has the week close on Monday while my code uses Friday as the last day of the week. This should not make that much of a difference.

The AmiBroker code is below. I have put it within the WordPress quote function, so it should be able to be cut and pasted without error.

*Update* It will not cut and paste without error. The problem seems to stem from the quotation marks. I’ll leave the code here so that others can peruse it. Email me woodshedder73 at google mail and I’ll send the .afl file as an attachment.

/*TransDow as described by Derry Brown: http://etfhq.com/blog/2013/05/04/market-timing-through-market-dominance-transdow/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EtfHq+%28ETF+HQ%29
*/

//Boilerplate options
SetTradeDelays( 0, 0, 0, 0 );

SetOption( “InitialEquity”, 10000 );
SetOption( “MinShares”, 1 );
SetOption( “MinPosValue”, 0 );
SetOption( “FuturesMode”, False );
SetOption( “AllowPositionShrinking”, True );
SetOption( “ActivateStopsImmediately”, False );
SetOption( “ReverseSignalForcesExit”, False );
SetOption( “AllowSameBarExit”, False );
SetOption( “CommissionMode”, 3 );
SetOption( “CommissionAmount”, 0.0 );
SetOption( “InterestRate”, 0 );
SetOption( “MarginRequirement”, 100 );
SetOption( “MaxOpenPositions”, 1 );
SetOption( “UsePrevBarEquityForPosSizing”, True );

RoundLotSize = 1; // 0 for Funds, 100 for Stocks
TickSize = 0; // 0 for no min. size
MarginDeposit = 0;

Totalpositions = 1;
PositionSize = -100/TotalPositions;

// Weekly Bars //
Time=inWeekly;
TimeFrameSet(Time);
DJI=Foreign(“$DJI”, “C”);
DJT=Foreign(“$DJT”, “C”);
Ratio=DJT/DJI;
Ratio10=MA(Ratio,10);
TimeFrameRestore();
RestorePriceArrays();

Ratio=TimeFrameExpand(Ratio,Time);
Ratio10=TimeFrameExpand(Ratio10,Time);

Buy=Cross(Ratio,Ratio10);
Sell=Cross(Ratio10,Ratio);

BuyPrice=SellPrice=Close;

ApplyStop(stopTypeLoss,stopModePercent,4,0,False);

Plot(Ratio, “Ratio”,colorYellow,styleLine);
Plot(Ratio10, “Ratio10”,colorGreen,styleLine);
Filter=True;
AddColumn(Ratio, “Ratio”,1.5);
AddColumn(Ratio10, “SMA10″,1.5);
AddColumn(Buy, “Buy”);
AddColumn(Sell, “Sell”);

Let me know in the comments if there are any questions about the code. My data provider uses $DJI for the Dow Jones Industrial Average and $DJT for the Dow Jones Transportation Index. These symbols may have to replaced with whatever symbol your data provider uses for the $DJI and $DJT.

PercentRank Function for AmiBroker

1,330 views

Friend of the blog, Ramon Cummins has graciously agreed to share his PercentRank function for AmiBroker language. This is a really useful function. It returns the rank of a value in a set of values as a percentage of the set. In other words, if an indicator produces a raw value, this function allows one to rank the raw value as a percentage of previous values.

//PercentRank Function
//As Coded by Ramon Cummins
function PercentRank( Data, Periods )
{
Count = 0;
for ( i = 1; i < Periods + 1 ; i++ )
{
Count = Count + IIf ( Ref( Data, 0 ) > Ref( Data, -i ), 1, 0 );
}
return 100 * Count / Periods;
}

//Now, lets use the function to rank  Average True Range in percentage terms relative to previous ATRs.
//Define ATR as a percentage
ATR_Percentage=(ATR(10)/C)*100;
//Here we define the lookback period (30 days) to compare current to previous ATR%
RankPeriods = Param( “PercentRank Lookback Periods”, 30,5,252,5 );
//Here we use the PercentRank function to rank the ATR% relative to previous ATR%s
ATR_Bounded = PercentRank( ATR_Percentage, RankPeriods );
if ( ParamToggle( “Show ATR_Bounded”, “No|Yes”, 1 ) == 1  )
{
Plot( ATR_Bounded, _DEFAULT_NAME(), ParamColor( “Color”, colorCycle ), ParamStyle( “Style” ) );
}

And below is a screenshot showing the ATR_Bounded applied to the Qs.
atr_bounded_percentrank-function

AmiBroker Code for TransDow System

1,077 views

I have been trying to replicate ETF HQ’s TransDow strategy. It is a neat idea, and the simplicity appeals to me. Beyond that, I’ve been working with AmiBroker to get better at coding in multiple time frames. Because this strategy uses weekly closes, I thought it would be good practice. The problem is that I cannot get my results to be any where near ETF HQ’s results. My guess is that my code has an error, but for the life of me, I cannot figure it out.

After emailing with ETF HQ, I was able to determine that their coding has the week close on Monday while my code uses Friday as the last day of the week. This should not make that much of a difference.

The AmiBroker code is below. I have put it within the WordPress quote function, so it should be able to be cut and pasted without error.

*Update* It will not cut and paste without error. The problem seems to stem from the quotation marks. I’ll leave the code here so that others can peruse it. Email me woodshedder73 at google mail and I’ll send the .afl file as an attachment.

/*TransDow as described by Derry Brown: http://etfhq.com/blog/2013/05/04/market-timing-through-market-dominance-transdow/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EtfHq+%28ETF+HQ%29
*/

//Boilerplate options
SetTradeDelays( 0, 0, 0, 0 );

SetOption( “InitialEquity”, 10000 );
SetOption( “MinShares”, 1 );
SetOption( “MinPosValue”, 0 );
SetOption( “FuturesMode”, False );
SetOption( “AllowPositionShrinking”, True );
SetOption( “ActivateStopsImmediately”, False );
SetOption( “ReverseSignalForcesExit”, False );
SetOption( “AllowSameBarExit”, False );
SetOption( “CommissionMode”, 3 );
SetOption( “CommissionAmount”, 0.0 );
SetOption( “InterestRate”, 0 );
SetOption( “MarginRequirement”, 100 );
SetOption( “MaxOpenPositions”, 1 );
SetOption( “UsePrevBarEquityForPosSizing”, True );

RoundLotSize = 1; // 0 for Funds, 100 for Stocks
TickSize = 0; // 0 for no min. size
MarginDeposit = 0;

Totalpositions = 1;
PositionSize = -100/TotalPositions;

// Weekly Bars //
Time=inWeekly;
TimeFrameSet(Time);
DJI=Foreign(“$DJI”, “C”);
DJT=Foreign(“$DJT”, “C”);
Ratio=DJT/DJI;
Ratio10=MA(Ratio,10);
TimeFrameRestore();
RestorePriceArrays();

Ratio=TimeFrameExpand(Ratio,Time);
Ratio10=TimeFrameExpand(Ratio10,Time);

Buy=Cross(Ratio,Ratio10);
Sell=Cross(Ratio10,Ratio);

BuyPrice=SellPrice=Close;

ApplyStop(stopTypeLoss,stopModePercent,4,0,False);

Plot(Ratio, “Ratio”,colorYellow,styleLine);
Plot(Ratio10, “Ratio10”,colorGreen,styleLine);
Filter=True;
AddColumn(Ratio, “Ratio”,1.5);
AddColumn(Ratio10, “SMA10″,1.5);
AddColumn(Buy, “Buy”);
AddColumn(Sell, “Sell”);

Let me know in the comments if there are any questions about the code. My data provider uses $DJI for the Dow Jones Industrial Average and $DJT for the Dow Jones Transportation Index. These symbols may have to replaced with whatever symbol your data provider uses for the $DJI and $DJT.

PercentRank Function for AmiBroker

1,330 views

Friend of the blog, Ramon Cummins has graciously agreed to share his PercentRank function for AmiBroker language. This is a really useful function. It returns the rank of a value in a set of values as a percentage of the set. In other words, if an indicator produces a raw value, this function allows one to rank the raw value as a percentage of previous values.

//PercentRank Function
//As Coded by Ramon Cummins
function PercentRank( Data, Periods )
{
Count = 0;
for ( i = 1; i < Periods + 1 ; i++ )
{
Count = Count + IIf ( Ref( Data, 0 ) > Ref( Data, -i ), 1, 0 );
}
return 100 * Count / Periods;
}

//Now, lets use the function to rank  Average True Range in percentage terms relative to previous ATRs.
//Define ATR as a percentage
ATR_Percentage=(ATR(10)/C)*100;
//Here we define the lookback period (30 days) to compare current to previous ATR%
RankPeriods = Param( “PercentRank Lookback Periods”, 30,5,252,5 );
//Here we use the PercentRank function to rank the ATR% relative to previous ATR%s
ATR_Bounded = PercentRank( ATR_Percentage, RankPeriods );
if ( ParamToggle( “Show ATR_Bounded”, “No|Yes”, 1 ) == 1  )
{
Plot( ATR_Bounded, _DEFAULT_NAME(), ParamColor( “Color”, colorCycle ), ParamStyle( “Style” ) );
}

And below is a screenshot showing the ATR_Bounded applied to the Qs.
atr_bounded_percentrank-function