Binario_3_v1

Author: Provided by sencho, coded by don_forex
Profit factor:
9034.81

Okay, here's a breakdown of what this script does, explained in a way that avoids technical jargon and is easy for someone who doesn't know programming to understand:

This script is designed to automatically place and manage buy and sell orders for a specific financial instrument (like a currency pair) on the MetaTrader platform. It aims to profit from price movements by strategically setting up orders based on certain calculated levels.

Here's the core idea: The script monitors the price and places pending "buy stop" and "sell stop" orders. These are basically instructions to automatically buy if the price rises to a certain level, or sell if the price falls to a certain level. The script uses moving averages as reference points to determine these levels. Moving averages smooth out the price data over a period of time, which can help to identify trends.

Here's a more detailed step-by-step explanation:

  1. Initial Setup and Checks: The script starts by checking if there's enough historical price data available (at least 100 data points) and if the specified "TakeProfit" value is reasonable (at least 10). If not, it stops. The script takes the symbol of the chart where it is running.

  2. Calculating Key Price Levels:

    • It calculates two moving averages of the price, one based on the high price and one based on the low price, both using a period of 144. These moving averages act as key reference points.
    • It then calculates the "BuyPrice" and "SellPrice" based on these moving averages. The "BuyPrice" is set slightly above the high moving average, and the "SellPrice" is set slightly below the low moving average. The "PipDifference" setting determines exactly how far away from these averages the pending orders are placed.
    • "BuyStopLoss" and "SellStopLoss" which are stop losses, are calculated based on the opposite moving average, this is how far we are willing to lose in case the trade goes south, this is set a little below the low moving average for buy trades and a little above the high moving average for sell trades.
    • "BuyTakeProfit" and "SellTakeProfit" define when to close the trades with profit, they are calculated based on the TakeProfit setting.
    • It also calculates how big each trade (in terms of "Lots") should be, based on the account size and the "MaximumRisk" setting. This is to manage risk by ensuring that trades are not too large relative to the available funds.
  3. Managing Existing Orders:

    • The script then looks at all existing orders on the account for the specific trading symbol and that were placed by this script.
    • If it finds a "buy stop" or "sell stop" order, it checks if the stop loss and take profit levels are in sync with the moving averages values and updates those levels to the correct values.
    • If it finds an open "buy" or "sell" position, it checks that the stop loss is not smaller/bigger (depending on the trade) than the calculated stop loss. In this case, the code modifies the order or deletes it, so it later replaces it with a new order.
    • It implements a "trailing stop" feature. This means that if a trade becomes profitable, the stop loss level is automatically moved closer to the current price, locking in profits. The "TrailingStop" setting determines how far the stop loss trails behind the price.
  4. Placing New Orders:

    • The script checks that there are enough funds available on the account to place new orders.
    • Finally, if the current price is between the high and low moving averages, and if the script needs to place a new order (because there isn't one already open, or a pending order already exists), it places a "buy stop" order at the calculated "BuyPrice" and a "sell stop" order at the calculated "SellPrice".

In short, this script automates a trading strategy that involves placing pending orders based on moving averages, managing risk through stop losses and lot size calculations, and potentially maximizing profits through a trailing stop feature. It continually adjusts and manages these orders to adapt to changing market conditions.

Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
15 Views
3 Downloads
0 Favorites
Binario_3_v1
//+------------------------------------------------------------------+
//|                           Copyright 2005, Gordago Software Corp. |
//|                                          http://www.gordago.com/ |
//+------------------------------------------------------------------+
// I want to thank Michal Rutka, michal1@zonnet.nl, for helping me correct
// the mistakes that I made... Good Job!!
#property copyright "Provided by sencho, coded by don_forex"
#property link      "http://www.gordago.com"
//----
extern int TakeProfit=850;
extern int TrailingStop=850;
extern int PipDifference=25;
extern double Lots=0.1;
extern double MaximumRisk=10;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  int start()
  {
   int cnt, ticket;
     if(Bars<100)
     {
      Print("bars less than 100");
      return(0);
     }
     if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);
     }
   string TradeSymbol=Symbol();
   double MA144H=MathRound(iMA(NULL,0,144,0,MODE_EMA,PRICE_HIGH,0)/Point)*Point;
   double MA144L=MathRound(iMA(NULL,0,144,0,MODE_EMA,PRICE_LOW,0)/Point)*Point;
   double Spread=Ask-Bid; // MarketInfo(TradeSymbol,MODE_SPREAD);
   double BuyPrice     =MA144H + Spread+PipDifference*Point;
   double BuyStopLoss  =MA144L - Point;
   double BuyTakeProfit=MA144H +(PipDifference+TakeProfit)*Point;
   double SellPrice    =MA144L -(PipDifference)*Point;
   double SellStopLoss =MA144H + Spread+Point;
   double SellTakeProfit= MA144L - Spread-(PipDifference+TakeProfit)*Point;
   double lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/50000,1);
   double close=iClose(NULL,0,0);
   int total=OrdersTotal();
//----
   bool need_long =true;
   bool need_short=true;
   // First update existing orders.
     for(cnt=0;cnt<total;cnt++) 
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
        if(OrderSymbol()==Symbol() && OrderMagicNumber()==16384)
        {
           if(OrderType()==OP_BUYSTOP)
           {
            need_long=false;
              if (OrderStopLoss()!=BuyStopLoss)
              {
               Print(BuyStopLoss, " ",OrderStopLoss());
               OrderModify(OrderTicket(),BuyPrice,BuyStopLoss,BuyTakeProfit,0,Green);
              }
           }
           if(OrderType()==OP_SELLSTOP)
           {
            need_short=false;
              if (OrderStopLoss()!=SellStopLoss)
              {
               Print(SellStopLoss, " ",OrderStopLoss());
               OrderModify(OrderTicket(),SellPrice,SellStopLoss,SellTakeProfit,0,Green);
              }
           }
           if(OrderType()==OP_BUY)
           {
            need_long=false;
              if (OrderStopLoss()<BuyStopLoss)
              {
               Print(BuyStopLoss, " ",OrderStopLoss());
               OrderModify(OrderTicket(),OrderOpenPrice(),BuyStopLoss,BuyTakeProfit,0,Green);
               OrderDelete(OrderTicket());
              }
              if(TrailingStop>0) 
              {
                 if(Bid-OrderOpenPrice()>Point*TrailingStop) 
                 {
                    if(OrderStopLoss()<Bid-Point*TrailingStop) 
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
           if(OrderType()==OP_SELL)
           {
            need_short=false;
              if (OrderStopLoss()>SellStopLoss)
              {
               Print(SellStopLoss, " ",OrderStopLoss());
               OrderModify(OrderTicket(),OrderOpenPrice(),SellStopLoss,SellTakeProfit,0,Green);
               OrderDelete(OrderTicket());
              }
              if(TrailingStop>0) 
              {
                 if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) 
                 {
                    if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) 
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
     if(AccountFreeMargin()<(1000*lot))
     {
      Print("We have no money. Free Margin = ", AccountFreeMargin());
      return(0);
     }
     if (close<MA144H && close>MA144L)
     {
      if(need_long)
         ticket=OrderSend(Symbol(),OP_BUYSTOP,lot,BuyPrice,3,BuyStopLoss,BuyTakeProfit,"Binario_v3",16384,0,Green);
      if(need_short)
         ticket=OrderSend(Symbol(),OP_SELLSTOP,lot,SellPrice,3,SellStopLoss,SellTakeProfit,"Binario_v3",16384,0,Red);
     }
  }
//+------------------------------------------------------------------+

Profitability Reports

EUR/USD Jul 2025 - Sep 2025
158890.02
Total Trades 11
Won Trades 3
Lost trades 8
Win Rate 27.27 %
Expected payoff 32657470.00
Gross Profit 359234439.60
Gross Loss -2260.90
Total Net Profit 359232178.70
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
103099.19
Total Trades 19
Won Trades 5
Lost trades 14
Win Rate 26.32 %
Expected payoff 16526639.00
Gross Profit 314009194.90
Gross Loss -3045.70
Total Net Profit 314006149.20
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.66
Total Trades 44
Won Trades 13
Lost trades 31
Win Rate 29.55 %
Expected payoff 317.35
Gross Profit 35147.40
Gross Loss -21183.80
Total Net Profit 13963.60
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.19
Total Trades 90
Won Trades 20
Lost trades 70
Win Rate 22.22 %
Expected payoff 69.18
Gross Profit 38981.30
Gross Loss -32755.50
Total Net Profit 6225.80
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
1.13
Total Trades 111
Won Trades 23
Lost trades 88
Win Rate 20.72 %
Expected payoff 28.00
Gross Profit 27346.79
Gross Loss -24239.25
Total Net Profit 3107.54
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.12
Total Trades 167
Won Trades 47
Lost trades 120
Win Rate 28.14 %
Expected payoff 27.95
Gross Profit 44315.18
Gross Loss -39648.13
Total Net Profit 4667.05
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
1.11
Total Trades 51
Won Trades 9
Lost trades 42
Win Rate 17.65 %
Expected payoff 21.60
Gross Profit 11279.37
Gross Loss -10177.83
Total Net Profit 1101.54
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.91
Total Trades 139
Won Trades 30
Lost trades 109
Win Rate 21.58 %
Expected payoff -22.88
Gross Profit 32644.38
Gross Loss -35824.20
Total Net Profit -3179.82
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.91
Total Trades 104
Won Trades 18
Lost trades 86
Win Rate 17.31 %
Expected payoff -15.87
Gross Profit 17551.77
Gross Loss -19202.55
Total Net Profit -1650.78
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.87
Total Trades 138
Won Trades 30
Lost trades 108
Win Rate 21.74 %
Expected payoff -38.10
Gross Profit 33974.98
Gross Loss -39232.46
Total Net Profit -5257.48
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.83
Total Trades 158
Won Trades 44
Lost trades 114
Win Rate 27.85 %
Expected payoff -41.56
Gross Profit 31257.54
Gross Loss -37823.85
Total Net Profit -6566.31
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.79
Total Trades 89
Won Trades 17
Lost trades 72
Win Rate 19.10 %
Expected payoff -25.04
Gross Profit 8482.10
Gross Loss -10710.60
Total Net Profit -2228.50
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.76
Total Trades 43
Won Trades 6
Lost trades 37
Win Rate 13.95 %
Expected payoff -50.36
Gross Profit 7002.50
Gross Loss -9167.90
Total Net Profit -2165.40
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.73
Total Trades 157
Won Trades 25
Lost trades 132
Win Rate 15.92 %
Expected payoff -52.03
Gross Profit 21923.90
Gross Loss -30092.80
Total Net Profit -8168.90
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.71
Total Trades 58
Won Trades 11
Lost trades 47
Win Rate 18.97 %
Expected payoff -78.62
Gross Profit 11342.91
Gross Loss -15902.91
Total Net Profit -4560.00
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.70
Total Trades 147
Won Trades 21
Lost trades 126
Win Rate 14.29 %
Expected payoff -56.05
Gross Profit 19435.27
Gross Loss -27674.08
Total Net Profit -8238.81
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.70
Total Trades 92
Won Trades 17
Lost trades 75
Win Rate 18.48 %
Expected payoff -31.01
Gross Profit 6775.60
Gross Loss -9628.70
Total Net Profit -2853.10
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.68
Total Trades 90
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -61.91
Gross Profit 11729.00
Gross Loss -17301.00
Total Net Profit -5572.00
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.68
Total Trades 154
Won Trades 25
Lost trades 129
Win Rate 16.23 %
Expected payoff -60.12
Gross Profit 19945.30
Gross Loss -29203.40
Total Net Profit -9258.10
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.68
Total Trades 66
Won Trades 13
Lost trades 53
Win Rate 19.70 %
Expected payoff -61.52
Gross Profit 8595.72
Gross Loss -12655.77
Total Net Profit -4060.05
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.67
Total Trades 106
Won Trades 18
Lost trades 88
Win Rate 16.98 %
Expected payoff -34.76
Gross Profit 7350.69
Gross Loss -11035.28
Total Net Profit -3684.59
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.58
Total Trades 143
Won Trades 21
Lost trades 122
Win Rate 14.69 %
Expected payoff -52.89
Gross Profit 10661.30
Gross Loss -18225.20
Total Net Profit -7563.90
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.55
Total Trades 66
Won Trades 10
Lost trades 56
Win Rate 15.15 %
Expected payoff -64.04
Gross Profit 5216.79
Gross Loss -9443.27
Total Net Profit -4226.48
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.54
Total Trades 59
Won Trades 12
Lost trades 47
Win Rate 20.34 %
Expected payoff -61.42
Gross Profit 4335.40
Gross Loss -7958.90
Total Net Profit -3623.50
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.52
Total Trades 142
Won Trades 23
Lost trades 119
Win Rate 16.20 %
Expected payoff -58.39
Gross Profit 9093.50
Gross Loss -17385.50
Total Net Profit -8292.00
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.42
Total Trades 48
Won Trades 8
Lost trades 40
Win Rate 16.67 %
Expected payoff -121.35
Gross Profit 4171.10
Gross Loss -9996.10
Total Net Profit -5825.00
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.36
Total Trades 120
Won Trades 17
Lost trades 103
Win Rate 14.17 %
Expected payoff -65.42
Gross Profit 4493.71
Gross Loss -12344.09
Total Net Profit -7850.38
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.27
Total Trades 79
Won Trades 8
Lost trades 71
Win Rate 10.13 %
Expected payoff -96.73
Gross Profit 2796.10
Gross Loss -10437.67
Total Net Profit -7641.57
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.25
Total Trades 114
Won Trades 9
Lost trades 105
Win Rate 7.89 %
Expected payoff -83.47
Gross Profit 3175.16
Gross Loss -12691.16
Total Net Profit -9516.00
-100%
-50%
0%
50%
100%

Comments