# Trying to convert a few lines to mt5 from mt4

So below is an EA that I am trying to get to run on mt5. But I cant figure out the corresponding functions which dont always have entries in the conversion document.

Its one of the only really well commented EA's that I'm trying to learn from but I first have to get it to run lol.

Thanks for every bit of advice or help, even if its just partial.

// Define risk multiplier and risk-reward ratio

double riskMultiplier = 2.0;
double riskRewardRatio = 1.5;

// Set up RSI indicator
RSI rsi;
int rsiPeriod = 14;
rsi.create(rsiPeriod);

// Identify range of market
double high = High[iHighest(NULL, 0, MODE_HIGH, rsiPeriod, 1)];
double low = Low[iLowest(NULL, 0, MODE_LOW, rsiPeriod, 1)];

// Monitor RSI for overbought/oversold conditions
double rsiValue = rsi.iRSI(0, rsiPeriod, PRICE_CLOSE, 0);
if(rsiValue > 70)
{
// RSI is overbought, look for swing low to place short trade
double swingLow = Low[iLowest(NULL, 0, MODE_LOW, 10, 1)];
double stopLoss = high + (high - low) * riskRewardRatio;
double takeProfit = swingLow - (high - low) * riskMultiplier;
OrderSend(Symbol(), OP_SELL, 0.1, swingLow, stopLoss, takeProfit);
}
else
if(rsiValue < 30)
{
// RSI is oversold, look for swing high to place long trade
double swingHigh = High[iHighest(NULL, 0, MODE_HIGH, 10, 1)];
double stopLoss = low - (high - low) * riskRewardRatio;
double takeProfit = swingHigh + (high - low) * riskMultiplier;
OrderSend(Symbol(), OP_BUY, 0.1, swingHigh, stopLoss, takeProfit);
}

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

The trading functions, like OrderSend() work totally differently in MQL5 compared to MQL4. MT4 only has Orders while MT5 has Orders, Positions and Deals. The code required to manage trades is way more complex than on MT4.

Also, the use of Indicators in EAs, is different between MQL4 and MQL5. In MQL4 they are accessed directly from the functions, but in MQL5 you fist need to obtain a handle from the indicator function, and then later copy the buffer contents with the CopyBuffer() function, using those indicator handles as references.

EDIT: In other words, converting MQL4 to MQL5 is not always an easy one-to-one conversion. You need to fully understand both languages and platforms to be able to convert/translate MQL4 functionality into MQL5.

1. Use the code button
2. Trading functions are completely different.
3. There are no predefined arrays High/Low.
4. ``` RSI rsi;
int rsiPeriod = 14;
rsi.create(rsiPeriod); ```
Whatever RSI is, internally, it needs a handle. You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.

Reason: