AnotherInstr1sep

Download script
AnotherInstr1sep

This tool is designed to provide a visual representation of price movement by comparing the behavior of two different financial instruments simultaneously. Instead of looking at just one currency pair or asset, it calculates a unique "relationship value" between your primary chart and a secondary instrument (such as GBPUSD) to help identify underlying trends.

How the Logic Works

The script operates by performing a multi-layered analysis based on three main components:

1. Relative Positioning Analysis For every price point on your current chart, the script looks at the high, low, and closing prices of both your current instrument and the secondary instrument. It calculates where the price sits within its own "range" (the distance between its highest and lowest points over a short period). For example, it determines if the price is currently hugging the top of its range, sitting in the middle, or dropping toward the bottom.

2. Multi-Step Scaling Rather than looking at just one moment in time, the script repeats this calculation multiple times (based on the "multistep" setting). In each step, it doubles the timeframe it analyzes. This creates a "weighted" perspective, allowing the tool to see not just what is happening right now, but how those relative positions have evolved over progressively larger windows of time.

3. The Correlation Calculation The core of the script is how it combines these two instruments:

  • It takes the position of the secondary instrument and applies it to the price action of your primary chart.
  • If the "mirror" setting is turned off, it calculates a moving average based on the low end of the price range; if turned on, it flips this logic to the high end.
  • Finally, it subtracts this calculated average from the current closing price.

The Visual Result

The final output is displayed as a histogram in a separate window below your main chart. This histogram represents the "gap" or the difference between the actual market price and the synthetic average derived from the secondary instrument's behavior.

By observing these fluctuations, you can see how closely (or wildly) the two instruments are behaving in relation to one another, providing a different layer of perspective than traditional standard indicators.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
5 Views
0 Downloads
0 Favorites
AnotherInstr1sep
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern string     Instr="GBPUSD";
extern int        multistep=6;
extern bool       mirror=false;

double OUT[];
 
int init()
  {
//---- indicators
   IndicatorShortName("AnotherInstr "+Instr);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,OUT);
//----
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
     limit=Bars-counted_bars;     
     for(int i=0; i<limit; i++){  
       int period=2;
       double MA=0;
       for (int j=1;j<=multistep;j++){      
         double anotherHi=iHigh(Instr,0,iHighest(Instr,0,MODE_HIGH,period,iBarShift(Instr,0,Time[i])));
         double anotherLo=iLow(Instr,0,iLowest(Instr,0,MODE_LOW,period,iBarShift(Instr,0,Time[i])));
         double anotherCl=iClose(Instr,0,iBarShift(Instr,0,Time[i]));
         double anotherWidth=(anotherHi-anotherLo);
         double Hi=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,period,i));
         double Lo=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,period,i));
         double Cl=iClose(NULL,0,i);
         double Width=(Hi-Lo);
         
         if (anotherWidth>0) double pos=(anotherCl-anotherLo)/anotherWidth; else pos=0;       
         if (mirror) MA=MA+(Hi-pos*Width); else MA=MA+(Lo+pos*Width);         
         period=period*2;
       }//for
       OUT[i]=Cl-MA/multistep;
     }//for 
   return(0);
  }



Comments