Author: mladen
tcf
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
tcf
//+------------------------------------------------------------------+
//|                                                          tcf.mq4 |
//|                                                           mladen |
//|                                                                  |
//| Trend Continuation Factor originaly developed by M.H. Pee        |
//| TASC : 20:3 (March 2002) article                                 |
//| "Just How Long Will A Trend Go On? Trend Continuation Factor"    |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 DarkOrange

extern int Length = 35;
extern int Price  = PRICE_CLOSE;

double TcfUp[];
double TcfDo[];
double values[][4];

//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,TcfUp);
   SetIndexBuffer(1,TcfDo);
   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+

#define plus_ch  0
#define minus_ch 1
#define plus_cf  2
#define minus_cf 3

//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,r,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;
         if (ArrayRange(values,0) != Bars) ArrayResize(values,Bars);

   //
    for(i=limit, r=Bars-limit-1; i>=0; i--,r++)
   {
      double roc = iMA(NULL,0,1,0,MODE_SMA,Price,i)-iMA(NULL,0,1,0,MODE_SMA,Price,i+1);

         values[r][plus_ch]  = 0;
         values[r][minus_ch] = 0;
         values[r][plus_cf]  = 0;
         values[r][minus_cf] = 0;
      
         //
                      
            if (roc>0)
            {
               values[r][plus_ch] = roc;
               if (r>1)
                     values[r][plus_cf] = values[r][plus_ch]+values[r-1][plus_cf];
               else  values[r][plus_cf] = values[r][plus_ch];
            }                  
            if (roc<0)
            {
               values[r][minus_ch] = -roc;
               if (r>1)
                     values[r][minus_cf] = values[r][minus_ch]+values[r-1][minus_cf];
               else  values[r][minus_cf] = values[r][minus_ch];
            }
   
         //
                      
         TcfUp[i] = 0;
         TcfDo[i] = 0;
         for (int l=0; l<Length; l++)
         {
            TcfUp[i] += values[r-l][plus_ch]-values[r-l][minus_cf];
            TcfDo[i] += values[r-l][minus_ch]-values[r-l][plus_cf];
         }
   }      
   return(0);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---