News Room



This blog is intended as a brief technical guide to start using the OpenAI API and exploit the enormous potential offered by the use of artificial intelligence, in particular Large Language Models, applied to trading.

Link to purchase the Library:

First you need to proceed to include the attached file StormWaveOpenAI.mqh, which contains the classes and the header of the library, so that you don’t have to worry about anything else.

Once the library has been included, we can start with a really simple example, which is the commented source code for the “OpenAI API” Expert Advisor, which you can download for free and test with my OpenAI API at the following link:

Let’s proceed!

 #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__); 

   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 : " ;

   string user_content = MESSAGE_;

   int str_tokens = client.CalculateTokens(MESSAGE_);
   if (str_tokens > MAX_TOKEN_)
      :: MessageBox (warning, "Error" , MB_OK | MB_ICONWARNING );
       return ( INIT_FAILED );
   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" , 
                       300 ,                 

   :: MessageBox (client.PrintResultMessage(), "Result" , MB_OK | MB_ICONINFORMATION ); 

   return ( INIT_SUCCEEDED );

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 ;

Well in this example we have created a simple EA that responds to questions made through the input window.

Other examples will follow soon with the use of tools (i.e. functions) and with the use of GPT-Vision’s Computer Vision.

Thanks for reading this article!


Source link

Leave a Reply

Your email address will not be published. Required fields are marked *