Breakthrough_BB

Profit factor:
0.78

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
19 Views
6 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

USD/JPY Jul 2025 - Sep 2025
0.59
Total Trades 30
Won Trades 8
Lost trades 22
Win Rate 26.67 %
Expected payoff -6.83
Gross Profit 292.21
Gross Loss -497.17
Total Net Profit -204.96
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.78
Total Trades 28
Won Trades 5
Lost trades 23
Win Rate 17.86 %
Expected payoff -3.50
Gross Profit 352.55
Gross Loss -450.66
Total Net Profit -98.11
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.63
Total Trades 27
Won Trades 8
Lost trades 19
Win Rate 29.63 %
Expected payoff -4.36
Gross Profit 196.48
Gross Loss -314.24
Total Net Profit -117.76
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.62
Total Trades 23
Won Trades 6
Lost trades 17
Win Rate 26.09 %
Expected payoff -3.48
Gross Profit 130.50
Gross Loss -210.50
Total Net Profit -80.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.98
Total Trades 29
Won Trades 9
Lost trades 20
Win Rate 31.03 %
Expected payoff -0.25
Gross Profit 421.50
Gross Loss -428.80
Total Net Profit -7.30
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.39
Total Trades 63
Won Trades 8
Lost trades 55
Win Rate 12.70 %
Expected payoff -4.59
Gross Profit 188.60
Gross Loss -477.67
Total Net Profit -289.07
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.96
Total Trades 29
Won Trades 14
Lost trades 15
Win Rate 48.28 %
Expected payoff -0.48
Gross Profit 350.27
Gross Loss -364.32
Total Net Profit -14.05
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
1.01
Total Trades 25
Won Trades 8
Lost trades 17
Win Rate 32.00 %
Expected payoff 0.16
Gross Profit 330.50
Gross Loss -326.60
Total Net Profit 3.90
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.01
Total Trades 25
Won Trades 9
Lost trades 16
Win Rate 36.00 %
Expected payoff 0.07
Gross Profit 197.30
Gross Loss -195.60
Total Net Profit 1.70
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.59
Total Trades 74
Won Trades 19
Lost trades 55
Win Rate 25.68 %
Expected payoff -8.21
Gross Profit 872.16
Gross Loss -1479.81
Total Net Profit -607.65
-100%
-50%
0%
50%
100%

Comments