Breakthrough_BB

Profit factor:
0.81

This script is designed to automatically trade on the MetaTrader platform. Here?s how it works, broken down step-by-step:

  1. Setup: The script starts by defining a few adjustable settings:

    • Period_MA_Long: This determines the period for calculating a long-term moving average. Think of this as the number of past days used to calculate an average price.
    • Period_BB: This sets the period for calculating Bollinger Bands, which are used to measure market volatility. It represents the number of past days used to determine the standard deviation
    • reserve: A parameter to set reserve from bollinger bands used to set the take profit values
    • deviation: A parameter for the calculation of the bollinger bands
    • Lots: The size of the trades the script will make.
  2. Safety Checks: It then performs a series of checks to avoid errors:

    • It makes sure there is enough historical price data available (at least as much as the settings for the moving average and Bollinger Bands require).
    • It verifies that the market is active and trading volume is present.
    • It confirms there's enough money in the trading account to place a trade of the specified size.
  3. Trend Identification: The script calculates several technical indicators to understand the current market trend. These are:

    • Long-term Moving Averages: It calculates two moving averages on daily data. The main comparison is between a more recent day and a past day, based on the Period_MA_Long setting, in order to evaluate the general direction of the trend
    • Bollinger Bands: It calculates the upper, middle and lower bands. These bands widen or narrow depending on how volatile the price is.
  4. Position Management: The script then checks if there are any existing open trades. If there are, it loops through them to consider if the trades must be closed

    • Closing Existing Trades: If the current price action suggests the trend has reversed (specifically if the price crosses the middle Bollinger Band), the script will automatically close the position to preserve profits or limit losses.
  5. Opening New Trades: If there are no open positions, the script evaluates the opportunity to open a new one based on the following logic:

    • Buy Condition: It looks for a situation where the price has recently broken above the upper Bollinger Band and where the Moving Average is trending upwards. If both conditions are met, it opens a "buy" order, betting that the price will continue to rise. The script sets a "take profit" level when opening the position
    • Sell Condition: Conversely, it looks for a situation where the price has recently broken below the lower Bollinger Band and where the Moving Average is trending downwards. If both conditions are met, it opens a "sell" order, betting that the price will continue to fall. The script sets a "take profit" level when opening the position

In essence, this script tries to identify potential buying or selling opportunities based on price breakouts and trend direction. It manages risk by closing trades when the trend appears to reverse, and it only opens new trades when certain criteria are met, based on the calculated technical indicators.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
4 Views
0 Downloads
0 Favorites
Breakthrough_BB
extern int Period_MA_Long = 100;// Ïåðèîä ñðåäíåé, íåîáõîäèìîé äëÿ îïðåäåëåíèÿ òðåíäà
extern int Period_BB = 25; // Ïåðèîä ñðåäíåé áîëèíäæåðà
extern double reserve=50;
extern double deviation = 1.5;
extern double Lots = 0.1; // Âåëè÷èíà ëîòà

int tmp, tc, st, et, dtmp;
//----------------------------------------------------------------------------------------------------------//
int start()
  {
   
   double MA_1_Long,MA_2_Long,BB_MA,BB_n_MA,BB_Up,BB_Low,ATR;
   int cnt, total;
   
//------------------------------------------Çàùèòà îò îøèáîê è êîñÿêîâ--------------------------------------//   
   if(Bars<Period_MA_Long || Bars<Period_BB) // Åñëè êîëè÷åñòâî ñâå÷åé ìåíåå 100
   {
      Print("Êîëè÷åñòâî áàðîâ ñëèøêîì ìàëî");
      return(0);  
   }
   if (Volume[0] < 1.0) // Åñëè òîðãè èäóò çíà÷èò îáüåì áîëåå 0
   {
      Comment("Òîðãîâ íåò.. Æäåì íîâûé áàð..");
      return(0);
   }
   if (AccountFreeMargin()<(1000*Lots)) 
   {
      Comment("Íåäîñòàòî÷íî äåíåã. Óðîâåíü ìàðæè ìåíåå ...");
      return(0);
   }

//-----------------------------------------Êîíåö çàùèòû îò êîñÿêîâ-----------------------------------------//   
      MA_1_Long=iMA(NULL,PERIOD_D1,Period_MA_Long,0,MODE_SMA,PRICE_CLOSE,1);
      MA_2_Long=iMA(NULL,PERIOD_D1,Period_MA_Long,0,MODE_SMA,PRICE_CLOSE,4);
      BB_MA=iCustom(NULL,0,"Bands",Period_BB,0,deviation,0,1);
      BB_n_MA=iCustom(NULL,0,"Bands",Period_BB,0,deviation,0,4);
      BB_Up=iCustom(NULL,0,"Bands",Period_BB,0,deviation,1,1);
      BB_Low=iCustom(NULL,0,"Bands",Period_BB,0,deviation,2,1); 

   total=OrdersTotal();
//-------------------------------------------Çàêðûòèå ïîçèöèé------------------------------------------   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&    
         OrderSymbol()==Symbol())  
        {
         if(OrderType()==OP_BUY)   
           {
               if (Close[1]<BB_MA)
               {
               OrderClose(OrderTicket(),OrderLots(),Bid,50,Violet);
               return(0);
               }
            }    
         if(OrderType()==OP_SELL)   
            {
               if (Close[1]>BB_MA) 
               {
               OrderClose(OrderTicket(),OrderLots(),Ask,50,Violet);
               return(0);
               }
            }
         }
                    
      }
//-----------------------------------------------Êîíåö çàêðûòèÿ ïîçèöèè------------------------------------
   if(total==0) // åñëè íåò ïîçèöèé
     {
      // îòêðûòèå äëèííîé ïîçèöèè
      if(Close[2]<BB_Up && Close[1]>BB_Up && MA_1_Long>MA_2_Long)
        {
        OrderSend(Symbol(),OP_BUY,Lots,Ask,50,BB_Low-reserve*Point,0,"Äëèííàÿ ïîçèöèÿ",16384,0,Green);
        return(0);
        }
      
      // îòêðûòèå êîðîòêîé ïîçèöèè
      if(Close[2]>BB_Low && Close[1]<BB_Low && MA_1_Long<MA_2_Long)
        {
         OrderSend(Symbol(),OP_SELL,Lots,Bid,50,BB_Up+reserve*Point,0,"Êîðîòêàÿ ïîçèöèÿ",16384,0,Red);
         return(0);
        }
     }
return(0);
}

Profitability Reports

EUR/USD Jan 2025 - Jul 2025
1.04
Total Trades 94
Won Trades 22
Lost trades 72
Win Rate 23.40 %
Expected payoff 0.53
Gross Profit 1313.10
Gross Loss -1263.40
Total Net Profit 49.70
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.77
Total Trades 66
Won Trades 20
Lost trades 46
Win Rate 30.30 %
Expected payoff -3.46
Gross Profit 745.20
Gross Loss -973.70
Total Net Profit -228.50
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
1.07
Total Trades 14
Won Trades 5
Lost trades 9
Win Rate 35.71 %
Expected payoff 0.72
Gross Profit 155.47
Gross Loss -145.40
Total Net Profit 10.07
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.56
Total Trades 42
Won Trades 13
Lost trades 29
Win Rate 30.95 %
Expected payoff -4.60
Gross Profit 246.60
Gross Loss -439.90
Total Net Profit -193.30
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.59
Total Trades 40
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -5.95
Gross Profit 340.40
Gross Loss -578.50
Total Net Profit -238.10
-100%
-50%
0%
50%
100%

Comments