MM % Volatility - MetaTrader 4 Script | Trading Script Download - MT4/MT5 Resources
Taking into account asset volatility, lot size and opening positions are calculated according to the market. Stop loss is automatically set, and take profit is set to a multiple of R as needed.
Lot size: = risk amount/(point price * stop loss point);
Risk amount: = available margin * risk percentage / 100;
StopLossPoints:=kATR*ATR(TimeFrame,RiskAtrPeriod)/PointSize;
Profit points: = Stop loss points * Profit and loss ratio.
The working function is Trade, located in the Trade.mq4 library file. declaration:
int Trade(string smb, int TimeFrame, int cmd, bool ShowQ, int Slippage, bool SetProfit, double MaxRiskPercent, int RiskAtrPeriod, double RiskMulATR, double ProfitToLossRatio), where:
smb - asset name;
TimeFrame - used to determine stop loss points;
cmd - OP_BUY or OP_SELL;
ShowQ - displays a dialog box asking for confirmation (False - no dialog box);
Slippage - Slippage in points;
SetProfit - if True - will specify take profit in the order;
MaxRiskPercent - % FreeMargin, risk allowed (2% - classic, 5% - aggressive, higher - based on luck);
RiskAtrPeriod - the number of last bars used to calculate the true range (21 is enough);
RiskMulATR - determine the stop loss point;
ProfitToLossRatio - the multiplicity of R (e.g. 5).
Attached script:
Buy.mq4/Sell.mq4 - Buy/Sell current asset, time frame, with confirmation dialog, slippage 1 pip, 2% risk, RiskAtrPeriod=21, RiskMulATR=1, ProfitToLossRatio=10;
Buy_nonQuery.mq4/Sell_nonQuery.mq4 - same settings, but without dialog and slippage=0.
How to install:
Trade.mqh - copied to the "include" subdirectory of the "experts" directory of the MetaTrader root folder;
Trade.mq4 - copied to the "libraries" subdirectory of the "experts" directory of the MetaTrader root folder and compiled;
Buy.mq4, Buy_nonQuery.mq4, Sell.mq4, Sell_nonQuery.mq4 - copied to the "scripts" subdirectory of the "experts" directory of the MetaTrader root folder and compiled.
Attachment download
📎Buy.mq4 (0.45 KB)
📎Buy_nonQuery.mq4 (0.45 KB)
📎 Sell.mq4 (0.45 KB)
📎 Sell_nonQuery.mq4 (0.46 KB)
📎 Trade.mq4 (3.22 KB)
📎 Trade.mqh (0.51 KB)
Source: MQL5 #7387
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •