Warrior_EA/references/MQL5/Experts/Evalutionary/Evolution-test.mq5

242 lines
18 KiB
MQL5

<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Q-Learning.mq5 |
//| Copyright 2022, DNG |
//| https://www.mql5.com/en/users/dng |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, DNG"
#property link "https://www.mql5.com/en/users/dng"
#property version "1.00"
//+------------------------------------------------------------------+
//| Includes |
//+------------------------------------------------------------------+
#include "..\NeuroNet_DNG\NeuroNet.mqh"
#include <Trade\SymbolInfo.mqh>
#include <Indicators\Oscilators.mqh>
#include <Trade\Trade.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#define FileName Symb.Name()+"_"+EnumToString((ENUM_TIMEFRAMES)Period())+"_Evolution"
#define NeuronsToBar 12
//+------------------------------------------------------------------+
//| Input parameters |
//+------------------------------------------------------------------+
uint HistoryBars = 20; //Depth of history
ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;
int Actions = 3;
//---
input group "---- RSI ----"
input int RSIPeriod = 14; //Period
input ENUM_APPLIED_PRICE RSIPrice = PRICE_CLOSE; //Applied price
//---
input group "---- CCI ----"
input int CCIPeriod = 14; //Period
input ENUM_APPLIED_PRICE CCIPrice = PRICE_TYPICAL; //Applied price
//---
input group "---- ATR ----"
input int ATRPeriod = 14; //Period
//---
input group "---- MACD ----"
input int FastPeriod = 12; //Fast
input int SlowPeriod = 26; //Slow
input int SignalPeriod = 9; //Signal
input ENUM_APPLIED_PRICE MACDPrice = PRICE_CLOSE; //Applied price
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CSymbolInfo Symb;
MqlRates Rates[];
CNet StudyNet;
CBufferFloat *TempData;
CiRSI RSI;
CiCCI CCI;
CiATR ATR;
CiMACD MACD;
CTrade Trade;
//---
float dError;
datetime dtStudied;
bool bEventStudy;
MqlDateTime sTime;
//---
CBufferFloat State;
datetime lastBar;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(!Symb.Name(_Symbol))
return INIT_FAILED;
Symb.Refresh();
//---
if(!RSI.Create(Symb.Name(), TimeFrame, RSIPeriod, RSIPrice))
return INIT_FAILED;
//---
if(!CCI.Create(Symb.Name(), TimeFrame, CCIPeriod, CCIPrice))
return INIT_FAILED;
//---
if(!ATR.Create(Symb.Name(), TimeFrame, ATRPeriod))
return INIT_FAILED;
//---
if(!MACD.Create(Symb.Name(), TimeFrame, FastPeriod, SlowPeriod, SignalPeriod, MACDPrice))
return INIT_FAILED;
//---
float temp1, temp2;
if(!StudyNet.Load(FileName + ".nnw", dError, temp1, temp2, dtStudied, true))
return INIT_FAILED;
//---
if(!StudyNet.GetLayerOutput(0, TempData))
return INIT_FAILED;
HistoryBars = TempData.Total() / NeuronsToBar;
StudyNet.getResults(TempData);
if(TempData.Total() != Actions)
return INIT_PARAMETERS_INCORRECT;
//---
if(!RSI.BufferResize(HistoryBars + 2) || !CCI.BufferResize(HistoryBars + 2) ||
!ATR.BufferResize(HistoryBars + 2) || !MACD.BufferResize(HistoryBars + 2))
return INIT_FAILED;
//---
lastBar = 0;
//---
if(!Trade.SetTypeFillingBySymbol(Symb.Name()))
return INIT_FAILED;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(!!TempData)
delete TempData;
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{