Trabalho concluído
![](https://c.mql5.com/i/avatar/avatar_na2.png)
Termos de Referência
Please create an EA code for MT4 MQL4 platform to execute the following rules.
Configuration:
Add in the name Chart Smart Trading in red color to the chart when it is plugged in.
Rules:
Take profit for Buy position should be set using a risk to reward ratio of 1:3 with a trailing stop loss option under configuration that can be set by user with Start, step and end.
Take Profit for sell position should be set with a risk to reward ratio of 1:3 with a trailing stop loss option under configuration that can be set by user with start, step and end.
Must be able to change the color of the font and background of the display under configuration.
I have this code I was working from but had two errors and not sure if it was correct. See below code.
#property copyright "Copyright (c) 2021 Chart Smart Trading"
#property link "https://www.chartsmart-trading.com"
#property version "1.00"
#property strict
input double Lots=0.01;
input double TrailingStopStart=100;
input double TrailingStopStep=10;
input double TrailingStopEnd=200;
input int TradeDays=127;
input int StartHour=0;
input int StartMinute=0;
input int EndHour=23;
input int EndMinute=59;
string ChartName = "Chart Smart Trading";
color ChartNameColor=clrRed;
int ticket;
int orderType;
double stopLoss;
double takeProfit;
int OnInit()
{
ObjectCreate(0, ChartName, OBJ_LABEL, 0, 0, 0);
ObjectSetText(ChartName, ChartName, 12, "Arial", ChartNameColor);
return(INIT_SUCCEEDED);
}
void OnTick()
{
int day = DayOfWeek();
if (TradeDays & (1 << day))
{
int time = TimeCurrent();
int currHour = TimeHour(time);
int currMinute = TimeMinute(time);
if (currHour >= StartHour && currHour <= EndHour && currMinute >= StartMinute && currMinute <= EndMinute)
{
double ema21 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 0);
double vwap = iCustom(NULL, 0, "vwap", 0, 0);
double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
double k, d;
Stochastic(NULL, 0, 14, 5, 3, 3, MODE_SMA, MODE_SMA, k, d);
if (Close[0] < ema21 && Close[0] > vwap && rsi < 20 && CrossOver(k, d))
{
orderType = OP_BUY;
stopLoss = Low[1] - 100 * Point;
takeProfit = High[1];
ticket = OrderSend(NULL, orderType, Lots, Ask, 3, stopLoss, takeProfit, NULL, 0, 0, Green);
if (ticket < 0)
{
Print("Error opening order: ", GetLastError());
}
else
{
if (TrailingStopStart > 0)
{
OrderModify(ticket, Bid, Ask, NormalizeDouble(Bid - TrailingStopStart * Point, Digits), NormalizeDouble(Ask + TrailingStopEnd * Point, Digits), 0, Green);
}
}
}
else if (Close[0] > ema21 && Close[0] < vwap && rsi > 80 && CrossUnder(k, d))
{
orderType = OP_SELL;
stopLoss = High[1] + 100 * Point;
takeProfit = Low[1];
ticket = OrderSend(NULL