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);
      }
   
}



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open prices of each bar
Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: