Author: Victor Nicolaev aka Vinin
returns

This tool is designed as a visual aid for traders to measure the relative strength and position of an asset's price within specific historical windows. Rather than looking at absolute price points, it translates market movement into a standardized range, allowing you to see where the current price sits in relation to recent highs and lows.

Core Logic and Functionality

The script operates by analyzing three distinct timeframes (or "look-back periods") simultaneously. By calculating the price action over these different durations, it provides a multi-layered view of market momentum:

  • Multi-Window Analysis: The tool evaluates the price based on three specific historical lengths (defaulting to 60, 240, and 1440 bars). This allows you to see short-term fluctuations, medium-term trends, and long-term cycles all at once.
  • Relative Positioning: For each of these periods, the script identifies the highest high and the lowest low reached during that timeframe. It then calculates where the current closing price falls within that specific range.
  • Standardized Scaling: The resulting values are normalized to a scale between -1 and 1. This means:
    • A value near 1 indicates the price is currently trading very close to its recent high.
    • A value near -1 indicates the price is trading very close to its recent low.
    • A value near 0 suggests the price is in the middle of its recent range.
  • Trend Smoothing: To make the data easier to read and to filter out "market noise," the script applies a Moving Average to these calculations. This results in smoother lines that highlight the underlying direction of the price movement rather than erratic jumps.

Visual Interpretation

The indicator displays six distinct lines on a separate window below your main chart:

  1. Primary Data: Three lines represent the raw relative position for each of the three timeframes.
  2. Smoothed Trends: Three additional lines represent the smoothed averages of those positions.

By observing where these lines intersect or move in relation to the 0.5 and -0.5 levels, you can gauge whether an asset is overextended, recovering from a low, or maintaining steady momentum across different time horizons.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
returns
//+------------------------------------------------------------------+
//|                                                      returns.mq4 |
//|                                                  Victor Nicolaev |
//|                                                    vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Victor Nicolaev aka Vinin"
#property link      "mailto: vinin@mail.ru"

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Maroon
#property indicator_color2 Blue
#property indicator_color3 DarkSlateGray
#property indicator_color4 Red
#property indicator_color5 DodgerBlue
#property indicator_color6 LimeGreen

#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2

#property indicator_level1 0.5
#property indicator_level2 0
#property indicator_level3 -0.5
#property indicator_levelcolor Gray

#property indicator_maximum 1
#property indicator_minimum -1
//---- input parameters

extern int CountBar1= 60;
extern int CountBar2= 240;
extern int CountBar3= 1440;
extern int MACountBar= 12;

//---- buffers
double ExtMapBuffer0[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
//---- drawing settings
   for (int i=0;i<6;i++) {
      SetIndexStyle(i,DRAW_LINE);
      SetIndexDrawBegin(i,MathMax(CountBar1,MathMax(CountBar2,CountBar3))+MACountBar);
  }
   
      
   SetIndexBuffer(0,ExtMapBuffer0);      
   SetIndexBuffer(1,ExtMapBuffer1);
   SetIndexBuffer(2,ExtMapBuffer2);
   SetIndexBuffer(3,ExtMapBuffer3);
   SetIndexBuffer(4,ExtMapBuffer4);
   SetIndexBuffer(5,ExtMapBuffer5);

   IndicatorShortName("Returns");
   
//---- initialization done
   return(0); }//int init() 
//+------------------------------------------------------------------+
int start() {
   int limit;
   int counted_bars=IndicatorCounted();
   int i;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if (limit>1440) limit = 1440;
   for (i = limit;i>=0;i--){
      ExtMapBuffer0[i] = Value(CountBar1,i);
      ExtMapBuffer1[i] = Value(CountBar2,i);
      ExtMapBuffer2[i] = Value(CountBar3,i);
   }
   for (i = limit;i>=0;i--){
      ExtMapBuffer3[i] = iMAOnArray(ExtMapBuffer0,0,MACountBar,0,MODE_SMA,i);
      ExtMapBuffer4[i] = iMAOnArray(ExtMapBuffer1,0,MACountBar,0,MODE_SMA,i);
      ExtMapBuffer5[i] = iMAOnArray(ExtMapBuffer2,0,MACountBar,0,MODE_SMA,i);
   }



   return(0); 
}// int start()

double Value(int CountBar, int pos) {
   double RetVal=0, tmpHigh, tmpLow;
   tmpHigh=High[iHighest(NULL,0,MODE_HIGH,CountBar,pos)];
   tmpLow=Low[iLowest(NULL,0,MODE_LOW,CountBar,pos)];
   if (tmpHigh>tmpLow) RetVal=((Close[pos]-tmpLow)/(tmpHigh-tmpLow)*2.0-1);
   return(RetVal);
}
   
   

Comments