İzle
1
0
Çatalla
Warrior_EA deposunu zaten çatalladınız
0
şundan çatallanmış animatedread/Warrior_EA
Warrior_EA/references/MQL5/Experts/CT/Study.mq5

268 satır
21 KiloByte
MQL5
HamKalıcı BağlantıNormal GörünümGeçmiş

<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 = 1e4;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
STrajectory Buffer[];
CNet Agent;
CNet Worker;
//---
float dError;
datetime dtStudied;
//---
CBufferFloat State;
CBufferFloat *Result;
vector<float> Actions;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
ResetLastError();
if(!LoadTotalBase())
{
PrintFormat("Error of load study data: %d", GetLastError());
return INIT_FAILED;
}
//--- load models
float temp;
if(!Worker.Load(FileName + "Work.nnw", temp, temp, temp, dtStudied, true))
{
PrintFormat("Error of load worker model: %d", GetLastError());
return INIT_FAILED;
}
if(!Agent.Load(FileName + "Act.nnw", temp, temp, temp, dtStudied, true))
{
CArrayObj *agent = new CArrayObj();
if(!CreateDescriptions(agent))
{
delete agent;
return INIT_FAILED;
}
if(!Agent.Create(agent))
{
delete agent;
return INIT_FAILED;
}
delete agent;
//---
}
//---
Worker.SetOpenCL(Agent.GetOpenCL());
Worker.TrainMode(false);
//---
Worker.getResults(Result);
if(Result.Total() != NActions)
{
PrintFormat("The scope of the worker does not match the actions count (%d <> %d)", NActions, Result.Total());
return INIT_FAILED;
}
//---
Worker.GetLayerOutput(0, Result);
if(Result.Total() != WorkerInput)
{
PrintFormat("Input size of Worker model doesn't match skills count (%d <> %d)", Result.Total(), WorkerInput);
return INIT_FAILED;
}
//---
Agent.getResults(Result);
if(Result.Total() != WorkerInput)
{
PrintFormat("The scope of the Agent does not match the skills count (%d <> %d)", WorkerInput, Result.Total());
return INIT_FAILED;
}
//---
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)
{
//---
Agent.Save(FileName + "Act.nnw", 0, 0, 0, TimeCurrent(), true);
delete Result;
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
if(id == 1001)
Train();
}
//+------------------------------------------------------------------+
//| Train function |
//+------------------------------------------------------------------+
void Train(void)
{
int total_tr = ArraySize(Buffer);
uint ticks = GetTickCount();
float err=0;
int err_count=0;
//---
bool StopFlag = false;
for(int iter = 0; (iter < Iterations && !IsStopped() && !StopFlag); iter ++)
{
int tr = (int)((MathRand() / 32767.0) * (total_tr - 1));
int i = (int)((MathRand() * MathRand() / MathPow(32767, 2)) * MathMax(Buffer[tr].Total - 2 * HistoryBars-ValueBars,MathMin(Buffer[tr].Total,20+ValueBars)));