Author: Copyright � 2008, Silas Palmer.
Profit factor:
2.03

This script is designed to automate the process of entering a "Buy" position in the financial markets while simultaneously handling complex risk management calculations. Instead of requiring a trader to manually calculate how much money to risk based on their current balance, the script performs these calculations instantly at the moment of execution.

Core Functionality

Automated Trade Execution The primary purpose of this tool is to immediately open a "Buy" order (a position where you are betting that the price will go up) at the current market price. It simplifies the workflow by removing the need to manually interact with the trading platform's order window for every trade.

Dynamic Money Management The script uses a specific mathematical formula to determine your trade size (the number of "lots"). It looks at your account's available balance and compares it against a user-defined threshold. This ensures that your position size is always proportional to how much money you currently have in your account, helping to maintain consistent risk levels as your balance grows or shrinks.

Smart Market Scaling One of the more sophisticated features of this logic is its ability to remain "currency neutral." Because different trading pairs (like EUR/USD vs. GBP/JPY) have different underlying values, a standard lot size doesn't mean the same thing across all markets. This script automatically detects the specific value of a "pip" (the smallest price movement) for whatever currency pair you are currently viewing. It then scales your trade size so that your risk remains consistent across different markets regardless of the currency being traded.

Safety and Compliance Checks Before placing the trade, the script performs several background checks to ensure the order is valid:

  • Minimum/Maximum Limits: It checks with the broker to ensure the calculated trade size isn't too small or too large for the rules of that specific market.
  • Lot Step Alignment: It rounds the trade size to the nearest "step" allowed by the broker to prevent the order from being rejected due to formatting errors.
  • Slippage Protection: It includes a standard allowance for price fluctuations, ensuring the trade executes even if the market moves slightly in the millisecond between calculation and execution.

Feedback System Finally, the script provides clear feedback to the user. If the trade is successful, it logs the entry price; if something goes wrong (such as insufficient funds or a connection issue), it triggers an immediate alert to notify the trader of the specific error encountered.

Orders Execution
It automatically opens orders when conditions are reached
8 Views
1 Downloads
0 Favorites
buy_v1
//+------------------------------------------------------------------+
//|                                                          buy.mq4 |
//|                      Copyright © 2008, Silas Palmer.             |
//|                                      http://www.silaspalmer.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Silas Palmer."
#property link      "http://www.silaspalmer.com"
#include <stderror.mqh>
#include <stdlib.mqh>

// #property show_confirm
// Uncomment to enable confirmation

//+------------------------------------------------------------------+
//| script "buy at market, using money management as defined below"  |
//+------------------------------------------------------------------+
int start()
  {
   // Change these amounts to suit your needs
   
   int lotbucks = 50000; // 1 lot for every x dollars in your account. 
   int Slippage = 3; // Standard amount
   
   // Note script auto-detects minimum lot size
   // It also automatically scales lots based on currency pair 
   // (so that a 1 pip move will be $1 per lotbuck regardless of the pair chosen)
   
//----
   int cmd = -1; // Nothing (buy=0 sell=1)
   int i;
   double lots,minl,maxl,pipbucks,step; 
   
   // Calculate lots
   pipbucks = MarketInfo(Symbol(),MODE_TICKVALUE);
   minl = MarketInfo(Symbol(),MODE_MINLOT);
   maxl = MarketInfo(Symbol(),MODE_MAXLOT);
   step = MarketInfo(Symbol(),MODE_LOTSTEP);
   // Scale lots so 1 pip = $1 at 1 lot

   lots = MathFloor( (((10 / pipbucks) * AccountFreeMargin()) / lotbucks) / step) * step;
   if (lots < minl) lots = minl;
   if (lots > maxl) lots = maxl;    

   if ( OrderSend( Symbol(), OP_BUY, lots, Ask, Slippage, 0, 0, "Opened Buy Order", 0, 0, Orange ) > 0 )
         Print ( "Opened Buy Order at ", Ask );
      else 
         Alert ( "Could not open Buy order for ", Symbol(), " ", lots, " at ", Ask, " Error=", ErrorDescription(GetLastError()) );
  
  
//----
   return(0);
  }
//+------------------------------------------------------------------+

Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
16 reports
EUR/USD Oct 2025 - Feb 2026
20.69
Total Trades 62
Won Trades 32
Lost trades 30
Win Rate 51.61 %
Expected payoff 1.32
Gross Profit 85.86
Gross Loss -4.15
Total Net Profit 81.71
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
10.43
Total Trades 83
Won Trades 38
Lost trades 45
Win Rate 45.78 %
Expected payoff 8.04
Gross Profit 738.30
Gross Loss -70.77
Total Net Profit 667.53
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.90
Total Trades 81
Won Trades 30
Lost trades 51
Win Rate 37.04 %
Expected payoff -0.54
Gross Profit 388.48
Gross Loss -431.88
Total Net Profit -43.40
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.38
Total Trades 49
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -5.57
Gross Profit 167.52
Gross Loss -440.42
Total Net Profit -272.90
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.07
Total Trades 72
Won Trades 5
Lost trades 67
Win Rate 6.94 %
Expected payoff -6.38
Gross Profit 33.43
Gross Loss -492.48
Total Net Profit -459.05
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
0.05
Total Trades 45
Won Trades 5
Lost trades 40
Win Rate 11.11 %
Expected payoff -4.27
Gross Profit 10.70
Gross Loss -203.00
Total Net Profit -192.30
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00
Total Trades 99
Won Trades 0
Lost trades 99
Win Rate 0.00 %
Expected payoff -13.06
Gross Profit 0.00
Gross Loss -1293.13
Total Net Profit -1293.13
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.00
Total Trades 67
Won Trades 0
Lost trades 67
Win Rate 0.00 %
Expected payoff -25.75
Gross Profit 0.00
Gross Loss -1725.47
Total Net Profit -1725.47
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 45
Won Trades 0
Lost trades 45
Win Rate 0.00 %
Expected payoff -30.04
Gross Profit 0.00
Gross Loss -1351.79
Total Net Profit -1351.79
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.00
Total Trades 35
Won Trades 0
Lost trades 35
Win Rate 0.00 %
Expected payoff -19.33
Gross Profit 0.00
Gross Loss -676.68
Total Net Profit -676.68
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.00
Total Trades 14
Won Trades 0
Lost trades 14
Win Rate 0.00 %
Expected payoff -109.37
Gross Profit 0.00
Gross Loss -1531.23
Total Net Profit -1531.23
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.00
Total Trades 44
Won Trades 0
Lost trades 44
Win Rate 0.00 %
Expected payoff -62.00
Gross Profit 0.00
Gross Loss -2727.92
Total Net Profit -2727.92
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.00
Total Trades 38
Won Trades 0
Lost trades 38
Win Rate 0.00 %
Expected payoff -39.80
Gross Profit 0.00
Gross Loss -1512.52
Total Net Profit -1512.52
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.00
Total Trades 50
Won Trades 0
Lost trades 50
Win Rate 0.00 %
Expected payoff -11.47
Gross Profit 0.00
Gross Loss -573.74
Total Net Profit -573.74
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.00
Total Trades 85
Won Trades 0
Lost trades 85
Win Rate 0.00 %
Expected payoff -21.70
Gross Profit 0.00
Gross Loss -1844.80
Total Net Profit -1844.80
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2025 - Feb 2026
0.00
Total Trades 51
Won Trades 0
Lost trades 51
Win Rate 0.00 %
Expected payoff -20.44
Gross Profit 0.00
Gross Loss -1042.61
Total Net Profit -1042.61
-100%
-50%
0%
50%
100%

Comments