Vigiar
1
0
Derivar
Você já tinha feito uma derivação do repositório okWarrior_EA, anteriormente
0
okWarrior_EA/references/MQL5/Experts/CFPI/StudyCritic.mq5

247 linhas
19 KiB
MQL5

<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Study.mq5 |
//| Copyright DNG<EFBFBD> |
//| https://www.mql5.com/en/users/dng |
//+------------------------------------------------------------------+
#property copyright "Copyright DNG<00>"
#property link "https://www.mql5.com/en/users/dng"
#property version "1.00"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#define Study
#include "Trajectory.mqh"
//+------------------------------------------------------------------+
//| Input parameters |
//+------------------------------------------------------------------+
input int Iterations = 1e6;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
STrajectory Buffer[];
CNet StateEncoder;
CNet Critic1;
CNet Critic2;
//---
float dError;
datetime dtStudied;
//---
CBufferFloat State;
CBufferFloat Account;
CBufferFloat Actions;
CBufferFloat Gradient;
CBufferFloat *Result;
//---
COpenCLMy *OpenCL;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
ResetLastError();
if(!LoadTotalBase())
{
PrintFormat("Error of load study data: %d", GetLastError());
return INIT_FAILED;
}
//--- load models
float temp;
if(!StateEncoder.Load(FileName + "Enc.nnw", temp, temp, temp, dtStudied, true) ||
!Critic1.Load(FileName + "Crt1.nnw", temp, temp, temp, dtStudied, true) ||
!Critic2.Load(FileName + "Crt2.nnw", temp, temp, temp, dtStudied, true))
{
Print("Init new models");
CArrayObj *actor = new CArrayObj();
CArrayObj *critic = new CArrayObj();
CArrayObj *encoder = new CArrayObj();
if(!CreateDescriptions(actor, critic, encoder))
{
delete actor;
delete critic;
delete encoder;
return INIT_FAILED;
}
if(!Critic1.Create(critic) || !Critic2.Create(critic) ||
!StateEncoder.Create(encoder))
{
delete actor;
delete critic;
delete encoder;
return INIT_FAILED;
}
delete actor;
delete critic;
delete encoder;
//---
}
//---
OpenCL = Critic1.GetOpenCL();
Critic2.SetOpenCL(OpenCL);
StateEncoder.SetOpenCL(OpenCL);
//---
StateEncoder.getResults(Result);
if(Result.Total() != LatentCount)
{
PrintFormat("The scope of the State Encoder does not match the latent size count (%d <> %d)", LatentCount, Result.Total());
return INIT_FAILED;
}
//---
StateEncoder.GetLayerOutput(0, Result);
if(Result.Total() != (HistoryBars * BarDescr))
{
PrintFormat("Input size of State Encoder doesn't match state description (%d <> %d)", Result.Total(), (HistoryBars * BarDescr));
return INIT_FAILED;
}
//---
Critic1.GetLayerOutput(0, Result);
if(Result.Total() != LatentCount)
{
PrintFormat("Input size of Critic1 doesn't match State Encoder output (%d <> %d)", Result.Total(), LatentCount);
return INIT_FAILED;
}
//---
Critic2.GetLayerOutput(0, Result);
if(Result.Total() != LatentCount)
{
PrintFormat("Input size of Critic2 doesn't match State Encoder output (%d <> %d)", Result.Total(), LatentCount);
return INIT_FAILED;
}
//---
Gradient.BufferInit(AccountDescr, 0);
//---
if(!EventChartCustom(ChartID(), 1, 0, 0, "Init"))
{
PrintFormat("Error of create study event: %d", GetLastError());
return INIT_FAILED;
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)