Navigation:Home > Content >

FPI_wibitiens.mq4

Time: 2013-03-28 | Download file:FPI_wibitiens.mq4

// ----------------------------------------------------------------------------- //
//                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;
extern int     Lot          = 1.0;

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

Recommend