Predictive_Price_FPIv2.2
Download scriptOverview of the Price Predictor Logic
The Price Predictor is a specialized trading tool designed to identify and visualize mathematical relationships between different currency pairs. Instead of relying on traditional indicators like moving averages or RSI, this script utilizes a concept called "Rings." These are groups of three related currency pairs that share a mathematical correlation.
By analyzing how these three specific pairs interact with one another, the script attempts to calculate a theoretical "equilibrium" level for your current chart.
How the Logic Works
1. The "Ring" System The script contains a pre-defined database of 14 different "Rings." Each Ring consists of a triplet of currency pairs (for example: EURJPY, EURAUD, and AUDJPY). These triplets are curated based on how their movements typically balance each other out in the global market.
2. Automatic Detection and Customization When you first load the script, it scans your current chart to see if the currency pair you are trading belongs to any of these 14 Rings. If it finds a match, it will prompt you with a message asking if you would like to "track" that specific Ring. If you agree, the script begins monitoring that mathematical relationship.
3. Dynamic Average Calculation (FPI) The core engine of the script works by calculating a value known as the FPI (Frequency Price Index). It looks at the real-time prices of all three pairs in a selected Ring simultaneously. It maintains a running historical average of these combined values.
Essentially, the script is "watching" the balance of the entire group. If one pair moves up while the others move down in a specific ratio, the script tracks this movement to determine where the price should logically settle based on the other two components of the Ring.
4. Visual Prediction Once the mathematical balance is calculated, the script projects a visual horizontal line onto your chart.
- The Goal: This line represents the calculated "fair value" or level derived from the rest of the Ring.
- Visual Cues: Each Ring is assigned a unique color (such as Yellow, Orange, Pink, etc.). The script automatically draws these lines on your screen, updating them in real-time as market prices fluctuate.
Summary for the User
In simple terms, this tool tells you: "Based on how these three other related currencies are behaving right now, here is where the price of the currency you are currently watching should logically be trading." It provides a visual reference point to help you identify potential overextended prices or areas of equilibrium.
//+------------------------------------------------------------------+
//| 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"
#include <WinUser32.mqh>
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 match[];
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";
}
}
}
int c;
for( i=0;i<14;i++){
for( y=0;y<3;y++){
if(pairs[i][y]==Symbol()){
string ord="";
for(int h=0;h<3;h++){
ord=ord+pairs[i][h]+" ";
}
if(MessageBox(ord,"Would you like track this RING?", MB_YESNO | MB_ICONQUESTION)==6){
c++;
ArrayResize(match,c);
match[c-1]=i;
}
}
}
}
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 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(int 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(int 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