Predictive_Price_FPIv2

Download script
Author: Copyright � 2007, MetaQuotes Software Corp.
Predictive_Price_FPIv2

The "Price Predictor" script is designed to provide visual price markers on a trading chart by analyzing the relationship between different currency pairs. Instead of looking at a single currency in isolation, the logic operates on the principle of inter-market correlation—essentially identifying how movements in one market affect others simultaneously.

Core Logic and Functionality

1. Correlation Grouping (The "Rings") The script identifies specific groups of three currency pairs that have a mathematical relationship with one another. These are defined as "Rings." For example, it looks at how three different pairs interact to create a balanced market equilibrium. The script is pre-configured with 14 of these specific groupings.

2. Dynamic Price Calculation The tool works by calculating a "Fair Price Index" (FPI). It continuously monitors the real-time prices of all currencies within its defined groups. By observing how these pairs move together, the script calculates a mathematical average or "equilibrium point."

When it determines this value, it translates that data back into a specific price level for the currency pair currently visible on your chart. If the current market price deviates significantly from this calculated level, the script suggests where the "fair" price should be based on the surrounding market activity.

3. Real-Time Visual Feedback To make this data usable for a trader, the script automatically draws horizontal lines on your chart:

  • Automatic Updates: The script refreshes almost instantly (every 100 milliseconds), meaning the lines move in real-time as the market fluctuates.
  • Visual Identification: Each "Ring" is assigned a unique color (such as Yellow, Orange, Pink, etc.). This allows you to see at a glance how many different market correlations are influencing the current price and where their respective equilibrium points lie.
  • Dynamic Labeling: The chart provides a text summary in the corner, listing the active Rings and their status, helping you keep track of which mathematical models are currently being calculated.

User Experience Summary

For a non-technical user, this tool acts as a "magnet" indicator. It identifies the mathematical "center" of the market based on multiple currency interactions simultaneously. Rather than just telling you what the price is, it shows you where the price should be according to the broader web of global currency movements, helping to highlight potential overextended moves or areas of stability.

12 Views
0 Downloads
0 Favorites
Predictive_Price_FPIv2
//+------------------------------------------------------------------+
//|                                              Price Predictor.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern bool IsMini= false;
extern bool UseBid= true;
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
};

int itn;string cal[14];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(IsMini){
      for(int i=0;i<14;i++){
         for(int y=0;y<3;y++){
            pairs[i][y]=pairs[i][y]+"m";
         }
      }
   }
   start();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   while(true){
      RefreshRates();
      main();
      itn++;
      Sleep(100);
   }
//----
   return(0);
  }
  
  
//+------------------------------------------------------------------+

void main(){
   color col[]={Yellow,Orange,Pink,YellowGreen,Purple,Red};
   string colst[]={"Yellow","Orange","Pink","YellowGreen","Purple","Red"};
   int match[];int c;
   for(int i=0;i<14;i++){
      for(int y=0;y<3;y++){
         if(pairs[i][y]==Symbol()){
            c++;
            ArrayResize(match,c);
            match[c-1]=i;
         }
      }
   }
   c=0;
   
   int size=ArraySize(match);
   /*for(i=0;i<size;i++){
      Comment("ring found ",match[i],"\n\n",
      pairs[match[i]][0],"  ",
      pairs[match[i]][1],"  ",
      pairs[match[i]][2],"  ");
      Sleep(2000);
   }
      */
   //Comment("\nMatches = ",size,"\nIterations = ",itn);
   static double fpi[];
   ////////////////////
   getFPI(match,fpi);////////////////
   ////////////////////
   for(i=0;i<size;i++){
      double level=0;
      if(UseBid)double pr1=MarketInfo(pairs[match[i]][0],MODE_BID);else pr1= MarketInfo(pairs[match[i]][0],MODE_ASK);
      if(UseBid)double pr2=MarketInfo(pairs[match[i]][1],MODE_BID);else pr2= MarketInfo(pairs[match[i]][1],MODE_ASK);
      if(UseBid)double pr3=MarketInfo(pairs[match[i]][2],MODE_BID);else pr3= MarketInfo(pairs[match[i]][2],MODE_ASK);
      pr1=1/pr1;
      for(y=0;y<3;y++){
         if(Symbol()==pairs[match[i]][y]){
            c++;
            if(y==0){
            level=fpi[match[i]]/(pr2*pr3);
            level=1/level;
            break;
            }
            if(y==1){
            level=fpi[match[i]]/(pr1*pr3);
            break;
            }
            if(y==2){
            level=fpi[match[i]]/(pr1*pr2);
            break;
            }
         }
      }
      //level=NormalizeDouble(level,Digits);
      //level+=i*Point;
      string name=Symbol()+DoubleToStr(i,0);
      drawLine(NormalizeDouble(level,Digits),name,col[i],1);
    
   }
   string k;
   for(i=0;i<size;i++){
      k=k+"\n";
      for(y=0;y<3;y++){
         k=k+pairs[match[i]][y]+" ";
      }
      k=k+StringConcatenate(" ( ",colst[i]," )",cal[match[i]]);
   }
   Comment("RINGS:\n",k);
}
      
void getFPI(int match[],double& fpi[])
{
   if(ArraySize(fpi)!=14)ArrayResize(fpi,14);
   int size=ArraySize(match);
   static double fpiavg[14][200];  
   static double lasttick[14];
   for(int i=0;i<size;i++){
      if(!UseBid){
         double aaa=(1/MarketInfo(pairs[match[i]][0],MODE_ASK))*MarketInfo(pairs[match[i]][1],MODE_ASK)*MarketInfo(pairs[match[i]][2],MODE_ASK);
      }else{
         aaa =(1/MarketInfo(pairs[match[i]][0],MODE_BID))*MarketInfo(pairs[match[i]][1],MODE_BID)*MarketInfo(pairs[match[i]][2],MODE_BID);
      }
      if(aaa!=lasttick[match[i]]){
         lasttick[match[i]]=aaa;
         for(int y=200-1;y>0;y--){
            fpiavg[match[i]][y]=fpiavg[match[i]][y-1];
         }
         fpiavg[match[i]][0]=aaa;
         int c=0;double total=0;
         while(fpiavg[match[i]][c]!=0){
            total+=fpiavg[match[i]][c];
            c++;
         }
         //if(c<3)cal[match[i]]=" (Calibrating) ";else cal[match[i]]="";
         
         fpi[match[i]]=total/c;
         Print("FPI new average on ",i," # ",c,"  avg :",fpi[match[i]]);
      }
   }
}
         
      
void drawLine(double lvl,string name, color Col,int type){
   if(ObjectFind(name) != 0){
      ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
      if(type == 1)
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      else
         ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(name, OBJPROP_COLOR, Col);
      ObjectSet(name,OBJPROP_WIDTH,1);
   }else{
      ObjectDelete(name);
      ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
      if(type == 1)
         ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      else
         ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(name, OBJPROP_COLOR, Col);        
      ObjectSet(name,OBJPROP_WIDTH,1);
   }
}
      
         

Comments