FPI_wibitiens_002

Author: Copyright � 2007, wibitiens
Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
FPI_wibitiens_002
// ----------------------------------------------------------------------------- //
//                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<LoFPI)&&(TO==0))
   {
      OrderSend(S1,OP_SELL, Lot, MarketInfo(S1,MODE_BID), 2, NULL, NULL, "FPI", magic, NULL, FireBrick);
      OrderSend(S2,OP_BUY, Lot, MarketInfo(S2,MODE_ASK), 2, NULL, NULL, "FPI", magic, NULL, LimeGreen);
      OrderSend(S3,OP_BUY, Lot, 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);
    }  
  }
  
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---