Triangular FM Pivots

Download script
Author: Copyright � 2008, Nicholas Barker | Apex Group Investments LLC
Triangular FM Pivots

The Gravity Levels 2 script is a sophisticated technical analysis tool designed for traders who look for interconnected price relationships across different currency pairs. Instead of looking at a single market in isolation, this tool identifies and plots key "gravity" price levels based on the mathematical relationships between multiple correlated instruments.

Core Logic and Functionality

1. Multi-Pair Correlation Mapping The script operates on a predefined system of "rings." Each ring consists of a specific group of three currency pairs that are mathematically linked (for example, a group might include EURUSD, GBPUSD, and EURGBP). By analyzing these groups simultaneously, the tool attempts to identify price levels where multiple markets exert influence on one another.

2. Dynamic Reference Calculation The logic does not rely on simple fixed numbers. Instead, it performs a deep scan of historical data:

  • Historical Range Analysis: It looks back at daily price movements (specifically searching for significant highs and lows) across the various pairs within a designated "ring."
  • Price Direction Detection: The script identifies whether a specific market moved up or down during that period to determine the correct starting point for its calculations.
  • Percentage Offsets: It uses specific percentage-based offsets (configured within the script) to calculate precise price targets relative to those historical ranges.

3. Cross-Market Mathematical Synthesis Once the data from the individual pairs is gathered, the script performs a series of complex algebraic operations to synthesize "Gravity Levels."

  • It calculates these levels by multiplying, dividing, or inverting the price points of the different pairs within a group.
  • Essentially, it is trying to find the "equilibrium" price where the forces of all three currencies in a group meet.

4. Visual Execution on the Chart The final result of this logic is the automatic plotting of horizontal lines on your trading chart:

  • Automatic Plotting: The script identifies which specific "ring" you are currently viewing and automatically draws the calculated gravity levels at their respective prices.
  • Real-Time Updates: As price action evolves, the script continuously recalculates these mathematical intersections to ensure the gravity levels remain relevant to current market conditions.
  • On-Screen Information: The tool provides a text commentary on the chart, clearly listing which currency groups are currently being calculated so the trader knows exactly which "rings" are influencing the visual lines.

Summary for the User

Think of this script as a "gravity map." While most traders only see one path (one currency pair), this script sees the entire landscape. It looks at several nearby markets, calculates how they are pulling on each other mathematically, and draws the "heavy" price levels where those forces meet. These lines represent areas of potential significance where the combined weight of multiple currencies creates a point of market interest.

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 open prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
Triangular FM Pivots
//+------------------------------------------------------------------+
//|                                             Gravity Levels 2.mq4 |
//|   Copyright © 2008, Nicholas Barker | Apex Group Investments LLC |
//|                                                  nick@barker.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Nicholas Barker | Apex Group Investments LLC"
#property link      "nick@barker.net"


#define HIGH 345
#define LOW 3455
#define GU 0
#define EU 1
#define EG 2


#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 Pink
#property indicator_color4 Pink
#property indicator_color5 Magenta
#property indicator_color6 Magenta
//#property indicator_color7 Gold
//---- buffers
string Sym[]={"GBPUSD","EURUSD","EURGBP"};
string pairs[14][3]={
"EURJPY","EURAUD","AUDJPY",//1 d
"EURJPY","EURCHF","CHFJPY",//6 h, inv
"EURJPY","EURGBP","GBPJPY",//12 inv
"EURJPY","EURUSD","USDJPY",//14
"AUDJPY","AUDUSD","USDJPY",//2 d
                "EURUSD","EURAUD","AUDUSD",//3 d
                "EURUSD","EURGBP","GBPUSD",//13
"USDJPY","USDCHF","CHFJPY",//8 
"GBPJPY","GBPCHF","CHFJPY",//7 inv
"GBPJPY","GBPUSD","USDJPY",//14
                 "EURCAD","EURUSD","USDCAD",//9 inv
"EURCHF","EURGBP","GBPCHF",//10 inv
"EURCHF","EURUSD","USDCHF",//11 inv
"GBPCHF","GBPUSD","USDCHF",//15
//"USDJPY","USDCAD","CADJPY",// inv
//"EURJPY","EURCAD","CADJPY",//4 d
};


double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
//double ExtMapBuffer7[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
   //SetIndexArrow(0,159);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3);
   //SetIndexArrow(1,159);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,3);
   //SetIndexArrow(0,159);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,3);
   //SetIndexArrow(1,159);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,3);
   //SetIndexArrow(0,159);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexEmptyValue(4,0.0);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,3);
   //SetIndexArrow(1,159);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexEmptyValue(5,0.0);
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int getrings(int& set[]){
   int c;
   for(int i=0;i<14;i++){
      for(int y=0;y<3;y++){
         if(pairs[i][y]==Symbol()){
            c++;
            ArrayResize(set,c);
            set[c-1]=i+1;
            Print("rings in play = ",i);
            break;
         }
      }
   }
   return(c);
}
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int getPos(int use){
   use-=1;
   for(int i=0;i<3;i++){
      if(Symbol()==pairs[use][i])return(i);
   }
   return(-1);
}

int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   double get[]={0,100};
   double fibs[3][2];
   int use[];
   getrings(use);
   
  // int z;
  // if(Symbol()=="EURUSD")z=EU;   
  // if(Symbol()=="GBPUSD")z=GU; 
  // if(Symbol()=="EURGBP")z=EG; 
   //=ROUND(1/((1/B4)*B2),4)
   for(int p=0;p<3;p++){
      if(use[p]<=0 || use[p]==EMPTY_VALUE)continue;
      int pos=getPos(use[p]);
      for(int i=0;i<Bars-counted_bars;i++){
         datetime time=Time[i];
         getFibs(get,fibs,time,use[p]);
         if(pos==0){
            if(p==0){
               ExtMapBuffer1[i]=NormalizeDouble(fibs[1][0]*fibs[2][0],Digits);
               ExtMapBuffer2[i]=NormalizeDouble(fibs[1][1]*fibs[2][1],Digits);
            }
            if(p==1){
               ExtMapBuffer3[i]=NormalizeDouble(fibs[1][0]*fibs[2][0],Digits);
               ExtMapBuffer4[i]=NormalizeDouble(fibs[1][1]*fibs[2][1],Digits);
            }
            if(p==2){
               ExtMapBuffer5[i]=NormalizeDouble(fibs[1][0]*fibs[2][0],Digits);
               ExtMapBuffer6[i]=NormalizeDouble(fibs[1][1]*fibs[2][1],Digits);
            }
         }
         if(pos==2){
            if(p==0){
               ExtMapBuffer1[i]=NormalizeDouble(1/((1/fibs[0][0])*fibs[1][0]),Digits); //NormalizeDouble(fibs[GU][0]*fibs[EG][0],Digits);
               ExtMapBuffer2[i]=NormalizeDouble(1/((1/fibs[0][1])*fibs[1][1]),Digits);
            }
            if(p==1){
               ExtMapBuffer3[i]=NormalizeDouble(1/((1/fibs[0][0])*fibs[1][0]),Digits); //NormalizeDouble(fibs[GU][0]*fibs[EG][0],Digits);
               ExtMapBuffer4[i]=NormalizeDouble(1/((1/fibs[0][1])*fibs[1][1]),Digits);
            }
            if(p==2){
               ExtMapBuffer5[i]=NormalizeDouble(1/((1/fibs[0][0])*fibs[1][0]),Digits); //NormalizeDouble(fibs[GU][0]*fibs[EG][0],Digits);
               ExtMapBuffer6[i]=NormalizeDouble(1/((1/fibs[0][1])*fibs[1][1]),Digits);
            }
            
         }
         if(pos==1){
            if(p==0){
               ExtMapBuffer1[i]=NormalizeDouble(1/((1/fibs[0][0])*fibs[2][0]),Digits); //NormalizeDouble(fibs[GU][0]*fibs[EG][0],Digits);
               ExtMapBuffer2[i]=NormalizeDouble(1/((1/fibs[0][1])*fibs[2][1]),Digits);
            }
            if(p==1){
               ExtMapBuffer3[i]=NormalizeDouble(1/((1/fibs[0][0])*fibs[2][0]),Digits); //NormalizeDouble(fibs[GU][0]*fibs[EG][0],Digits);
               ExtMapBuffer4[i]=NormalizeDouble(1/((1/fibs[0][1])*fibs[2][1]),Digits);
            }
            if(p==2){
               ExtMapBuffer5[i]=NormalizeDouble(1/((1/fibs[0][0])*fibs[2][0]),Digits); //NormalizeDouble(fibs[GU][0]*fibs[EG][0],Digits);
               ExtMapBuffer6[i]=NormalizeDouble(1/((1/fibs[0][1])*fibs[2][1]),Digits);
            } 
         } 
      }
      draw(0,ExtMapBuffer1[0]);
      draw(100,ExtMapBuffer2[0]);
      draw(10,ExtMapBuffer3[0]);
      draw(1100,ExtMapBuffer4[0]);
      draw(20,ExtMapBuffer5[0]);
      draw(2100,ExtMapBuffer6[0]);
   }
   string k;
   string col[]={"<<WHITE>>","<<PINK>>","<<MAGENTA>>"};
   for(p=0;p<3;p++){
      k=k+"\n"+col[p];
      for(i =0;i<3;i++){
         k=k+" "+pairs[use[p]-1][i];
      }
   }
   Comment(k);
//----
   return(0);
  }
//+------------------------------------------------------------------+


int getFibs(double use[],double& set[][],datetime time,int ring){
   ring-=1;
   int mode;int c;
   for(int e=0;e<3;e++){
      if(TimeDayOfWeek(time)==1)int s=iBarShift(pairs[ring][e],1440,time-(60*60*24*3));
      else s=iBarShift(pairs[ring][e],1440,time-(60*60*24));
      double range=iHigh(pairs[ring][e],1440,s)-iLow(pairs[ring][e],1440,s);
      //Print(Sym[e],"  ",range);
      if(iClose(pairs[ring][e],1440,s) < iOpen(pairs[ring][e],1440,s) ){
         double startprice=iLow(pairs[ring][e],1440,s);
         mode=LOW;
      }else{
         startprice=iHigh(pairs[ring][e],1440,s);
         mode=HIGH;
      }
      for(int i=0;i<ArraySize(use);i++){
         //ArrayResize(set,i+1);
         if(mode==LOW){
            set[e][i]=NormalizeDouble(startprice+(range*(use[i]/100)),MarketInfo(pairs[ring][e],MODE_DIGITS));
            //Print(Sym[e],"  ",set[e][i]);
         }
         else if (mode==HIGH){
            set[e][i]=NormalizeDouble(startprice-(range*(use[i]/100)),MarketInfo(pairs[ring][e],MODE_DIGITS));
            //Print(Sym[e],"  ",set[e][i]);
         }
         c++;
      }
   }
   if(c<=0)return(-1);
   return(mode);
}

int draw(double n,double t1){
   //for(int i=0;i<ArraySize(n);i++){
      string name = StringConcatenate(n," Line");
      if(ObjectFind(name) != 0){
         ObjectCreate(name, OBJ_HLINE, 0, Time[0],t1);
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
         ObjectSet(name, OBJPROP_COLOR, White);
      } else {
         ObjectMove(name, 0, Time[0],t1);
      }
   
}

Comments