E-friday_v4

Author: ��� ����� �. aka KimIV
Profit factor:
0.73

This script is designed to automate trading on the Metatrader platform, specifically targeting a strategy related to Friday's price movements. Here's a breakdown of its logic:

Overall Strategy:

The script aims to open a trade on Friday mornings (at a specific hour) based on the previous day's price action. It then manages this trade by potentially closing it on Friday evening, and using a trailing stop to protect profits.

Key Steps:

  1. Initialization: The script starts by reading in several settings (parameters) defined by the user. These settings control things like the size of trades, stop-loss and take-profit levels, trading hours, and risk management preferences. It also checks if it should only trade on a specific account.

  2. Trading Day/Time Check: On each tick, the script verifies that it's Friday and that the current time is within the specified trading hours. If not, it does nothing. This ensures trades are only placed during the intended timeframe.

  3. Opening a Position (Trade):

    • If it's the specified Friday morning hour, the script checks if there are any existing open positions (trades) already managed by it. If not, it proceeds to open a new trade.
    • It looks at the price movement of the previous day. If the price closed lower than it opened on the previous day, it interprets this as a bullish trend and opens a "buy" order. Conversely, if the price closed higher than it opened, it opens a "sell" order.
    • When placing an order, it sets Stop Loss and Take Profit levels, it also specifies a "magic number" to easily identify orders placed by this specific script.
  4. Closing a Position: If it's the specified Friday evening hour (and the "Use Close Position" setting is enabled), the script closes all open positions that it manages on the current currency pair. It does this by sending a closing command to the trading platform.

  5. Trailing Stop:

    • If enabled, the script implements a trailing stop, which automatically adjusts the stop-loss order as the price moves in a favorable direction.
    • The amount the stop-loss trails by is determined by the "Trailing Stop" parameter.
    • The script can be configured to only start trailing the stop once the trade is in profit ("Profit Trailing" setting).
  6. Sound Alerts: The script can optionally play a sound when it opens or closes a trade, or modifies the stop loss, acting as an audible notification of its actions.

In summary: The script is an automated trading system that executes trades based on a simple Friday-focused strategy, opening positions based on the previous day's price movement, and managing those positions with a trailing stop and optional Friday evening closure.

Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
2 Views
0 Downloads
0 Favorites
E-friday_v4
//+------------------------------------------------------------------+
//|                                                     e-Friday.mq4 |
//|                                           Êèì Èãîðü Â. aka KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//| 08.10.2005  Ýôôåêò ïÿòíèöû                                       |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link      "http://www.kimiv.ru"
//-------
#define   MAGIC     20051008
//------- Âíåøíèå ïàðàìåòðû ñîâåòíèêà --------------------------------
extern string _Parameters_Trade="----- Ïàðàìåòðû òîðãîâëè";
extern double Lots           =0.1;    // Ðàçìåð òîðãóåìîãî ëîòà
extern int    StopLoss       =75;     // Ðàçìåð ôèêñèðîâàííîãî ñòîïà
extern int    TakeProfit     =0;      // Ðàçìåð ôèêñèðîâàííîãî òýéêà
extern int    HourOpenPos    =7;      // Âðåìÿ îòêðûòèÿ ïîçèöèè
extern bool   UseClosePos    =True;   // Èñïîëüçîâàòü çàêðûòèå ïîçèöèè
extern int    HourClosePos   =19;     // Âðåìÿ çàêðûòèÿ ïîçèöèè
extern bool   UseTrailing    =True;   // Èñïîëüçîâàòü òðàë
extern bool   ProfitTrailing =True;   // Òðàëèòü òîëüêî ïðîôèò
extern int    TrailingStop   =60;     // Ôèêñèðîâàííûé ðàçìåð òðàëà
extern int    TrailingStep   =5;      // Øàã òðàëà
extern int    Slippage       =3;      // Ïðîñêàëüçûâàíèå öåíû
//----
extern string _Parameters_Expert="----- Ïàðàìåòðû ñîâåòíèêà";
extern bool   UseOneAccount=False;        // Òîðãîâàòü òîëüêî íà îäíîì ñ÷¸òå
extern int    NumberAccount=11111;        // Íîìåð òîðãîâîãî ñ÷¸òà
extern string Name_Expert  ="e-Friday.mq4";
extern bool   UseSound     =True;         // Èñïîëüçîâàòü çâóêîâîé ñèãíàë
extern string NameFileSound="expert.wav"; // Íàèìåíîâàíèå çâóêîâîãî ôàéëà
extern color  clOpenBuy    =LightBlue;    // Öâåò îòêðûòèÿ ïîêóïêè
extern color  clOpenSell   =LightCoral;   // Öâåò îòêðûòèÿ ïðîäàæè
extern color  clModifyBuy  =Aqua;         // Öâåò ìîäèôèêàöèè ïîêóïêè
extern color  clModifySell =Tomato;       // Öâåò ìîäèôèêàöèè ïðîäàæè
extern color  clCloseBuy   =Blue;         // Öâåò çàêðûòèÿ ïîêóïêè
extern color  clCloseSell  =Red;          // Öâåò çàêðûòèÿ ïðîäàæè
//---- Ãëîáàëüíûå ïåðåìåííûå ñîâåòíèêà -------------------------------
//------- Ïîäêëþ÷åíèå âíåøíèõ ìîäóëåé --------------------------------
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
  void deinit() 
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
  void start() 
  {
     if (UseOneAccount && AccountNumber()!=NumberAccount) 
     {
      if (!IsTesting()) Comment("Òîðãîâëÿ íà ñ÷¸òå: "+AccountNumber()+" ÇÀÏÐÅÙÅÍÀ!");
      return;
     }
      else if (!IsTesting()) Comment("");
      if (DayOfWeek()!=5 || Hour()<HourOpenPos || Hour()>HourClosePos) 
      {
      if (!IsTesting()) Comment("Âðåìÿ òîðãîâëè åù¸ íå íàñòóïèëî!");
      return;
     }
      else if (!IsTesting()) Comment("");
   if (Hour()==HourOpenPos) OpenPosition();
   if (Hour()>=HourClosePos && UseClosePos) CloseAllPositions();
   if (UseTrailing) TrailingPositions();
  }
//+------------------------------------------------------------------+
//| Óñòàíîâêà îðäåðîâ                                                |
//+------------------------------------------------------------------+
  void OpenPosition() 
  {
   double ldStop=0, ldTake=0;
   double Op1=iOpen (NULL, PERIOD_D1, 1);
   double Cl1=iClose(NULL, PERIOD_D1, 1);
//----
     if (!ExistPosition()) 
     {
        if (Op1>Cl1) 
        {
         if (StopLoss!=0) ldStop=Ask-StopLoss*Point;
         if (TakeProfit!=0) ldTake=Ask+TakeProfit*Point;
         SetOrder(OP_BUY, Ask, ldStop, ldTake);
        }
        if (Op1<Cl1) 
        {
         if (StopLoss!=0) ldStop=Bid+StopLoss*Point;
         if (TakeProfit!=0) ldTake=Bid-TakeProfit*Point;
         SetOrder(OP_SELL, Bid, ldStop, ldTake);
        }
     }
  }
//+------------------------------------------------------------------+
//| Âîçâðàùàåò ôëàã ñóùåñòâîâàíèÿ ïîçèöèè                            |
//+------------------------------------------------------------------+
  bool ExistPosition() 
  {
   bool Exist=False;
     for(int i=0; i<OrdersTotal(); i++) 
     {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
        {
           if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) 
           {
              if (OrderType()==OP_BUY || OrderType()==OP_SELL) 
              {
               Exist=True; break;
              }
           }
        }
     }
   return(Exist);
  }
//+------------------------------------------------------------------+
//| Óñòàíîâêà îðäåðà                                                 |
//| Ïàðàìåòðû:                                                       |
//|   op     - îïåðàöèÿ                                              |
//|   pp     - öåíà                                                  |
//|   ldStop - óðîâåíü ñòîï                                          |
//|   ldTake - óðîâåíü òåéê                                          |
//+------------------------------------------------------------------+
  void SetOrder(int op, double pp, double ldStop, double ldTake) 
  {
   color  clOpen;
   string lsComm=GetCommentForOrder();
//----
   if (op==OP_BUYLIMIT || op==OP_BUYSTOP) clOpen=clOpenBuy;
   else clOpen=clOpenSell;
   //  Lots=MathCeil(AccountFreeMargin()/10000*10)/10;
   OrderSend(Symbol(),op,Lots,pp,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpen);
   if (UseSound) PlaySound(NameFileSound);
  }
//+------------------------------------------------------------------+
//| Ãåíåðèðóåò è âîçâðàùàåò ñòðîêó êîìåíòàðèÿ äëÿ îðäåðà èëè ïîçèöèè |
//+------------------------------------------------------------------+
  string GetCommentForOrder() 
  {
   return(Name_Expert);
  }
//+------------------------------------------------------------------+
//| Çàêðûòèå âñåõ ïîçèöèé ïî ðûíî÷íîé öåíå                           |
//+------------------------------------------------------------------+
  void CloseAllPositions() 
  {
   bool fc;
     for(int i=OrdersTotal()-1; i>=0; i--) 
     {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
        {
           if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) 
           {
            fc=False;
              if (OrderType()==OP_BUY) 
              {
               fc=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clCloseBuy);
              }
              if (OrderType()==OP_SELL) 
              {
               fc=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clCloseSell);
              }
            if (fc && UseSound) PlaySound(NameFileSound);
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Ñîïðîâîæäåíèå ïîçèöèè ïðîñòûì òðàëîì                             |
//+------------------------------------------------------------------+
  void TrailingPositions() 
  {
     for(int i=0; i<OrdersTotal(); i++) 
     {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
        {
           if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) 
           {
              if (OrderType()==OP_BUY) 
              {
                 if (!ProfitTrailing || (Bid-OrderOpenPrice())>TrailingStop*Point) 
                 {
                    if (OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*Point) 
                    {
                     ModifyStopLoss(Bid-TrailingStop*Point, clModifyBuy);
                    }
                 }
              }
              if (OrderType()==OP_SELL) 
              {
                 if (!ProfitTrailing || OrderOpenPrice()-Ask>TrailingStop*Point) 
                 {
                    if (OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0) 
                    {
                     ModifyStopLoss(Ask+TrailingStop*Point, clModifySell);
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Ïåðåíîñ óðîâíÿ StopLoss                                          |
//| Ïàðàìåòðû:                                                       |
//|   ldStopLoss - óðîâåíü StopLoss                                  |
//|   clModify   - öâåò ìîäèôèêàöèè                                  |
//+------------------------------------------------------------------+
  void ModifyStopLoss(double ldStop, color clModify) 
  {
   bool   fm;
   double ldOpen=OrderOpenPrice();
   double ldTake=OrderTakeProfit();
//----
   fm=OrderModify(OrderTicket(), ldOpen, ldStop, ldTake, 0, clModify);
   if (fm && UseSound) PlaySound(NameFileSound);
  }
//+------------------------------------------------------------------+

Profitability Reports

EUR/USD Jan 2025 - Jul 2025
43957.29
Total Trades 102
Won Trades 84
Lost trades 18
Win Rate 82.35 %
Expected payoff 58177.44
Gross Profit 5934233.70
Gross Loss -135.00
Total Net Profit 5934098.70
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
1.42
Total Trades 33
Won Trades 19
Lost trades 14
Win Rate 57.58 %
Expected payoff 1.33
Gross Profit 148.80
Gross Loss -105.00
Total Net Profit 43.80
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.38
Total Trades 17
Won Trades 7
Lost trades 10
Win Rate 41.18 %
Expected payoff -1.96
Gross Profit 20.08
Gross Loss -53.35
Total Net Profit -33.27
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.60
Total Trades 18
Won Trades 6
Lost trades 12
Win Rate 33.33 %
Expected payoff -1.98
Gross Profit 54.40
Gross Loss -90.00
Total Net Profit -35.60
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.18
Total Trades 20
Won Trades 4
Lost trades 16
Win Rate 20.00 %
Expected payoff -4.92
Gross Profit 21.70
Gross Loss -120.00
Total Net Profit -98.30
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
1.07
Total Trades 16
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 0.30
Gross Profit 72.30
Gross Loss -67.50
Total Net Profit 4.80
-100%
-50%
0%
50%
100%

Comments