0% found this document useful (0 votes)
31 views3 pages

New Text Document

The document is a MetaTrader 5 (MT5) Expert Advisor (EA) script for scalping multiple symbols using moving averages and RSI for trading signals. It includes parameters for lot size, moving average periods, RSI period, slippage, stop loss, and take profit settings. The EA initializes indicators, executes buy/sell trades based on crossover signals, and manages trades with specified risk-reward ratios.

Uploaded by

eniskrasniqi1510
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
0% found this document useful (0 votes)
31 views3 pages

New Text Document

The document is a MetaTrader 5 (MT5) Expert Advisor (EA) script for scalping multiple symbols using moving averages and RSI for trading signals. It includes parameters for lot size, moving average periods, RSI period, slippage, stop loss, and take profit settings. The EA initializes indicators, executes buy/sell trades based on crossover signals, and manages trades with specified risk-reward ratios.

Uploaded by

eniskrasniqi1510
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/ 3

//+------------------------------------------------------------------+

//| Scalping_Enko_MultiSymbol_Fixed.mq5 |
//| Copyright 2025, xAI |
//| Modified by Grok 3 |
//+------------------------------------------------------------------+

#property copyright "Copyright 2025, xAI"


#property link "https://x.ai"
#property version "1.08"
#property strict

// Input parameters
input double LotSize = 0.1; // Lot Size
input int FastMAPeriod = 5; // Fast MA Period
input int SlowMAPeriod = 20; // Slow MA Period
input int TrendMAPeriod = 50; // Trend MA Period (for trend filter)
input int RSIPeriod = 14; // RSI Period
input int Slippage = 50; // Slippage in points
input double StopLossPips = 10.0; // Stop Loss in pips
input double TakeProfitPips = 50.0; // Take Profit in pips (1:5 risk-reward ratio)

// Include necessary files


#include <Trade\Trade.mqh>

// Global variables
int handleFastMA = 0; // Handle for Fast Moving Average
int handleSlowMA = 0; // Handle for Slow Moving Average
int handleTrendMA = 0; // Handle for Trend Moving Average
int handleRSI = 0; // Handle for RSI
CTrade trade; // Trade object for order execution

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Create indicators for the chart's symbol
string symbol = _Symbol;
handleFastMA = iMA(symbol, PERIOD_M1, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE);
handleSlowMA = iMA(symbol, PERIOD_M1, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE);
handleTrendMA = iMA(symbol, PERIOD_M1, TrendMAPeriod, 0, MODE_SMA, PRICE_CLOSE);
handleRSI = iRSI(symbol, PERIOD_M1, RSIPeriod, PRICE_CLOSE);

if(handleFastMA == INVALID_HANDLE || handleSlowMA == INVALID_HANDLE ||


handleTrendMA == INVALID_HANDLE || handleRSI == INVALID_HANDLE)
{
Print("Failed to create indicators for ", symbol, ". Error: ",
GetLastError());
return INIT_FAILED;
}

Print("EA initialized successfully for ", symbol);


return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Release indicators
if(handleFastMA != INVALID_HANDLE) IndicatorRelease(handleFastMA);
if(handleSlowMA != INVALID_HANDLE) IndicatorRelease(handleSlowMA);
if(handleTrendMA != INVALID_HANDLE) IndicatorRelease(handleTrendMA);
if(handleRSI != INVALID_HANDLE) IndicatorRelease(handleRSI);
}

//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Get the current symbol and timeframe
string symbol = _Symbol;
ENUM_TIMEFRAMES timeframe = PERIOD_M1; // Scalping on 1-minute timeframe

// Get indicator buffers


double fastMA[], slowMA[], trendMA[], rsi[];
ArraySetAsSeries(fastMA, true);
ArraySetAsSeries(slowMA, true);
ArraySetAsSeries(trendMA, true);
ArraySetAsSeries(rsi, true);

if(CopyBuffer(handleFastMA, 0, 0, 3, fastMA) < 0 ||


CopyBuffer(handleSlowMA, 0, 0, 3, slowMA) < 0 ||
CopyBuffer(handleTrendMA, 0, 0, 3, trendMA) < 0 ||
CopyBuffer(handleRSI, 0, 0, 3, rsi) < 0)
{
Print("Failed to copy indicator buffers for ", symbol, ". Error: ",
GetLastError());
return;
}

// Get current price and point value


double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
double pipValue = point * 10; // Adjust for pip (1 pip = 10 points for most
brokers)

// Calculate stop-loss and take-profit in points


double stoplossPoints = StopLossPips * pipValue;
double takeProfitPoints = TakeProfitPips * pipValue;

// Debugging: Print indicator values to verify data


Print("Symbol: ", symbol, " fastMA[1]: ", fastMA[1], " slowMA[1]: ", slowMA[1],
" trendMA[1]: ", trendMA[1], " rsi[1]: ", rsi[1]);

// Trading logic
bool buySignal = false;
bool sellSignal = false;

// Crossover with RSI and trend filter


if(fastMA[1] > slowMA[1] && fastMA[2] <= slowMA[2] && rsi[1] < 70) // Buy signal
{
bool isUptrend = (fastMA[1] > trendMA[1]);
if (isUptrend)
buySignal = true;
}
if(fastMA[1] < slowMA[1] && fastMA[2] >= slowMA[2] && rsi[1] > 30) // Sell
signal
{
bool isDowntrend = (fastMA[1] < trendMA[1]);
if (isDowntrend)
sellSignal = true;
}

// Execute trades (only if no positions are open)


if(buySignal && PositionsTotal() == 0)
{
double sl = ask - stoplossPoints; // Stop Loss below entry
double tp = ask + takeProfitPoints; // Take Profit above entry

if(trade.Buy(LotSize, symbol, ask, sl, tp, "Scalping Buy on " + symbol))


Print("Buy order executed successfully with SL: ", sl, " TP: ", tp);
else
Print("Buy order failed for ", symbol, ". Error: ", GetLastError());
}

if(sellSignal && PositionsTotal() == 0)


{
double sl = bid + stoplossPoints; // Stop Loss above entry
double tp = bid - takeProfitPoints; // Take Profit below entry

if(trade.Sell(LotSize, symbol, bid, sl, tp, "Scalping Sell on " + symbol))


Print("Sell order executed successfully with SL: ", sl, " TP: ", tp);
else
Print("Sell order failed for ", symbol, ". Error: ", GetLastError());
}
}

//+------------------------------------------------------------------+

You might also like