Author:
iMirror

This script is a visual analysis tool designed to project a "mirrored" or inverted mathematical representation of price action directly onto your trading chart. Its primary purpose is to provide a secondary perspective on market movements by transforming standard price data into an inverse format, helping traders visualize price dynamics through a different lens.

How the Logic Works

The tool operates by performing several layers of calculations on the visible portion of your current chart:

1. Dynamic Range Identification Instead of looking at the entire historical record, the script automatically identifies the specific window of data you are currently viewing. It calculates the highest and lowest price points within this visible area to establish a reference range.

2. Inversion Mapping The core logic begins by "flipping" the standard price values. It takes the Open, High, Low, and Close prices and calculates their mathematical reciprocals (essentially dividing 1 by the price). This creates an inverted data set where traditional highs become low relative points and vice versa.

3. Scaling and Proportionality To ensure the mirrored data remains relevant to the actual chart, the script calculates a proportionality ratio (KK). It compares the range of the original price action against the range of the inverted price action. This ratio allows the tool to shrink or expand the mirrored data so that it scales proportionally with your current view.

4. Visual Projection Finally, the script draws four distinct visual elements (histograms) on your chart. These represent the transformed price points:

  • It maps the "mirrored" highs and lows based on whether the current candle was bullish (closing higher than it opened) or bearish.
  • By adjusting these points based on the proportionality ratio identified earlier, it projects a symmetrical reflection of market movement.

Summary for the Trader

Essentially, this script takes the "shape" of the market price and flips it upside down. If the market moves up with high volatility, the indicator reflects that same intensity but in an inverted orientation. It is designed to provide a visual "shadow" of price action, allowing you to see the mathematical inverse of the current trend side-by-side with the actual price.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
iMirror
//+------------------------------------------------------------------+
//|                                                      iMirror.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3

//---- input parameters
extern int       ExtParam1;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer3);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer4);   
   
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexBuffer(2,ExtMapBuffer1);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexBuffer(3,ExtMapBuffer2);
   
   

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  

      int First_Visible_Index=FirstVisibleBar();
      int Last_Visible_Index=FirstVisibleBar()-BarsPerWindow();
      if(Last_Visible_Index<0)Last_Visible_Index=0;      
      
      if(Last_Visible_Index<0)Last_Visible_Index=0;
      double wr=(High[Highest(NULL,0,MODE_HIGH,First_Visible_Index-Last_Visible_Index+1,Last_Visible_Index)]-Low[Lowest(NULL,0,MODE_LOW,First_Visible_Index-Last_Visible_Index+1,Last_Visible_Index)])/Point;

      for(int i=0;i<Bars;i++){
         ExtMapBuffer1[i]=EMPTY_VALUE;
         ExtMapBuffer2[i]=EMPTY_VALUE;
         ExtMapBuffer3[i]=EMPTY_VALUE;
         ExtMapBuffer4[i]=EMPTY_VALUE;      
      }
      
      for(i=Last_Visible_Index;i<=First_Visible_Index;i++){
         ExtMapBuffer1[i]=1/Open[i];
         ExtMapBuffer2[i]=1/Close[i]; 
         ExtMapBuffer3[i]=1/High[i];
         ExtMapBuffer4[i]=1/Low[i];       
      }
      double ho=High[Highest(NULL,0,MODE_HIGH,First_Visible_Index-Last_Visible_Index+1,Last_Visible_Index)];
      double lo=Low[Lowest(NULL,0,MODE_LOW,First_Visible_Index-Last_Visible_Index+1,Last_Visible_Index)];
      double hn=ExtMapBuffer4[ArrayMaximum(ExtMapBuffer4,First_Visible_Index-Last_Visible_Index+1,Last_Visible_Index)];
      double ln=ExtMapBuffer3[ArrayMinimum(ExtMapBuffer3,First_Visible_Index-Last_Visible_Index+1,Last_Visible_Index)];
      double RR=ho-lo;
      double NR=hn-ln;
      double KK=RR/NR;
      
      for(i=Last_Visible_Index;i<=First_Visible_Index;i++){
         double hh=lo+KK*(ExtMapBuffer1[i]-ln);
         double ll=lo+KK*(ExtMapBuffer2[i]-ln);
         ExtMapBuffer1[i]=hh;
         ExtMapBuffer2[i]=ll;
         if(Close[i]>Open[i]){
            hh=lo+KK*(ExtMapBuffer3[i]-ln);
            ll=lo+KK*(ExtMapBuffer4[i]-ln);   
            ExtMapBuffer4[i]=hh;
            ExtMapBuffer3[i]=ll;         
         }
         else{
            ExtMapBuffer3[i]=lo+KK*(ExtMapBuffer3[i]-ln);
            ExtMapBuffer4[i]=lo+KK*(ExtMapBuffer4[i]-ln);  
         }
      }      
      
          

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

Comments