Wednesday, October 2, 2024

OpenAI Library MT5 by StormWave Consumer’s Handbook – Buying and selling Methods – 9 February 2024

TECHNICAL MANUAL

This weblog is meant as a quick technical information to start out utilizing the OpenAI API and exploit the large potential supplied by way of synthetic intelligence, specifically Giant Language Fashions, utilized to buying and selling.

Hyperlink to buy the Library:

https://www.mql5.com/en/market/product/112766?supply=Unknown

First you want to proceed to incorporate the connected file StormWaveOpenAI.mqh, which incorporates the courses and the header of the library, in order that you do not have to fret about the rest.

As soon as the library has been included, we will begin with a very easy instance, which is the commented supply code for the “OpenAI API” Professional Advisor, which you’ll be able to obtain at no cost and check with my OpenAI API on the following hyperlink:
https://www.mql5.com/en/market/product/112756?supply=Web site+Market+Product+Web page

Let’s proceed!

 #embody <StormWaveOpenAI.mqh>       

enter string OPENAI_API_KEY_ = "" ;  
enter string MESSAGE_ = "" ;         
enter int MAX_TOKEN_ = 300 ;         

COpenAI *consumer;                     
CMessages *_message_;               

string __api_key__ = OPENAI_API_KEY_;




int OnInit ()
  {

   if ( MQLInfoInteger ( MQL_TESTER ))
       return ( INIT_FAILED );

   consumer = iOpenAI(__api_key__); 
   

   consumer.ParseCache();
   consumer.start_thread();             
   string completion;






   _message_ = iMessages();           
   string system_content = "You're a technical {and professional} monetary assistant specializing in foreign exchange chart evaluation and reply in a most of 40 phrases within the language of the final message despatched by the consumer" ; 
   _message_.AddMessage(system_content, system); 

   string warning = "Warning. You're utilizing API KEY, so you might be restricted to getting into a shorter message!n" +
                     "If you wish to enter an extended message you should use your API KEY." +
                     "You may get them by going to the next URL : https://platform.openai.com/api-keys " ;

   string user_content = MESSAGE_;

   int str_tokens = consumer.CalculateTokens(MESSAGE_);
   if (str_tokens > MAX_TOKEN_)
      MB_ICONWARNING );
       return ( INIT_FAILED );
     
   user_content = MESSAGE_;

   _message_.AddMessage(user_content, consumer);           
   int token = is_personal_key ? MAX_TOKEN_ : 100 ;


   completion = consumer.completions_create(
                       "gpt-3.5-turbo-0125" , 
                       _message_,           
                       300 ,                 
                       1.0                    
                );

   :: MessageBox (consumer.PrintResultMessage(), "Outcome" , MB_OK | MB_ICONINFORMATION ); 
   DeletePointer(_message_);
   DeletePointer(consumer);

   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 ;
     }
  }

Properly on this instance we’ve got created a easy EA that responds to questions made by way of the enter window.

Different examples will comply with quickly with the usage of instruments (i.e. capabilities) and with the usage of GPT-Imaginative and prescient’s Pc Imaginative and prescient.

Thanks for studying this text!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles