Trabajo finalizado
![](https://c.mql5.com/i/avatar/avatar_na2.png)
![](https://c.mql5.com/i/avatar/avatar_na2.png)
Tarea técnica
Hi.So Here is what i want to EA to do. EA needs to work in all instruments and all timeframes.It needs to opedate only trades it has taken.I Want to have These values so that i can change them :Time to trade,Daily profit target and max loss target(if hit stop trading fo the day), EMA values ,Rsi values and atr values all can be changed.
For buy Check if its trading time,check if daily target is hit,Buy if fast Ema (13,can be changed) crosses above slow Ema (50,can be changed) and RSI is above (50 can be changed).So Buy only Once When Crosses above and Sell only when crosses below an RSI IS below (50 can be changed) set takeprofit ATR (2 can be changed) and stoploss ATR (1can be changed).
And Code needs to be open so it can be edited.
#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)
#define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
input int InpMagicNumber = 123456; //Magic Number
void OnStart() {
int ticket;
// Set the values for the variables that can be changed by the user
int timeToTrade = 90000; // Time to start trading (in seconds since midnight)
double dailyProfitTarget = 100.0; // Daily profit target in dollars
double maxLossTarget = 50.0; // Maximum loss target in dollars
int fastEmaPeriod = 13; // Period for the fast EMA
int slowEmaPeriod = 50; // Period for the slow EMA
int rsiPeriod = 14; // Period for the RSI
int rsiThreshold = 50; // Threshold for the RSI
double atrTakeProfit = 2.0; // ATR multiple for the take profit
double atrStopLoss = 1.0; // ATR multiple for the stop loss
// Check if it's time to start trading
if (TimeCurrent() >= timeToTrade) {
// Calculate the current daily profit or loss
double dailyProfit = AccountInfoDouble(ACCOUNT_PROFIT);
// Check if the daily profit or loss has reached the target
if (dailyProfit >= dailyProfitTarget || dailyProfit <= -maxLossTarget) {
// End the script if the profit or loss target has been reached
return;
}
// Calculate the values for the fast and slow EMAs
double fastEma = iMA(NULL, 0, fastEmaPeriod, 13, MODE_EMA, PRICE_CLOSE, 0);
double slowEma = iMA(NULL, 0, slowEmaPeriod, 26, MODE_EMA, PRICE_CLOSE, 0);
//// Calculate the value for the RSI
double rsi = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, 0);
// Calculate the value for the ATR
double atr = iATR(NULL, 0, 14, 0);
MqlTradeRequest request;
MqlTradeResult result;
// Check if the fast EMA has crossed above the slow EMA
if (fastEma > slowEma) {
// Check if the RSI is above the threshold
if (rsi > rsiThreshold) {
while (true) {
// Place a buy order
request.type = OP_BUY;
request.volume = 0.1;
request.price = Ask;
request.slippage = 3;
request.magic = 0;
request.take_profit = Ask + atrTakeProfit * atr;
request.stop_loss = Ask - atrStopLoss * atr;
request.comment = "EA Order";
request.expiration = 0;
request.arrow_color = Green;
if((m_position.Magic() == InpMagicNumber) && (m_position.Symbol() == m_symbol.Name()))
if (OrderSend(request, result)) {
// Order has been placed successfully
} else {
// An error occurred while placing the order
Print("Error code: ", GetLastError());
}
}
} else if (fastEma < slowEma) {
// Check if the RSI is below the threshold
if (rsi < rsiThreshold) {
// Place a sell order
request.type = OP_SELL;
request.price = Bid;
request.take_profit = Bid - atrTakeProfit * atr;
request.stop_loss = Bid + atrStopLoss * atr;
request.arrow_color = Red;
if (OrderSend(request, result)) {
// Order has been placed successfully
} else {
// An error occurred while placing the order
Print("Error code: ", GetLastError());
}
}
}