FPI_wibitiens_v0.2_ModRingandLots





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





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