// ----------------------------------------------------------------------------- // // 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 = 50; extern double LoFPI = 0.9999; extern double HiFPI = 1.0003; 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 string S1 = "EURUSD"; string S2 = "EURGBP"; string S3 = "GBPUSD"; double EU = MarketInfo(S1,MODE_BID); double EG = MarketInfo(S2,MODE_BID); double GU = MarketInfo(S3,MODE_BID); double FPI = EG * GU * (1/EU); if ((FPI<LoFPI)&&(TO==0)) { OrderSend(S1,OP_SELL, 1, MarketInfo(S1,MODE_BID), 2, NULL, NULL, "FPI", magic, NULL, FireBrick); OrderSend(S2,OP_BUY, 1, MarketInfo(S2,MODE_ASK), 2, NULL, NULL, "FPI", magic, NULL, LimeGreen); OrderSend(S3,OP_BUY, 0.67, MarketInfo(S3,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 : ",S1," - ",S2," - ",S3,"\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); } } }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself
Other Features:
It issuies visual alerts to the screen