Wednesday, March 20, 2013

Trend Continuation Factor - Amibroker AFL Code

Trend Continuation Factor

Positive values of either the +TCF and the -TCF indicate the presence of a strong trend.

Positive values of +TCF indicator a strong uptrend, while positive values of -TCF indicate a strong downtrend.

+TCF & -TCF cannot both be positive at the same time, since both an uptrend & a downtrend cannot occur simultaneously.  Both can be negative.  if both are negative, this signifies consolidation, OR the absence of a trend.

It recommended to enter long positions when the +TCF value is positive, & enter Short positions when the -TCF value is positive.

The AFL is being presented on as is basis as written by the author of the AFL. Always paper trade before using a new indicator or system in real time basis.

=======================Copy The Code From Below================

/*Trend Continuation Factor
  March 2000 TAS&C */

Length = Param("Length",20,1,100,1);

Change = Close - Ref(Close, -1);
PlusChange = IIf(Change > 0, Change, 0);
MinusChange = IIf(Change < 0, -Change, 0);

EnableScript("jscript");
<%
PlusChange=VBArray(AFL("PlusChange")).toArray();
MinusChange=VBArray(AFL("MinusChange")).toArray();

/*Make two new arrays*/
var PlusCF=new Array ();
var MinusCF=new Array();

/*fill array "PlusCF"*/
for (i=0; i<PlusChange.length; i++ )
{
   if ( PlusChange[i]==0 ) { PlusCF[i]=0; }
    else { PlusCF[i]=PlusChange[i]+PlusCF[i-1]; }
}

/*Fill array "MinusCF*/
for (i=0; i<MinusChange.length; i++ )
{
   if ( MinusChange[i]==0 ) { MinusCF[i]=0; }
    else { MinusCF[i]=MinusChange[i]+MinusCF[i-1]; }
}

/*Convert to AFL variables*/
AFL("PlusCF")=PlusCF;
AFL("MinusCF")=MinusCF;
%>

PlusTCF = Sum(PlusChange-MinusCF,Length);
MinusTCF = Sum(MinusChange-PlusCF,Length);

Plot(PlusTCF, "+TFC("+Length+")", colorGreen);
Plot(MinusTCF, "-TFC("+Length+")", colorRed);
PlotGrid(0, colorLightGrey);

Buy=PlusTCF>0;
Sell=MinusTCF>0;
Short=Sell;
Cover=Buy;

/*This is optional*/
ApplyStop(2,1,Optimize("Stop Loss",12,1,15,1),1);

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

"Positive values of either the +TCF and the -TCF indicate the presence of a strong trend. ";
"";
"Positive values of +TCF indicator a strong uptrend, while positive values of -TCF indicate a strong downtrend.";
"";
"+TCF+ & -TCF cannot both be positive at the same time, since both an uptrend & a downtrend cannot occur simultaneously.  Both can be negative.  if both are negative, this signifies consolidation, OR the absence of a trend.";
"";
"It recommended to enter long positions when the +TCF value is positive, & enter Short positions when the -TCF- value is positive.";

===========================================================

No comments:

Post a Comment

Required US Government Disclaimer & CTFC Rule 4.41

Futures trading contains substantial risk and is not suitable for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only consider risk capital that should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. CTFC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS SUCH AS LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN. All trades, patterns, charts, systems, etc., discussed in this website or advertisement are for illustrative purposes only and not construed as specific advisory recommendations. All ideas and materials presented herein are for information and educational purposes only. No system or trading methodology has ever been developed that can guarantee profits or prevent losses. The testimonials and examples used herein are exceptional results which do not apply to average people and are not intended to represent or guarantee that anyone will achieve the same or similar results. Trades placed on the reliance of Trend Methods systems are taken at your own risk for your own account. This is not an offer to buy or sell futures interests.