//+-----------------------------------------------------------+ //| mp6140 GBPUSD Daily Hedge EA for MetaTrader4 | //| version 3.1 | //| original idea from mp6140 | //| EA conversion by azmel | //+-----------------------------------------------------------+ //| VERSION HISTORY | //| 1 Initial version. Settings for three AccountTypes. New | //| trades won't open until previous trades closes. | //| 2 Fixed SELL bug | //| 3 Added Money Management and Take Profit. New hedge | //| regardless of previous hedge closed or not. | //| 3.1 Hedge can be opened by the minute instead of by the | //| the hour. | //+-----------------------------------------------------------+ //| INSTRUCTIONS | //| To be used on GBPUSD pair only with any timeframe. EA | //| will place a hegde (a BUY and a SELL simultaneously) at | //| exactly 8pm EST with Take Profit of 10 and zero Stop | //| Loss. 8pm EST (or 1am GMT) is the GBPUSD's daily refence | //| line. In the next 24 hours when London and New York | //| opens, the market will cross this line. Thus by placing a | //| hedge on the starting point will ensure a consistent 20 | //| pips per day. | //+-----------------------------------------------------------+ //| SETTINGS | //| AccountType=0 for Standard (1 Lot) Accounts | //| AccountType=1 for Mini (0.1 Lot) Accounts | //| AccountType=2 for Micro (0.01 Lot) Accounts | //| AccountType=3 for InterbankFX Nano (0.01 Lot) Accounts | //+-----------------------------------------------------------+ #include extern int Magic = 54288; extern int HourToTrade = 1; extern int MinuteToTrade = 0; extern double Lots = 0.1; extern int TakeProfit = 10; extern int StopLoss = 0; extern bool MoneyManagement = false; extern int PercentageToTrade = 40; extern int AccountType = 1; extern int Leverage = 100; double MaxLots; double DecimalCorrection; int DecimalPlaces; int i; int OpenOrders; double PricePerPip; int TradeFlag; int OKToTrade; int ticket1; int ticket2; int err; int start() { if (AccountType==0) { PricePerPip = 10; DecimalCorrection = 0.5; DecimalPlaces = 0; } if (AccountType==1) { PricePerPip = 10; DecimalCorrection = 0.05; DecimalPlaces = 1; } if (AccountType==2) { PricePerPip = 10; DecimalCorrection = 0.005; DecimalPlaces = 2; } if (AccountType==3) { PricePerPip = 1; DecimalCorrection = 0.005; DecimalPlaces = 2; } if (MoneyManagement) { if (PercentageToTrade > 50) { Comment("ERROR: PercentageToTrade value too large."); OKToTrade=0; } else { if (PercentageToTrade < 1) { Comment("ERROR: PercentageToTrade value too small."); OKToTrade=0; } else { Lots=NormalizeDouble(((AccountFreeMargin()*PercentageToTrade*Leverage)/ (Ask*PricePerPip*1000000))-DecimalCorrection,DecimalPlaces); OKToTrade=1; } } } else { MaxLots=NormalizeDouble(((AccountFreeMargin()*50*Leverage)/ (Ask*PricePerPip*1000000))-DecimalCorrection,DecimalPlaces); if (Lots > MaxLots) { Comment("ERROR: Insufficient Free Margin.\nLower Lots value or use MoneyManagement."); OKToTrade=0; } else { OKToTrade=1; } } if (OKToTrade) { if (TradeFlag==0 && Hour()==HourToTrade && Minute()==MinuteToTrade) { if (StopLoss == 0) { ticket1=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,0,Ask+TakeProfit*Point,"mp6140-Buy",Magic,Blue); if (ticket1 == -1) { err=GetLastError(); Print("ERROR ",err,": ",ErrorDescription(err)," at ", Hour(),":",Minute()); } ticket2=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,0,Bid-TakeProfit*Point,"mp6140-Sell",Magic,Red); if (ticket2 == -1) { err=GetLastError(); Print("ERROR ",err,": ",ErrorDescription(err)," at ", Hour(),":",Minute()); } TradeFlag=1; } else { ticket1=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point,"mp6140-Buy",Magic,Blue); if (ticket1 == -1) { err=GetLastError(); Print("ERROR ",err,": ",ErrorDescription(err)," at ", Hour(),":",Minute()); } ticket2=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Bid+StopLoss*Point,Bid-TakeProfit*Point,"mp6140-Sell",Magic,Red); if (ticket2 == -1) { err=GetLastError(); Print("ERROR ",err,": ",ErrorDescription(err)," at ", Hour(),":",Minute()); } TradeFlag=1; } } if (TradeFlag==1 && Hour() != HourToTrade) { TradeFlag=0; } /* The following routine is for version 01, where no new trades will be opened until previous trades closes. if (TradeFlag==1 && Hour() != HourToTrade) { OpenOrders=0; for(i=0;i