Author: Copyright � 2011, Brian Dee
Indicators Used
Indicator of the average true rangeStandard Deviation indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
SFX_TOR_v1
#property copyright "Copyright © 2011, Brian Dee"
#property link      "briandee@selectfx.net"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Aqua
#property  indicator_color2  Yellow
#property  indicator_color3  Red
#property  indicator_width1  2

//---- indicator parameters
extern string PairName = "";   // Leave blank for the pair of the chart, enter other pair name to compare correlated pairs

extern int ATR_Period=12;        // D1=20
extern int StdDev_MA_Period=12;  // D1=20
extern int StdDev_MA_Shift=0;    //
extern int StdDev_MA_Method = 0; // 0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
extern int StdDev_MA_Price = 0;  // 0 Close price, 1 Open price, 2 High price, 3 Low price, 4 Median price, (high+low)/2, 5 Typical price, (high+low+close)/3, 6 Weighted close price, (high+low+close+close)/4

extern int MA_Fast_Period = 3;
extern int MA_Fast_Method = 2;   //  0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
extern int MA_Fast_Shift = 0;

int i, limit, counted_bars;
static string Pair1;

//---- indicator buffers
double     ATRBuffer[];
double     STDBuffer[];
double     stddevma[];

/*
The Trend Or Range Indicator (TOR)
A remarkably simple but very useful indicator

Earlier and clearer signals than ADX or VHF
More positive ranging signal than any other indi

Old conventional theory says when StdDev above ATR then market trending
I say this idea may be OK for stocks & commodites but for the harmonics of Forex market we need something quicker and clearer
Also never forget time of day in relation to the pairs main movements

Yellow = StdDev
Aqua = ATR
Red = Smoothed Moving Average of the StdDev

Usage:-
Any pair, any time frame
Best used on majors and M15 period or higher

Yellow breaks above Red when below Aqua = Trend building
Yellow breaks below Red when above Aqua = Trend exhausting
Yellow below Red when below Aqua = Ranging/Sideways market

Details:-
Code shows how to apply a Moving Average to almost any indicator

Some sample code snippets below to show you how to call this indi in an EA
Do not mail me if this EA sample code doesnt compile - is only pseudo-code!!!

*/

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(Digits+1);
     
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE); // 
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   
  // SetIndexDrawBegin(1,SignalSMA);
   
//---- indicator buffers mapping
   SetIndexBuffer(0, ATRBuffer);
   SetIndexBuffer(1, STDBuffer);
   SetIndexBuffer(2, stddevma);
   
   if (PairName == "") Pair1 = Symbol();
   else Pair1 = PairName;

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("SFX TOR: "+Pair1+"("+ATR_Period+","+StdDev_MA_Period+")");
   SetIndexLabel(0,"ATR");
   SetIndexLabel(1,"StdDev");
   SetIndexLabel(2,"StdDev MA");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int limit = Bars - counted_bars;
   if(counted_bars==0) limit--;
   
//---- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
    {
      ATRBuffer[i]=iATR(Pair1,0,ATR_Period,i);
      STDBuffer[i]=iStdDev(Pair1,0,StdDev_MA_Period, StdDev_MA_Shift, StdDev_MA_Method, StdDev_MA_Price, i);
    }
    
   for(i=0; i<limit; i++)   
    {
     stddevma[i] = iMAOnArray(STDBuffer, 0, MA_Fast_Period, MA_Fast_Shift, MA_Fast_Method, i);
    }
       
//---- done
   return(0);
  }
//+------------------------------------------------------------------+


/*
// Example EA code
extern int AgedPeriodSwitch = 5;   // 1=M1 2=M5 -- 9=MN1 Enables easy period value changing in optimizer ;)

// Settings for SFX TOR
 int TOR.ATR_Period=12;        // D1=20
 int TOR.StdDev_MA_Period=12;  // D1=20
 int TOR.StdDev_MA_Shift=0;    //
 int TOR.StdDev_MA_Method = 0; // 0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
 int TOR.StdDev_MA_Price = 0;  // 0 Close price, 1 Open price, 2 High price, 3 Low price, 4 Median price, (high+low)/2, 5 Typical price, (high+low+close)/3, 6 Weighted close price, (high+low+close+close)/4

 int TOR.MA_Fast_Period = 3;
 int TOR.MA_Fast_Method = 2;   //  0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
 int TOR.MA_Fast_Shift = 0;


bool bTrendEnd;



start()
 {


 bTrendEnd = IsTrendFading(AgedPeriodSwitch);

 if (IsNewBar)
  if (bTrendEnd) CloseYourTrendingOrders();
   ....
   ....

 return (0);
 }


bool IsTrendFading(int iPeriodSwitch)
 {
  int iPeriodToUse;
  string strSymbol;
  
  strSymbol = Symbol();
   
  if (iPeriodSwitch == 0) iPeriodToUse = 0; // i.e. the current chart period of the EA
  else iPeriodToUse = PeriodSwitcher(iPeriodSwitch); 
  
 
  double Aqua_1 = iCustom(strSymbol, iPeriodToUse, "SFX TOR", strSymbol, TOR.ATR_Period,TOR.StdDev_MA_Period,TOR.StdDev_MA_Shift,TOR.StdDev_MA_Method,TOR.StdDev_MA_Price,TOR.MA_Fast_Period,TOR.MA_Fast_Method,TOR.MA_Fast_Shift, 0, 1);
  double Yellow_1 = iCustom(strSymbol, iPeriodToUse, "SFX TOR", strSymbol, TOR.ATR_Period,TOR.StdDev_MA_Period,TOR.StdDev_MA_Shift,TOR.StdDev_MA_Method,TOR.StdDev_MA_Price,TOR.MA_Fast_Period,TOR.MA_Fast_Method,TOR.MA_Fast_Shift, 1, 1);
  double Red_1 = iCustom(strSymbol, iPeriodToUse, "SFX TOR", strSymbol, TOR.ATR_Period,TOR.StdDev_MA_Period,TOR.StdDev_MA_Shift,TOR.StdDev_MA_Method,TOR.StdDev_MA_Price,TOR.MA_Fast_Period,TOR.MA_Fast_Method,TOR.MA_Fast_Shift, 2, 1);
 
  if (Yellow_1 > Aqua_1)
   if (Red_1 > Aqua_1)
    if (Yellow_1 < Red_1) return (true);
 
  return (false);
 }
 
int PeriodSwitcher(int iSP)
 {
  // Takes a number 1-9 returns a chart period
  int iP=0;
 
   switch (iSP) 
   {
    case 1:
     iP=PERIOD_M1;
     break;
    
    case 2:
     iP=PERIOD_M5;
     break;
    
    case 3:
     iP=PERIOD_M15;
     break;
     
    case 4:
     iP=PERIOD_M30;
     break;
    
    case 5:
     iP=PERIOD_H1;
     break;
    
    case 6:
     iP=PERIOD_H4;
     break;
     
    case 7:
     iP=PERIOD_D1;
     break;
    
    case 8:
     iP=PERIOD_W1;
     break;
    
    case 9:
     iP=PERIOD_MN1;
     break;
   }  
 
 return(iP);
 }
 
 
*/

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