Need Trend Continuation Factor

jlmalhotra

Active Member
#2
Metastock Formula

Name: +TCF
Formula:
pc:=If(ROC(C,1,$)>0,ROC(C,1,$),0);
nc:=If(ROC(C,1,$)<0,Neg(ROC(C,1,$)),0);
ncf:=If(nc=0,0,PREV+nc);
Sum(pc,35)-Sum(ncf,35)
Name: -TCF
Formula:
pc:=If(ROC(C,1,$)>0,ROC(C,1,$),0);
nc:=If(ROC(C,1,$)<0,Neg(ROC(C,1,$)),0);
pcf:=If(pc=0,0,PREV+pc);
Sum(nc,35)-Sum(pcf,35)
Name: Position
Formula:
pc:=If(ROC(C,1,$)>0,ROC(C,1,$),0);
nc:=If(ROC(C,1,$)<0,Neg(ROC(C,1,$)),0);
pcf:=If(pc=0,0,PREV+pc);
ncf:=If(nc=0,0,PREV+nc);
ptcf:=Sum(pc,35)-Sum(ncf,35);
ntcf:=Sum(nc,35)-Sum(pcf,35);
If(ptcf>0,1, If(ntcf>0,-1, PREV));
 

hmsanil

Active Member
#3
Metastock Formula

Name: +TCF
Formula:
pc:=If(ROC(C,1,$)>0,ROC(C,1,$),0);
nc:=If(ROC(C,1,$)<0,Neg(ROC(C,1,$)),0);
ncf:=If(nc=0,0,PREV+nc);
Sum(pc,35)-Sum(ncf,35)
Name: -TCF
Formula:
pc:=If(ROC(C,1,$)>0,ROC(C,1,$),0);
nc:=If(ROC(C,1,$)<0,Neg(ROC(C,1,$)),0);
pcf:=If(pc=0,0,PREV+pc);
Sum(nc,35)-Sum(pcf,35)
Name: Position
Formula:
pc:=If(ROC(C,1,$)>0,ROC(C,1,$),0);
nc:=If(ROC(C,1,$)<0,Neg(ROC(C,1,$)),0);
pcf:=If(pc=0,0,PREV+pc);
ncf:=If(nc=0,0,PREV+nc);
ptcf:=Sum(pc,35)-Sum(ncf,35);
ntcf:=Sum(nc,35)-Sum(pcf,35);
If(ptcf>0,1, If(ntcf>0,-1, PREV));


Hi,

Thanks, But i need AFL Indicator for amibroker.
By the by what's your thought on this indicator

Cheers,

Sudha
 

a1b1trader

Well-Known Member
#4
Hi,

Thanks, But i need AFL Indicator for amibroker.
By the by what's your thought on this indicator

Cheers,

Sudha
Try this AFL:
________________________________________

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

EnableScript("jscript");

Length=Optimize("Length",35,1,100,1);

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

<%

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==0) {
PlusCF=0;
}
else {
PlusCF=PlusChange+PlusCF[i-1];
}
}

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

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

%>

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

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);

___________________________________________

If this works then do let me know about the funda of "Trend Continuation Factor" i.e How TCF is used
 

KelvinHand

Well-Known Member
#5
Hi,

Could not understand why the "jscript" did not work 5.50
So re-code with "ascript":

Hope it work the same.
________________________________________

Code:
Length=Param("Length",35,1,100,1);


Change= ROC(C,1);
PlusChange= IIf(Change>0, Change,  0);
MinusChange= IIf(Change<0, -Change, 0);

PlusCF[0] = 0;
MinusCF[0] = 0;


for(i=1; i<BarCount; i++)
  if (MinusChange[i]==0)
      MinusCF[i]=0;
  else
      MinusCF[i]=MinusCF[i-1]+MinusChange[i];


for(i=1; i<BarCount; i++)
  if (PlusChange[i]==0)
      PlusCF[i]=0;
  else
      PlusCF[i]=PlusCF[i-1]+PlusChange[i];




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


Plot(PlusTCF, "+PCF", colorBlue, styleThick);
Plot(MinusTCF, "+NCF", colorRed, styleThick);

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);
 
Last edited:

hmsanil

Active Member
#6
Hi,

Could not understand why the "jscript" did not work 5.50
So re-code with "ascript":

Hope it work the same.
________________________________________

Code:
Length=Param("Length",35,1,100,1);


Change= ROC(C,1);
PlusChange= IIf(Change>0, Change,  0);
MinusChange= IIf(Change<0, -Change, 0);

PlusCF[0] = 0;
MinusCF[0] = 0;


for(i=1; i<BarCount; i++)
  if (MinusChange[i]==0)
      MinusCF[i]=0;
  else
      MinusCF[i]=MinusCF[i-1]+MinusChange[i];


for(i=1; i<BarCount; i++)
  if (PlusChange[i]==0)
      PlusCF[i]=0;
  else
      PlusCF[i]=PlusCF[i-1]+PlusChange[i];




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


Plot(PlusTCF, "+PCF", colorBlue, styleThick);
Plot(MinusTCF, "+NCF", colorRed, styleThick);

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);
Thanks A lot

Its working now

Cheers

Sudha
 
#7
Hi,

Could not understand why the "jscript" did not work 5.50
You forgot the plot

Code:
/*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.";
 

KelvinHand

Well-Known Member
#8
You forgot the plot

Code:
/*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.";

The problem now is both ascript & jscript plot the same curves, but the label scale are different.
for example, ascript is +/- 0 ~100, but the jscript is +/- 0~10 for the same stock.
ascript seen to be quite close to the picture in post #1.

Need help to further confirm with original metastock script.
 
Last edited: