OpenAI Library MT5 by StormWave User Manual – Trading System – February 9, 2024
technical manual
This blog is intended as a brief technical guide to get started using the OpenAI API and take advantage of the enormous potential offered by artificial intelligence applied to trading, especially the use of large-scale language models.
Library purchase link:
https://www.mql5.com/en/market/product/112766?source=Unknown
First you need to include the attachment StormWaveOpenAI.mqh, which contains the classes and library headers, so you don’t have to worry about anything else.
Once the library is included, you can start with a really simple example. This is the annotated source code for the “OpenAI API” Expert Advisor. You can download this example for free and test it with the OpenAI API at the following link.
https://www.mql5.com/en/market/product/112756?source=Site+Market+Product+Page
Let’s continue!
#include <StormWaveOpenAI.mqh> input string OPENAI_API_KEY_ = "" ; input string MESSAGE_ = "" ; input int MAX_TOKEN_ = 300 ; COpenAI *client; CMessages *_message_; string __api_key__ = OPENAI_API_KEY_; int OnInit () if ( MQLInfoInteger ( MQL_TESTER )) return ( INIT_FAILED ); client = iOpenAI(__api_key__); client.ParseCache(); client.start_thread(); string completion; _message_ = iMessages(); string system_content = "You are a technical and professional financial assistant specializing in forex chart analysis and respond in a maximum of 40 words in the language of the last message sent by the user" ; _message_.AddMessage(system_content, system); string warning = "Warning. You are using API KEY, so you are limited to entering a shorter message!\n" + "If you want to enter a longer message you can use your API KEY." + "You can get them by going to the following URL : https://platform.openai.com/api-keys " ; string user_content = MESSAGE_; int str_tokens = client.CalculateTokens(MESSAGE_); if (str_tokens > MAX_TOKEN_) :: MessageBox (warning, "Error" , MB_OK user_content = MESSAGE_; _message_.AddMessage(user_content, user); int token = is_personal_key ? MAX_TOKEN_ : 100 ; completion = client.completions_create( "gpt-3.5-turbo-0125" , _message_, 300 , 1.0 ); :: MessageBox (client.PrintResultMessage(), "Result" , MB_OK void OnTick () if ( MQLInfoInteger ( MQL_TESTER )) return ; ExpertRemove (); template < typename T> void DeletePointer(T* &ptr) if (:: CheckPointer (ptr) == POINTER_DYNAMIC && ptr != NULL ) delete ptr; ptr = NULL ;
In this example, we created a simple EA that answers questions asked through an input window.
Other examples of the use of tools (i.e. features) and computer vision in GPT-Vision will follow shortly.
Thanks for reading this article!