okWarrior_EA/references/MQL5/Experts/CT/StudyValue.mq5

211 lines
15 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 = 1e7;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
STrajectory Buffer[];
CNet Value;
//---
float dError;
datetime dtStudied;
//---
CBufferFloat State;
CBufferFloat *Result;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
ResetLastError();
if(!LoadTotalBase())
{
PrintFormat("Error of load study data: %d", GetLastError());
return INIT_FAILED;
}
//--- load models
float temp;
if(!Value.Load(FileName + "Val.nnw", temp, temp, temp, dtStudied, true))
{
CArrayObj *value = new CArrayObj();
if(!CreateValueDescriptions(value))
{
delete value;
return INIT_FAILED;
}
if(!Value.Create(value))
{
delete value;
return INIT_FAILED;
}
delete value;
//---
}
//---
Value.getResults(Result);
if(Result.Total() != NRewards)
{
PrintFormat("The scope of the Value does not match the rewards count (%d <> %d)", NRewards, 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)
{
//---
Value.Save(FileName + "Val.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();
int check = 0;
//---
bool StopFlag = false;
for(int iter = 0; (iter < Iterations && !IsStopped() && !StopFlag); iter ++)