100% found this document useful (3 votes)
10K views2 pages

Alpha V2.0

This document outlines a trading algorithm implemented in MQL4 that utilizes Simple Moving Averages (SMA) for trade entry and exit decisions. It includes risk management features such as drawdown limits and customizable lot sizing based on risk percentage or fixed lot size. The algorithm also incorporates parameters for stop loss and take profit calculations based on the Average True Range (ATR).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
10K views2 pages

Alpha V2.0

This document outlines a trading algorithm implemented in MQL4 that utilizes Simple Moving Averages (SMA) for trade entry and exit decisions. It includes risk management features such as drawdown limits and customizable lot sizing based on risk percentage or fixed lot size. The algorithm also incorporates parameters for stop loss and take profit calculations based on the Average True Range (ATR).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Trade\Trade.

mqh>

CTrade trade;

// 📌 Input Settings
input double Risk_Percentage = 1.0; // % Risk per trade
input double Fixed_Lot = 0.1; // Fixed lot size
input bool Use_Fixed_Lot = false; // Use fixed lot instead of risk %

input int SMA_Fast = 9;


input int SMA_Slow = 21;

input double SL_Multiplier = 1.5;


input double Risk_Reward_Ratio = 3.0; // Default 1:3 RR
input double Alternative_RR = 4.0; // Alternative 1:4 RR

input double Max_Drawdown_Percentage = 10.0;

input string NFP_Direction = "NONE"; // Manual NFP input: "BUY", "SELL", "NONE"

// 📊 Indicator Functions
double GetSMA(int period, int shift) {
return iMA(Symbol(), 0, period, 0, MODE_SMA, PRICE_CLOSE, shift);
}

double GetATR(int period) {


return iATR(Symbol(), 0, period, 0);
}

// 📌 Money Management - Lot Sizing


double CalculateLotSize(double stopLoss) {
if (Use_Fixed_Lot) return Fixed_Lot;

double riskAmount = (Risk_Percentage / 100) * AccountBalance();


double lotSize = riskAmount / (stopLoss * PointValue());

return NormalizeDouble(lotSize, 2);


}

// 🔥 Risk Management - Stop Trading on High Drawdown


bool CheckDrawdownLimit() {
double equity = AccountEquity();
double maxLoss = (Max_Drawdown_Percentage / 100) * AccountBalance();
return (equity < AccountBalance() - maxLoss);
}

// 🚀 Trade Logic - Entry & Exit Rules


void CheckTradeOpportunities() {
if (CheckDrawdownLimit()) return; // Stop trading if drawdown exceeded

double smaFast = GetSMA(SMA_Fast, 0);


double smaSlow = GetSMA(SMA_Slow, 0);
double price = Close[0];

double atr = GetATR(14);


double stopLoss = atr * SL_Multiplier;
double takeProfit = stopLoss * Risk_Reward_Ratio;

double lotSize = CalculateLotSize(stopLoss);


bool allowTrade = (NFP_Direction == "NONE") ||
(NFP_Direction == "BUY" && smaFast > smaSlow) ||
(NFP_Direction == "SELL" && smaFast < smaSlow);

if (!allowTrade) return;

// 🔵 Buy Condition
if (smaFast > smaSlow && price > smaFast) {
double slPrice = Bid - stopLoss;
double tpPrice = Bid + takeProfit;
trade.Buy(lotSize, Symbol(), slPrice, tpPrice, 0, "Buy Order");
}

// 🔴 Sell Condition
if (smaFast < smaSlow && price < smaFast) {
double slPrice = Ask + stopLoss;
double tpPrice = Ask - takeProfit;
trade.Sell(lotSize, Symbol(), slPrice, tpPrice, 0, "Sell Order");
}
}

// 🎯 Main Execution Function


void OnTick() {
CheckTradeOpportunities();
}

You might also like