ToR_1[3][1].03

Download script
Author: Copyright � 2007 Tom Balfe
ToR_1[3][1].03

This tool is designed to help traders quickly identify the "personality" of a financial market—specifically, whether it is currently moving in a clear direction (trending) or moving sideways within a boundary (ranging). Because different trading strategies work best in different conditions—such as using moving averages for trends and oscillators for ranges—this script provides an at-a-glance visual guide to help you choose the right technique.

How the Logic Works

The script analyzes several timeframes simultaneously, ranging from very short-term (5 minutes) to long-term (Daily charts). For each of these timeframes, it calculates three specific pieces of data:

  1. Trend Strength: It measures how intense the current price movement is.
  2. Directional Movement: It determines if the momentum is leaning toward the "Upside" or "Downside."

By comparing these values across multiple timeframes, the tool categorizes the market into four distinct states, which are represented by specific colors and icons on your screen:

  • Ranging Market: If the trend strength is low, the tool identifies the market as "sideways." It displays a unique icon (a squiggly line) and a light blue color to warn you that standard trend-following strategies may not be effective here.
  • Weak Trend: When the market begins to show some momentum but isn't very powerful yet, it provides a subtle visual cue to show the early direction of movement.
  • Strong Upward Trend: When both the strength and the upward momentum meet a high threshold, the tool highlights this with a vibrant green color and a specific "up" arrow.
  • Strong Downward Trend: Similarly, when strong downward momentum is detected, the tool uses a distinct red color and a "down" arrow.

Key Features for the Trader

  • Multi-Timeframe Overview: Instead of looking at one chart, you can see the status of the 5m, 15m, 30m, 1h, 4h, and Daily charts all in one place. This helps you spot "divergences"—for example, seeing a short-term trend moving against the long-term daily trend.
  • Automated Alerts: The script includes an automated notification system. If it detects a significant shift in direction on the 5-minute and 15-minute timeframes simultaneously, it will trigger an alert to notify you of the change immediately.
  • Decision Support: The ultimate goal of this logic is to provide clarity. It allows you to decide instantly whether to take a trade, which strategy to apply, or—just as importantly—when to stay out of the market entirely because conditions are not favorable.
Indicators Used
Movement directional index
Miscellaneous
It issuies visual alerts to the screen
16 Views
0 Downloads
0 Favorites
ToR_1[3][1].03
//+------------------------------------------------------------------+
//|                                             Trending or Ranging? |
//|                                                     ToR_1.02.mq4 |
//|                                       Copyright © 2007 Tom Balfe |
//|                                                                  |
//| This indicator shows you whether a pair is trending or ranging.  | 
//| For trending markets use moving averages and for ranging         |
//| market use oscillators.                                          |
//|                                                                  |
//| It shows ADX values for multiple timeframes to help you          |
//| decide which trading technique to use.                           |
//| Sometimes you'll see short-term trends against the H4            |
//| and D1 trend.                                                    |
//|                                                                  |
//| It's up to you whether you trade in a ranging market. It seems   |
//| to me that trading with the long-term trend is best.             |
//| Having said that, the reason why I made this indicator is to     |
//| to let the trader decide at a glance what to do, or even to      |
//| do nothing. Staying out of a market is a position too.           |
//|                                                                  |
//| If you want to chat about FOREX my friends and I made an IRC     |
//| channel on Undernet called #forex.                               |
//|                                                                  |
//| Best of luck in all your trades!                                 |
//|                                                                  |
//| Version: 1.02                                                    |
//|                                                                  |
//| Changelog:                                                       |
//|     1.02 - added arrows, ranging icon, no zero space state       |
//|            for icons/arrows, spacing got messed up, now          | 
//|            fixed                                                 |
//|     1.01 - unreleased, reduced number of colors, functional      |
//|     1.0  - unreleased, too many colors for ADX values            |
//|                                                                  |
//|                   http://www.forex-tsd.com/members/nittany1.html |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007 Tom Balfe"
#property link      "http://www.forex-tsd.com/members/nittany1.html"
#property link      "redcarsarasota@yahoo.com"
#property indicator_separate_window
#define   labelNames "Tor 1.03"

int spread;
//---- user selectable stuff
extern int  SpreadThreshold=6;
extern bool Show_D1_ADX=true;
double alertBar;
double prev;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- indicator short name
   IndicatorShortName("ToR 1.03 ("+Symbol()+")");

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   for(int i = 1; i < 7; i++) deleteObject(i);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   //---- let's define some stuff 
   // M5 data
   double adx_m5 = iADX(NULL,5,14,PRICE_CLOSE,0,0);
   double di_p_m5 = iADX(NULL,5,14,PRICE_CLOSE,1,0);
   double di_m_m5 = iADX(NULL,5,14,PRICE_CLOSE,2,0);
   // M15 data
   double adx_m15 = iADX(NULL,15,14,PRICE_CLOSE,0,0); 
   double di_p_m15 = iADX(NULL,15,14,PRICE_CLOSE,1,0);
   double di_m_m15 = iADX(NULL,15,14,PRICE_CLOSE,2,0);
   // M30 data
   double adx_m30 = iADX(NULL,30,14,PRICE_CLOSE,0,0); 
   double di_p_m30 = iADX(NULL,30,14,PRICE_CLOSE,1,0);
   double di_m_m30 = iADX(NULL,30,14,PRICE_CLOSE,2,0);
   // H1 data
   double adx_h1 = iADX(NULL,60,14,PRICE_CLOSE,0,0);
   double di_p_h1 = iADX(NULL,60,14,PRICE_CLOSE,1,0);
   double di_m_h1 = iADX(NULL,60,14,PRICE_CLOSE,2,0);
   // H4 data
   double adx_h4 = iADX(NULL,240,14,PRICE_CLOSE,0,0);
   double di_p_h4 = iADX(NULL,240,14,PRICE_CLOSE,1,0);
   double di_m_h4 = iADX(NULL,240,14,PRICE_CLOSE,2,0);
   // D1 data
   double adx_d1 = iADX(NULL,1440,14,PRICE_CLOSE,0,0);
   double di_p_d1 = iADX(NULL,1440,14,PRICE_CLOSE,1,0);
   double di_m_d1 = iADX(NULL,1440,14,PRICE_CLOSE,2,0);
   
   //---- define colors and arrows 
 
   color   adx_color_m5,adx_color_m15,adx_color_m30,adx_color_h1,adx_color_h4,adx_color_d1;
   string  adx_arrow_m5,adx_arrow_m15,adx_arrow_m30,adx_arrow_h1,adx_arrow_h4,adx_arrow_d1;
   
   //---- store values into strings
   
      string  adx_value_m5  = adx_m5;
      string  adx_value_m15 = adx_m15;
      string  adx_value_m30 = adx_m30;
      string  adx_value_h1  = adx_h1;
      string  adx_value_h4  = adx_h4;
      string  adx_value_d1  = adx_d1;
      
   //---- assign colors
   
      adx_color_m5  = setColor(adx_m5 ,di_p_m5 ,di_m_m5);
      adx_color_m15 = setColor(adx_m15,di_p_m15,di_m_m15);
      adx_color_m30 = setColor(adx_m30,di_p_m30,di_m_m30);
      adx_color_h1  = setColor(adx_h1 ,di_p_h1 ,di_m_h1);
      adx_color_h4  = setColor(adx_h4 ,di_p_h4 ,di_m_h4);
      adx_color_d1  = setColor(adx_d1 ,di_p_d1 ,di_m_d1);

   //---- assign arrows
   
      adx_arrow_m5  = setArrow(adx_m5  ,di_p_m5  ,di_m_m5);
      adx_arrow_m15 = setArrow(adx_m15 ,di_p_m15 ,di_m_m15);
      adx_arrow_m30 = setArrow(adx_m30 ,di_p_m30 ,di_m_m30);
      adx_arrow_h1  = setArrow(adx_h1  ,di_p_h1  ,di_m_h1);
      adx_arrow_h4  = setArrow(adx_h4  ,di_p_h4  ,di_m_h4);
      adx_arrow_d1  = setArrow(adx_d1  ,di_p_d1  ,di_m_d1);
   
   //---- alert 
   
      if (prev != 1 && adx_arrow_m5 == "é" && adx_arrow_m15 == "é" && adx_arrow_m5 != "h" && adx_arrow_m15 != "h" && Bars>alertBar) {Alert("5 & 15 min ToR  changing to Up on ",Symbol()," ", Period());alertBar = Bars;prev=1;}   
      if (prev != 2 && adx_arrow_m5 == "ê" && adx_arrow_m15 == "ê" && adx_arrow_m5 != "h" && adx_arrow_m15 != "h" && Bars>alertBar) {Alert("5 & 15 min ToR  changing to Down on ",Symbol()," ", Period());alertBar = Bars;prev=2;}   
      
   //---- show it
         
      setLabel(1," 5 Min:",95 ,adx_value_m5 ,adx_color_m5 ,adx_arrow_m5);
      setLabel(2,"15 Min:",228,adx_value_m15,adx_color_m15,adx_arrow_m15);
      setLabel(3,"30 Min:",366,adx_value_m30,adx_color_m30,adx_arrow_m30);
      setLabel(4,"  1 Hr:",490,adx_value_h1 ,adx_color_h1 ,adx_arrow_h1);
      setLabel(5,"  4 Hr:",622,adx_value_h4 ,adx_color_h4 ,adx_arrow_h4);
      if (Show_D1_ADX)
            setLabel(6,"1 day:",753,adx_value_d1 ,adx_color_d1 ,adx_arrow_d1);
      else  deleteObject(6);


//----
   return(0);
  }



//+------------------------------------------------------------------+
//| Custom functions and procedures                                  |
//+------------------------------------------------------------------+
  
color setColor(double first,double second,double third)
{
   color retColor;
   if ((first < 23) && (first  !=    0)) { retColor = LightSkyBlue; }
   if ((first >=23) && (second > third)) { retColor = Lime; }
   if ((first >=23) && (second < third)) { retColor = Red; }
   return(retColor);
}  

//
//
//    ---- assign arrows 
//             strong up:   { adx_arrow_ = "é"; } 
//             strong down: { adx_arrow_ = "ê"; }
//             up:          { adx_arrow_ = "ì"; } 
//             down:        { adx_arrow_ = "î"; }
//             range: { adx_arrow_ = "h"; }
//             use wingdings for these, the h is squiggly line
//
//

string setArrow(double first, double second, double third)
{
   string arrow;
   
   if ( first <  23 && first != 0)                      { arrow = "h"; }
   if ((first >= 23 && first < 28) && (second > third)) { arrow = "ì"; }
   if ((first >= 23 && first < 28) && (second < third)) { arrow = "î"; }
   if ( first >= 28                && (second > third)) { arrow = "é"; }
   if ( first >= 28                && (second < third)) { arrow = "ê"; }
   return(arrow);
}

//
//
//
//
//

void setLabel(int name,string text,int x,string value, color theColor, string arrow)
{
     setObject(name+"0001",text                           ,x);
     setObject(name+"0002"," ADX "+StringSubstr(value,0,5),x+43 ,theColor);
     setObject(name+"0003",arrow                          ,x+116,theColor,"Wingdings");
}

//
//
//
//
//

void setObject(string name,string text,int x,color theColor = LightSteelBlue, string font = "Lucida Sans Regular")
{
      string indNames = "ToR 1.03 ("+Symbol()+")";
      int    window   = WindowFind(indNames);  
      
      if (ObjectFind(labelNames+name) == -1)
            {
               ObjectCreate(labelNames+name,OBJ_LABEL,window,0,0);
                  ObjectSet(labelNames+name,OBJPROP_CORNER,0);
                  ObjectSet(labelNames+name,OBJPROP_XDISTANCE,x);
                  ObjectSet(labelNames+name,OBJPROP_YDISTANCE,2);
            }               

            //
            //
            //
            //
            //
            
            ObjectSetText(labelNames+name,text,9,font,theColor);
}
void deleteObject(int name)
{
  if (ObjectFind(labelNames+name+"0001") > 0) {
      ObjectDelete(labelNames+name+"0001");
      ObjectDelete(labelNames+name+"0002");
      ObjectDelete(labelNames+name+"0003");
      }      
}
//+------------------------------------------------------------------+

Comments