FPI_wibitiens_v0.2_ModRingandLots
Download scriptThis automated trading tool, known as the Fractional Product Inefficiency (FPI) Expert Advisor, is designed to identify and capitalize on mathematical imbalances between different currency pairs. Instead of looking at a single market in isolation, the system analyzes the relationship between three specific currencies simultaneously to detect "inefficiencies"—moments where the price of one currency is slightly out of alignment with the others.
Core Logic and Methodology
The Mathematical "Ring" Concept The strategy operates on a concept called a "Ring." It takes three different currency pairs (for example, GBP/USD, EUR/USD, and EUR/GBP) and performs a specific mathematical calculation: it multiplies two prices together and divides them by the third. The goal is to find a balance point. In a perfectly balanced market, this calculation should result in a specific value (targeted near 1.000).
Identifying Opportunities The software constantly monitors the real-time market data for these three pairs. It is looking for a specific mathematical "dip" or "peak." When the calculated FPI value falls below a predetermined threshold, the system identifies an inefficiency. It interprets this as a signal that the market is temporarily distorted and will likely move to correct itself.
Execution Strategy When the system detects this inefficiency (and provided there are no current trades running), it automatically executes three simultaneous trades:
- It opens a Sell position on the first currency pair.
- It opens Buy positions on the remaining two currency pairs.
By taking these opposite positions at the same time, the strategy aims to profit from the market's natural correction toward equilibrium.
Profit Management and Automation The tool is designed for "hands-off" management with a focus on total account growth:
- Real-Time Monitoring: The script constantly calculates your current floating profit across all active trades.
- Automatic Exit: You can set a specific "Total Profit" goal. Once the combined profit of all three active trades reaches your target amount, the system will automatically trigger an alert and close all positions instantly.
- Visual Feedback: While running, the tool provides a live dashboard on your screen, showing you the time remaining until the next price candle, the current mathematical FPI values, and your real-time profit status.
In summary, this script acts as a sophisticated arbitrage-style monitor that looks for mathematical gaps between correlated currencies, executes a balanced set of trades to capture those gaps, and automatically secures your profits once your goals are met.
// ----------------------------------------------------------------------------- //
// FPI - Fractional Product Inefficiency EA //
// © 2007 by wibitiens - Forex TSD //
// Thanks to: //
// Michal Kreslik, from where this method was adopted //
// URL = http://kreslik.com/forums/viewtopic.php?t=307&highlight=fpi //
// Nicholishen for building the (FPI) predictive price //
// URL = http://www.forex-tsd.com/indicators-metatrader-4/ //
// 6008-fpi-predictive-price.html?highlight=Ring //
// ----------------------------------------------------------------------------- //
#property copyright "Copyright © 2007, wibitiens"
#property link "http://www.forex-tsd.com/"
extern double TotalProfit = 75;
extern double LoFPI = 0.9999;
extern double HiFPI = 1.0003;
extern string Rings = "=== Currency pairs setting ===";
extern string ring1 = "GBPUSD";
extern string ring2 = "EURUSD";
extern string ring3 = "EURGBP";
extern double lot1 = 4;
extern double lot2 = 2;
extern double lot3 = 1;
double HProfit = -999999;
double LProfit = 999999;
double HFPI = -9;
double LFPI = 9;
int magic = 9502;
int start()
{
int TO = OrdersTotal();
// ===== Time to Next Bar
double seco= (Time[4]-Time[5])-MathMod(CurTime(),Time[4]-Time[5]);
double minu=seco/60;
seco=(minu-MathFloor(minu))*60;
minu=MathFloor(minu);
// ===== Get FPI Value
double bid1 = MarketInfo(ring1,MODE_BID);
double bid2 = MarketInfo(ring2,MODE_BID);
double bid3 = MarketInfo(ring3,MODE_BID);
double FPI = bid2 * bid3 * (1/bid1);
if ((FPI<LoFPI)&&(TO==0))
{
OrderSend(ring1,OP_SELL, lot1, MarketInfo(ring1,MODE_BID), 2, NULL, NULL, "FPI", magic, NULL, FireBrick);
OrderSend(ring2,OP_BUY, lot2, MarketInfo(ring2,MODE_ASK), 2, NULL, NULL, "FPI", magic, NULL, LimeGreen);
OrderSend(ring3,OP_BUY, lot3, MarketInfo(ring3,MODE_ASK), 2, NULL, NULL, "FPI", magic, NULL, LimeGreen);
}
// ===== Get Account Profit and Update Highest Profit
double Profit = AccountProfit();
if (TO==3)
{
if (HProfit<Profit) HProfit = Profit;
if (Profit<LProfit) LProfit = Profit;
if (HFPI<FPI) HFPI = FPI;
if (FPI<LFPI) LFPI = FPI;
}
// ===== Write Comment
Comment("Time to Next Bar = ",minu," : ",seco,"\n",
"Ring : ",ring1," - ",ring2," - ",ring3,"\n",
"FPI = ",FPI," : ",LFPI," to ",HFPI,"\n",
"Profit = ",Profit," : ",LProfit," to ",HProfit
);
// ===== If Target Profit reached then Close All Orders
if ((Profit>=TotalProfit)&&(TO==3))
{
Alert("Total Profit of ",TotalProfit," has been reach. Closing all trades now!");
CloseAllOpens();
// Reset Highest Profit
HProfit = -999999;
}
return(0);
}
// =========================================================================================== //
// C L O S E A L L O P E N P O S I T I O N //
// =========================================================================================== //
void CloseAllOpens()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
}
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments