#(T_S_R)-Monthly Range Calculator

Download script
Author: Copyright � 2006, Ogeima
#(T_S_R)-Monthly Range Calculator

This script functions as a comprehensive statistical and visual analysis tool designed to help traders understand historical price movements and calculate potential risk parameters for various financial assets.

Instead of just showing where the price is now, the logic focuses on "Range Analysis"—measuring how much an asset typically moves over specific periods of time. Here is a breakdown of the logic:

Historical Range Calculation

The script automatically looks back at historical monthly data to calculate the "High" and "Low" values for different timeframes. It specifically calculates the price range (the distance between the highest and lowest points) for:

  • The most recent single month.
  • An average of the last 5 months.
  • An average of the last 10 months.
  • An average of the last 20 months.

By gathering this data, the script provides a "Typical Range" (RAvg), which helps traders understand the asset's volatility. It tells you how much "room" the market usually has to move based on past behavior.

Dynamic Risk and "Room" Analysis

Once the averages are calculated, the logic compares these historical figures against the current live market price. It determines two specific values:

  • Room Up: How much upward movement is available before hitting a standard average range.
  • Room Down: How much downward movement is available before hitting a standard average range.

Automated Stop-Loss Positioning

The script uses these "Room" calculations to suggest mathematically derived Stop-Loss levels. It takes the user's desired Risk-to-Reward ratio (a setting you can adjust) and works backward from the price:

  1. It calculates how many pips away a Stop-Loss should be based on the available "Room."
  2. It converts those pips into actual price numbers.
  3. It provides specific targets for both Long (buying) and Short (selling) positions, showing you exactly where to place your exit point to maintain your desired profit ratio.

Visual Dashboard

Rather than making the user do any math, the script generates a real-time visual dashboard on the trading chart. This dashboard displays:

  • The calculated averages for 1, 5, 10, and 20 months.
  • The specific "Room" available in the current direction.
  • The exact price levels for your Stop-Losses (highlighted in different colors like Lime Green and Red).
  • Key historical benchmarks, such as the Monthly High, Monthly Low, and the Current Price.

In summary, the logic takes complex historical volatility data, averages it out to find a "norm," and then tells the trader exactly how much room they have to move in the current market while providing specific price targets for their risk management.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicator
15 Views
0 Downloads
0 Favorites
#(T_S_R)-Monthly Range Calculator
//+------------------------------------------------------------------+
//|                            #(T_S_R)-Monthly Range Calculator.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//|                             #(T_S_R)-Weekly Range Calculator.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//|                             #(T_S_R)-Daily Range Calculator .mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property link      "Data window & extra Periods by cja"
//+------------------------------------------------------------------+
//|                                                   TSR_Ranges.mq4 |
//|                                         Copyright © 2006, Ogeima |
//|                                             ph_bresson@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Ogeima"
#property link      "ph_bresson@yahoo.com"

#property indicator_separate_window
//---- input parameters
extern double  Risk_to_Reward_ratio =  3.0;
extern int First_Av = 5;
extern int Second_Av = 10;
extern int Third_Av = 20;

int nDigits;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("TSR_Monthly");
   if(Symbol()=="GBPJPY" || Symbol()=="EURJPY" || Symbol()=="USDJPY" || Symbol()=="GOLD" || Symbol()=="USDMXN") nDigits = 2;
   if(Symbol()=="GBPUSD" || Symbol()=="EURUSD" || Symbol()=="NZDUSD" || Symbol()=="USDCHF"  ||
   Symbol()=="USDCAD" || Symbol()=="AUDUSD" || Symbol()=="EURUSD" || Symbol()=="EURCHF"  || Symbol()=="EURGBP"
   || Symbol()=="EURCAD" || Symbol()=="EURAUD" )nDigits = 4;

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  // Comment(""); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //----
   int R1=0,R5=0,R10=0,R20=0,RAvg=0;
   int RoomUp=0,RoomDown=0,StopLoss_Long=0,StopLoss_Short=0;
   double   SL_Long=0,SL_Short=0;
   double   low0=0,high0=0;
   string   Text="";
   int i=0;

   R1 =  (iHigh(NULL,PERIOD_MN1,1)-iLow(NULL,PERIOD_MN1,1))/Point;
   for(i=1;i<=First_Av;i++)
      R5    =    R5  +  (iHigh(NULL,PERIOD_MN1,i)-iLow(NULL,PERIOD_MN1,i))/Point;
   for(i=1;i<=Second_Av;i++)
      R10   =    R10 +  (iHigh(NULL,PERIOD_MN1,i)-iLow(NULL,PERIOD_MN1,i))/Point;
   for(i=1;i<=Third_Av;i++)
      R20   =    R20 +  (iHigh(NULL,PERIOD_MN1,i)-iLow(NULL,PERIOD_MN1,i))/Point;

   R5 = R5/First_Av;
   R10 = R10/Second_Av;
   R20 = R20/Third_Av;
   RAvg  =  (R1+R5+R10+R20)/4; //RAvg  =  (R5+R10+R20)/3;new setting    

   low0  =  iLow(NULL,PERIOD_MN1,0);
   high0 =  iHigh(NULL,PERIOD_MN1,0);
   RoomUp   =  RAvg - (Bid - low0)/Point;
   RoomDown =  RAvg - (high0 - Bid)/Point;
   StopLoss_Long  =  RoomUp/Risk_to_Reward_ratio;
   SL_Long        =  Bid - StopLoss_Long*Point;
   StopLoss_Short =  RoomDown/Risk_to_Reward_ratio;
   SL_Short       =  Bid + StopLoss_Short*Point;


   Text =   "Average Months Range: " +  RAvg + "\n"  + 
            "Prev 01  Months  Range: " +  R1   + "\n" + 
            "Prev 05  Months Range: " +  R5   + "\n" + 
            "Prev 10  Months Range: " +  R10  + "\n" +
            "Prev 20  Months Range: " +  R20  + "\n";
   Text =   Text +
            "Room Up:     " + RoomUp              + "\n" +
            "Room Down: " + RoomDown            + "\n" +
            "Maximum StopLosses :"  + "\n" +
            "Long:  " + StopLoss_Long  + " Pips at " + DoubleToStr(SL_Long,nDigits)  + "\n" +
            "Short: " + StopLoss_Short + " Pips at " + DoubleToStr(SL_Short,nDigits) + "\n" ;

   //Comment(Text);
  
   string P=Period();
  
   
        ObjectCreate("MTSR", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR",StringSubstr(Symbol(),0),12, "Arial Bold", CadetBlue);
        ObjectSet("MTSR", OBJPROP_CORNER, 0);
        ObjectSet("MTSR", OBJPROP_XDISTANCE, 25);
        ObjectSet("MTSR", OBJPROP_YDISTANCE, 2);
        ObjectCreate("MTSR1", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR1",StringSubstr(P,0),12, "Arial Bold", CadetBlue);
        ObjectSet("MTSR1", OBJPROP_CORNER, 0);
        ObjectSet("MTSR1", OBJPROP_XDISTANCE, 100);
        ObjectSet("MTSR1", OBJPROP_YDISTANCE, 2);
        
        ObjectCreate("MTSR2", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR2","Average Monthly Range:", 10, "Arial Bold", CadetBlue);
        ObjectSet("MTSR2", OBJPROP_CORNER, 0);
        ObjectSet("MTSR2", OBJPROP_XDISTANCE, 150);
        ObjectSet("MTSR2", OBJPROP_YDISTANCE, 2);
        ObjectCreate("MTSR3", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR3",DoubleToStr(RAvg ,0),12, "Arial Bold", Orange);
        ObjectSet("MTSR3", OBJPROP_CORNER, 0);
        ObjectSet("MTSR3", OBJPROP_XDISTANCE, 310);
        ObjectSet("MTSR3", OBJPROP_YDISTANCE, 2);
        
        ObjectCreate("MTSR4", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR4","Prev 1 Month Range:", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR4", OBJPROP_CORNER, 0);
        ObjectSet("MTSR4", OBJPROP_XDISTANCE, 25);
        ObjectSet("MTSR4", OBJPROP_YDISTANCE, 20);
        ObjectCreate("MTSR5", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR5",DoubleToStr(R1,0),12, "Arial Bold", Orange);
        ObjectSet("MTSR5", OBJPROP_CORNER, 0);
        ObjectSet("MTSR5", OBJPROP_XDISTANCE, 170);
        ObjectSet("MTSR5", OBJPROP_YDISTANCE, 20);
        
        ObjectCreate("MTSR6", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR6","Prev "+First_Av+" Months Range:", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR6", OBJPROP_CORNER, 0);
        ObjectSet("MTSR6", OBJPROP_XDISTANCE, 25);
        ObjectSet("MTSR6", OBJPROP_YDISTANCE, 35);
        ObjectCreate("MTSR7", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR7",DoubleToStr(R5,0),12, "Arial Bold", Orange);
        ObjectSet("MTSR7", OBJPROP_CORNER, 0);
        ObjectSet("MTSR7", OBJPROP_XDISTANCE, 170);
        ObjectSet("MTSR7", OBJPROP_YDISTANCE, 35);
        
        ObjectCreate("MTSR8", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR8","Prev "+Second_Av+" Months Range:", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR8", OBJPROP_CORNER, 0);
        ObjectSet("MTSR8", OBJPROP_XDISTANCE, 220);
        ObjectSet("MTSR8", OBJPROP_YDISTANCE, 20);
        ObjectCreate("MTSR9", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR9",DoubleToStr(R10,0),12, "Arial Bold", Orange);
        ObjectSet("MTSR9", OBJPROP_CORNER, 0);
        ObjectSet("MTSR9", OBJPROP_XDISTANCE, 370);
        ObjectSet("MTSR9", OBJPROP_YDISTANCE, 20);
        
        ObjectCreate("MTSR10", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR10","Prev "+Third_Av+" Months Range:", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR10", OBJPROP_CORNER, 0);
        ObjectSet("MTSR10", OBJPROP_XDISTANCE, 220);
        ObjectSet("MTSR10", OBJPROP_YDISTANCE, 35);
        ObjectCreate("mMTSR11", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("mMTSR11",DoubleToStr(R20,0),12, "Arial Bold", Orange);
        ObjectSet("mMTSR11", OBJPROP_CORNER, 0);
        ObjectSet("mMTSR11", OBJPROP_XDISTANCE, 370);
        ObjectSet("mMTSR11", OBJPROP_YDISTANCE, 35);
        
        ObjectCreate("MTSR12", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR12","Room UP:", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR12", OBJPROP_CORNER, 0);
        ObjectSet("MTSR12", OBJPROP_XDISTANCE, 420);
        ObjectSet("MTSR12", OBJPROP_YDISTANCE, 20);
        ObjectCreate("mMTSR13", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("mMTSR13",DoubleToStr(RoomUp,0),12, "Arial Bold", Orange);
        ObjectSet("mMTSR13", OBJPROP_CORNER, 0);
        ObjectSet("mMTSR13", OBJPROP_XDISTANCE, 490);
        ObjectSet("mMTSR13", OBJPROP_YDISTANCE, 20);
        
        ObjectCreate("MTSR14", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR14","Room DN:", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR14", OBJPROP_CORNER, 0);
        ObjectSet("MTSR14", OBJPROP_XDISTANCE, 420);
        ObjectSet("MTSR14", OBJPROP_YDISTANCE, 35);
        ObjectCreate("MTSR15", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR15",DoubleToStr(RoomDown,0),12, "Arial Bold", Orange);
        ObjectSet("MTSR15", OBJPROP_CORNER, 0);
        ObjectSet("MTSR15", OBJPROP_XDISTANCE, 490);
        ObjectSet("MTSR15", OBJPROP_YDISTANCE, 35);
        
        ObjectCreate("MTSR16", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR16","Maximum StopLosses;",10, "Arial Bold", CadetBlue);
        ObjectSet("MTSR16", OBJPROP_CORNER, 0);
        ObjectSet("MTSR16", OBJPROP_XDISTANCE, 560);
        ObjectSet("MTSR16", OBJPROP_YDISTANCE, 2);
        
        ObjectCreate("MTSR17", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR17","Long:             Pips at", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR17", OBJPROP_CORNER, 0);
        ObjectSet("MTSR17", OBJPROP_XDISTANCE, 560);
        ObjectSet("MTSR17", OBJPROP_YDISTANCE, 20);
        ObjectCreate("mMTSR18", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("mMTSR18",DoubleToStr(StopLoss_Long,0),14, "Arial Bold", LimeGreen);
        ObjectSet("mMTSR18", OBJPROP_CORNER, 0);
        ObjectSet("mMTSR18", OBJPROP_XDISTANCE, 600);
        ObjectSet("mMTSR18", OBJPROP_YDISTANCE, 17);
        
        ObjectCreate("MTSR19", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR19","Short:             Pips at", 10, "Arial ", LightSteelBlue);
        ObjectSet("MTSR19", OBJPROP_CORNER, 0);
        ObjectSet("MTSR19", OBJPROP_XDISTANCE, 560);
        ObjectSet("MTSR19", OBJPROP_YDISTANCE, 35);
        ObjectCreate("MTSR20", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR20",DoubleToStr(StopLoss_Short,0),14, "Arial Bold", Red);
        ObjectSet("MTSR20", OBJPROP_CORNER, 0);
        ObjectSet("MTSR20", OBJPROP_XDISTANCE, 600);
        ObjectSet("MTSR20", OBJPROP_YDISTANCE, 32);
        
        ObjectCreate("MTSR21", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR21",DoubleToStr(SL_Long,nDigits),12, "Arial Bold", LimeGreen);
        ObjectSet("MTSR21", OBJPROP_CORNER, 0);
        ObjectSet("MTSR21", OBJPROP_XDISTANCE, 690);
        ObjectSet("MTSR21", OBJPROP_YDISTANCE, 20);
        ObjectCreate("MTSR22", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR22",DoubleToStr(SL_Short,nDigits),12, "Arial Bold",Red);
        ObjectSet("MTSR22", OBJPROP_CORNER, 0);
        ObjectSet("MTSR22", OBJPROP_XDISTANCE, 690);
        ObjectSet("MTSR22", OBJPROP_YDISTANCE, 35);
        
        ObjectCreate("MTSR23", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR23","Risk to Reward Ratio:", 10, "Arial Bold", CadetBlue);
        ObjectSet("MTSR23", OBJPROP_CORNER, 0);
        ObjectSet("MTSR23", OBJPROP_XDISTANCE, 350);
        ObjectSet("MTSR23", OBJPROP_YDISTANCE, 2);
        ObjectCreate("MTSR24", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("MTSR24",DoubleToStr( Risk_to_Reward_ratio ,0),12, "Arial Bold", Orange);
        ObjectSet("MTSR24", OBJPROP_CORNER, 0);
        ObjectSet("MTSR24", OBJPROP_XDISTANCE, 500);
        ObjectSet("MTSR24", OBJPROP_YDISTANCE, 2);
        
     
        double HIMonthly = iMA(Symbol(),PERIOD_MN1,1,0,MODE_HIGH,PRICE_HIGH,0);
        double LOWMonthly = iMA(Symbol(),PERIOD_MN1,1,0,MODE_LOW,PRICE_LOW,0); 
        //double YEST_HIDaily = iMA(Symbol(),PERIOD_D1,1,0,MODE_HIGH,PRICE_HIGH,1);
        //double YEST_LOWDaily = iMA(Symbol(),PERIOD_D1,1,0,MODE_LOW,PRICE_LOW,1); 
   
        ObjectCreate("Mhigh", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mhigh",DoubleToStr(HIMonthly,Digits), 12, "Arial Bold", Orange);
        ObjectSet("Mhigh", OBJPROP_CORNER, 0);
        ObjectSet("Mhigh", OBJPROP_XDISTANCE, 890);
        ObjectSet("Mhigh", OBJPROP_YDISTANCE, 20);
        
        ObjectCreate("Mhigh2", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mhigh2","MonthlyHigh", 9, "Arial Bold", CadetBlue);
        ObjectSet("Mhigh2", OBJPROP_CORNER, 0);
        ObjectSet("Mhigh2", OBJPROP_XDISTANCE, 890);
        ObjectSet("Mhigh2", OBJPROP_YDISTANCE, 2);
        
        ObjectCreate("Mlow", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mlow",DoubleToStr(LOWMonthly,Digits), 12, "Arial Bold", Orange);
        ObjectSet("Mlow", OBJPROP_CORNER, 0);
        ObjectSet("Mlow", OBJPROP_XDISTANCE, 830);
        ObjectSet("Mlow", OBJPROP_YDISTANCE, 20);
        
        ObjectCreate("mMlow2", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("mMlow2","MonthlyLow", 9, "Arial Bold", CadetBlue);
        ObjectSet("mMlow2", OBJPROP_CORNER, 0);
        ObjectSet("mMlow2", OBJPROP_XDISTANCE, 810);
        ObjectSet("mMlow2", OBJPROP_YDISTANCE, 2);
        
         double CURR = iMA(Symbol(),0,1,0,MODE_LWMA,PRICE_CLOSE,0);
   
           
        ObjectCreate("Mhigh3", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mhigh3",DoubleToStr(CURR,Digits), 12, "Arial Bold", Coral);
        ObjectSet("Whigh3", OBJPROP_CORNER, 0);
        ObjectSet("Mhigh3", OBJPROP_XDISTANCE, 890);
        ObjectSet("Mhigh3", OBJPROP_YDISTANCE,35 );
            
        ObjectCreate("Mhigh4", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mhigh4",DoubleToStr(CURR,Digits), 12, "Arial Bold", Coral);
        ObjectSet("Mhigh4", OBJPROP_CORNER, 0);
        ObjectSet("Mhigh4", OBJPROP_XDISTANCE, 830);
        ObjectSet("Mhigh4", OBJPROP_YDISTANCE,35 );
        
        ObjectCreate("Mlow4", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mlow4","Curr/Month", 9, "Arial ", LightSteelBlue);
        ObjectSet("Mlow4", OBJPROP_CORNER, 0);
        ObjectSet("Mlow4", OBJPROP_XDISTANCE, 760);
        ObjectSet("Mlow4", OBJPROP_YDISTANCE, 20);
        ObjectCreate("Mlow5", OBJ_LABEL, WindowFind("TSR_Monthly"), 0, 0);
        ObjectSetText("Mlow5","Price", 9, "Arial ", LightSteelBlue);
        ObjectSet("Mlow5", OBJPROP_CORNER, 0);
        ObjectSet("Mlow5", OBJPROP_XDISTANCE, 790);
        ObjectSet("Mlow5", OBJPROP_YDISTANCE, 37);
   
   


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

Comments