TECHNICAL MANUAL
This weblog is meant as a quick technical information to start out utilizing the OpenAI API and exploit the large potential provided by means of synthetic intelligence, particularly Massive Language Fashions, utilized to buying and selling.
Hyperlink to buy the Library:
https://www.mql5.com/en/market/product/112766?supply=Unknown
First you must proceed to incorporate the connected file StormWaveOpenAI.mqh, which comprises the courses and the header of the library, in order that you do not have to fret about anything.
As soon as the library has been included, we are able to begin with a very easy instance, which is the commented supply code for the “OpenAI API” Skilled Advisor, which you’ll obtain totally free and take a look at 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 might be utilizing API KEY, so you might be restricted to coming into a shorter message!n” +
“If you wish to enter an extended message you need to use your API KEY.” +
“You will 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 created a easy EA that responds to questions made by means of the enter window.
Different examples will observe quickly with the usage of instruments (i.e. features) and with the usage of GPT-Imaginative and prescient’s Laptop Imaginative and prescient.
Thanks for studying this text!