Author: timbo
Profit factor:
0.40
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Blessing
//+------------------------------------------------------------------+
//|                                       Blessing Martingale_v5.mq4 |
//|                                                            timbo |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "timbo"
#property link      ""

//---- input parameters

extern int     levels = 8;
extern int     TP=40;
extern double  Lots=0.06;
extern bool    UseStopLoss=true;
extern int     magic=111;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
    
   int cmd = 2; double Lot = Lots; double price; int slippage = 4; double stoploss=0; double takeprofit; color colour;
   int BuyTicket = 0;
   int SellTicket = 0;


   BuyTicket = FixTakeProfit(magic,0);

   if(BuyTicket == 0)
   {
      CleanAllPendings(magic,2);
      
      cmd = 0; price = Ask; colour = Green; takeprofit = Ask + TP*Point;
      if(UseStopLoss == true) stoploss = Ask - levels*TP*Point;
      OpenOrder(cmd, Lot, price, slippage, stoploss, takeprofit, magic, colour);
      
      SetPendingOrders(2,Lot,price,slippage,stoploss,TP,magic,levels);
      return(0);
   }

   SellTicket = FixTakeProfit(magic,1);

   if(SellTicket == 0)
   {
      CleanAllPendings(magic,3);
      
      cmd = 1; price = Bid; colour = Red; takeprofit = Bid - TP*Point; 
      if(UseStopLoss == true) stoploss = Bid + levels*TP*Point; 
      OpenOrder(cmd, Lot, price, slippage, stoploss, takeprofit, magic, colour);
      
      SetPendingOrders(3,Lot,price,slippage,stoploss,(-TP),magic,levels);
      return(0);
   }


//----
   return(0);
  }
//+------------------------------------------------------------------+

int OpenOrder(int cmd, double Lot, double price, int slippage, double stoploss, double takeprofit, int magic, color colour)
{
   RefreshRates();
   while(IsTradeAllowed() == false) Sleep(10000);
   int ticket = OrderSend(Symbol(), cmd, Lot, price, slippage, stoploss, takeprofit, NULL, magic, 0, colour);
   if(ticket < 0)
   {
      Print(price," == ",stoploss);
      Alert("!!! Error opening order !!! ", GetLastError());
      ticket = 0;
   }
   return(ticket);
}

//+-------------------------------------------------------

int FixTakeProfit(int magic, int cmd)
{
   int ticket = 0; int i;
   datetime time = 0;
   for(i=0;i<OrdersTotal();i++)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType() == cmd)
      {
         if(OrderOpenTime() > time) { time = OrderOpenTime();ticket = OrderTicket(); }
      }
   }
   
   if(ticket != 0)
   {
      OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
      double takeprofit = OrderTakeProfit();
   
      for(i=0;i<OrdersTotal();i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType() == cmd)
         {
            if(OrderTakeProfit() != takeprofit) 
            { 
               while(IsTradeAllowed() == false) Sleep(10000);
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),takeprofit,0,Yellow); 
            }
         }
      }
   }
   
   return(ticket);
}   
//+------------------------------------------------------

void CleanAllPendings(int magic,int cmd)
{   
      for(int i=OrdersTotal()-1;i>=0;i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType() == cmd)
         {
            int ticket = OrderTicket();
            while(IsTradeAllowed() == false) Sleep(10000);
            OrderDelete(ticket,CLR_NONE);
         }
      }
}

//+-----------------------------------------------------

void SetPendingOrders(int cmd,double Lot,double price,int slippage,double stoploss,int TP,int magic, int levels)
{
   for(int i=0;i<levels-1;i++)
   {
      while(IsTradeAllowed() == false) Sleep(10000);
      OpenOrder(cmd,Lot*MathPow(2,i),price-(i+1)*TP*Point,slippage,stoploss,price-i*TP*Point,magic,CLR_NONE);
   }
   return(0);
}

//+-----------------------------------------------------

Profitability Reports

USD/CAD Oct 2024 - Jan 2025
0.49
Total Trades 3014
Won Trades 1933
Lost trades 1081
Win Rate 64.13 %
Expected payoff -2.69
Gross Profit 7770.58
Gross Loss -15872.23
Total Net Profit -8101.65
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.26
Total Trades 1100
Won Trades 612
Lost trades 488
Win Rate 55.64 %
Expected payoff -8.79
Gross Profit 3403.80
Gross Loss -13069.44
Total Net Profit -9665.64
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.45
Total Trades 1749
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -4.08
Gross Profit 5856.00
Gross Loss -12990.78
Total Net Profit -7134.78
-100%
-50%
0%
50%
100%

Comments