ChatGPT is a large-scale language model trained by OpenAI.
It is said to provide reasonably accurate answers to any questions, so I will proceed with the conversation using a dialogue format with ChatGPT.
Requesting a simple EA to be created
Although it seems that providing more detailed conditions would result in a better EA, let’s start with a vague request.
// Moving Average EA
#property copyright "Copyright 2023, OpenAI"
#property link "https://www.OpenAI.com"
extern int MA_Period = 14;
extern int Slippage = 3;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double MA = iMA(NULL,0,MA_Period,0,MODE_SMA,PRICE_CLOSE,0);
if (Bid > MA)
OrderSend(Symbol(),OP_BUY,0.1,Bid,Slippage,0,0,"My EA",16384,0,clrGreen);
else if (Bid < MA)
OrderSend(Symbol(),OP_SELL,0.1,Bid,Slippage,0,0,"My EA",16384,0,clrRed);
return(0);
}
It seems that it cannot generate long code. However, it did provide us with a sample code.
I’ll now explain the logic and provide the translation of the Japanese blog article into English, leaving the code unchanged.
I will also explain the logic behind it.
This EA implements a trading logic using the Moving Average (MA) indicator.
・The MA_Period variable sets the period for the moving average.
・The Slippage variable sets the slippage.
・The start() function executes the actual trading logic.
・If the Bid price is higher than the moving average, a buy order is issued.
・If the Bid price is lower than the moving average, a sell order is issued.
This EA has a simple trading logic, and more complex logic may be needed in actual trading.
As expected, it can write MQL4 code and explain the overview of it.
By the way, when I tried to compile it as is, there were no errors. It seems to work just fine. The logic is very simple, but it seems to be useful for supplementing EA creation.
Creating an EA using RSI
Continuing on, this time I will ask for an EA using the RSI technical indicator.
// RSI EA
#property copyright "Copyright 2023, OpenAI"
#property link "https://www.OpenAI.com"
extern int RSI_Period = 14;
extern int Slippage = 3;
extern int Overbought = 70;
extern int Oversold = 30;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double RSI = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,0);
if (RSI > Overbought)
OrderSend(Symbol(),OP_SELL,0.1,Bid,Slippage,0,0,"My EA",16384,0,clrRed);
else if (RSI < Oversold)
OrderSend(Symbol(),OP_BUY,0.1,Bid,Slippage,0,0,"My EA",16384,0,clrGreen);
return(0);
}
I will also ask about the logic.
This EA implements a trading logic using the RSI (Relative Strength Index) indicator.
・The RSI_Period variable sets the calculation period for the RSI.
・The Slippage variable sets the slippage.
・The Overbought variable sets the RSI level at which to close buy positions.
・The Oversold variable sets the RSI level at which to close sell positions.
・The start() function executes the actual trading logic.
・If the RSI exceeds the Overbought level, a sell order is issued.
・If the RSI falls below the Oversold level, a buy order is issued.
This EA has a simple trade logic, and more complex logic may be required for actual trading.
The EA’s logic is systematically explained, which is useful just for this feature alone.
I was also able to compile without any issues by simply copying and pasting.
Let’s try asking for the code in MQL5 for MT5 as well.
Now, let’s continue and ask if they can write an EA in MQL5 for MT5 using the same logic.
// RSI EA for MT5
#property copyright "Copyright 2023, OpenAI"
#property link "https://www.OpenAI.com"
input int RSI_Period = 14;
input int Slippage = 3;
input int Overbought = 70;
input int Oversold = 30;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double RSI = iRSI(NULL,0,RSI_Period,MODE_CLOSE,0);
if (RSI > Overbought)
OrderSend(Symbol(),OP_SELL,0.1,Ask,Slippage,0,0,"My EA",16384,0,clrRed);
else if (RSI < Oversold)
OrderSend(Symbol(),OP_BUY,0.1,Ask,Slippage,0,0,"My EA",16384,0,clrGreen);
}
It was an impressive immediate response. Moreover, as it appeared to be almost the same as MT4, I tried compiling it in MT4 and encountered no errors.
On the other hand, when I tried compiling it in MT5, which is the main focus, I received “7 errors, 0 warnings.”
Ask about the cause of the compilation errors
This error indicates that the iRSI function is not being passed the correct arguments.To use the iRSI function in MT5, you need to pass the arguments as follows:
iRSI(string symbol, int timeframe, int period, int applied_price, int shift)
// RSI EA for MT5
#property copyright "Copyright 2023, OpenAI"
#property link "https://www.OpenAI.com"
input int RSI_Period = 14;
input int Slippage = 3;
input int Overbought = 70;
input int Oversold = 30;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double RSI = iRSI(Symbol(),0,RSI_Period,MODE_CLOSE,0);
if (RSI > Overbought)
OrderSend(Symbol(),OP_SELL,0.1,Ask,Slippage,0,0,"My EA",16384,0,clrRed);
else if (RSI < Oversold)
OrderSend(Symbol(),OP_BUY,0.1,Ask,Slippage,0,0,"My EA",16384,0,clrGreen);
}
The first argument of the iRSI function has been corrected from NULL to Symbol().
However, when compiling, the same error occurs. Let’s continue further.
Ask for the cause of the error after the correction
This error indicates that the iRSI function is not being passed the correct arguments.Here is the corrected sample code:
// RSI EA for MT5
#property copyright "Copyright 2023, OpenAI"
#property link "https://www.OpenAI.com"
input int RSI_Period = 14;
input int Slippage = 3;
input int Overbought = 70;
input int Oversold = 30;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double RSI = iRSI(Symbol(), PERIOD_CURRENT, RSI_Period, PRICE_CLOSE, MODE_MAIN, 0);
if (RSI > Overbought)
OrderSend(Symbol(),OP_SELL,0.1,Ask,Slippage,0,0,"My EA",16384,0,clrRed);
else if (RSI < Oversold)
OrderSend(Symbol(),OP_BUY,0.1,Ask,Slippage,0,0,"My EA",16384,0,clrGreen);
}
The arguments have changed again. Compile again and this time, a different error occurs.
Ask for the cause of the new error
This error indicates that MODE_MAIN is not defined.This error may or may not occur depending on the version of MT5. Generally, it can be fixed as follows:
double RSI = iRSI(Symbol(), PERIOD_CURRENT, RSI_Period, PRICE_CLOSE, MODE_RSI, 0);
Even after following the instructions and making corrections, the compilation error remains.
For now, the following seems to be the correct solution, although it might be hard to reach this conclusion.
For now, give up
double RSI = iRSI(Symbol(), PERIOD_CURRENT, RSI_Period, PRICE_CLOSE);
It seems there are also errors in the OrderSend function, and the code appears to be mostly in MQL4.
The person behind the code might not be able to clearly distinguish between MQL4 and MQL5. Moreover, there are different versions and evolutions of MQL5, which might not be well absorbed.
Conclusion
From my brief experience, ChatGPT seemed to be more proficient in MQL4 and struggled with MQL5. It is just like an EA developer who has been working with MQL4 for a long time and cannot adapt to the changes in MQL5.
However, I think that with the right approach to asking questions, there’s a possibility that ChatGPT can handle MQL5 well.
Lastly, I asked this question:
With MT4, if more specific conditions are given, it might develop an excellent EA for us.
Moreover, using it as a dictionary during EA development or for deciding variable names as a support tool might also be effective.
More Advanced ChatGPT (GPT-4)
There is an article on the more advanced ChatGPT (GPT-4) beyond the ChatGPT (GPT-3.5) introduced in this article.
Comments