mp6140's Hedge v3.1

Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open orders
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
14.00 %
Total Trades 130
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -5.84
Gross Profit 125.00
Gross Loss -884.70
Total Net Profit -759.70
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
3.00 %
Total Trades 130
Won Trades 121
Lost trades 9
Win Rate 0.93 %
Expected payoff -29.90
Gross Profit 121.00
Gross Loss -4007.80
Total Net Profit -3886.80
-100%
-50%
0%
50%
100%
mp6140's Hedge v3.1
//+-----------------------------------------------------------+
//|              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 <stdlib.mqh>

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<OrdersTotal();i++)   
         {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
	        {				
	  	        OpenOrders++;
	        }
	      }
	   
         if (OpenOrders == 0)
	      {
            TradeFlag=0;
         }
      }
*/
   }
   
   if (OKToTrade && TradeFlag == 0)
   {
      if (MinuteToTrade<10)
      {
         Comment("AccountType = ",AccountType,"\nLots = ",Lots,"\nNext trade will open at ",HourToTrade,":0",MinuteToTrade);
      }
      else
      {
         Comment("AccountType = ",AccountType,"\nLots = ",Lots,"\nNext trade will open at ",HourToTrade,":",MinuteToTrade);
      }
   }
   
   if (OKToTrade && TradeFlag == 1)
   {
      Comment("AccountType = ",AccountType,"\nLots = ",Lots,"\nOrders are active.");
   }

   return(0);
}

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 ---