Отслеживать
1
0
Ответвление
У вас уже есть ответвление okWarrior_EA
0
ответвлён от animatedread/Warrior_EA
okWarrior_EA/references/MQL5/Experts/CT/Faza1.mq5

375 строки
27 КиБ
MQL5
ИсходныйПостоянная ссылкаОбычный видИстория

<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Faza1.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"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "Trajectory.mqh"
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Indicators\Oscilators.mqh>
//+------------------------------------------------------------------+
//| Input parameters |
//+------------------------------------------------------------------+
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;
input double MinProfit = 10;
input int MaxSteps = 48;
input int MinBars = 300;
//---
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
//---
input group "---- Optimization ----"
input int OptimizationAgents = 1;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
SState sState;
STrajectory Base;
STrajectory Buffer[];
STrajectory Frame[1];
STrajectory Loaded;
int StartBar = 0;
int CurrentBar = 0;
//---
CSymbolInfo Symb;
CTrade Trade;
//---
MqlRates Rates[];
CiRSI RSI;
CiCCI CCI;
CiATR ATR;
CiMACD MACD;
//---
vector<float> AgentResult;
double PrevBalance = 0;
double PrevEquity = 0;
//+------------------------------------------------------------------+
//| 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;
if(!RSI.BufferResize(NBarInPattern) || !CCI.BufferResize(NBarInPattern) ||
!ATR.BufferResize(NBarInPattern) || !MACD.BufferResize(NBarInPattern))
{
PrintFormat("%s -> %d", __FUNCTION__, __LINE__);
return INIT_FAILED;
}
//---
if(!Trade.SetTypeFillingBySymbol(Symb.Name()))
return INIT_FAILED;
//---
PrevBalance = AccountInfoDouble(ACCOUNT_BALANCE);
PrevEquity = AccountInfoDouble(ACCOUNT_EQUITY);
AgentResult = vector<float>::Zeros(NActions);
//---
int error_code;
if(Buffer.Size() > 0 || LoadTotalBase())
{
int tr = int(MathRand() / 32767.0 * Buffer.Size());
Loaded = Buffer[tr];
StartBar = MathMax(0,Loaded.Total - int(MathMax(Math::MathRandomNormal(0.5, 0.5, error_code), 0) * MaxSteps));
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(!IsNewBar())
return;
//---
CurrentBar++;
int bars = CopyRates(Symb.Name(), TimeFrame, iTime(Symb.Name(), TimeFrame, 1), NBarInPattern, Rates);
if(!ArraySetAsSeries(Rates, true))
return;
//---
RSI.Refresh();
CCI.Refresh();
ATR.Refresh();
MACD.Refresh();
Symb.Refresh();
Symb.RefreshRates();
//--- History data
float atr = 0;
for(int b = 0; b < (int)NBarInPattern; b++)
{
float open = (float)Rates[b].open;
float rsi = (float)RSI.Main(b);
float cci = (float)CCI.Main(b);
atr = (float)ATR.Main(b);
float macd = (float)MACD.Main(b);
float sign = (float)MACD.Signal(b);
if(rsi == EMPTY_VALUE || cci == EMPTY_VALUE || atr == EMPTY_VALUE || macd == EMPTY_VALUE || sign == EMPTY_VALUE)
continue;
//---
int shift = b * BarDescr;
sState.state[shift] = (float)(Rates[b].close - open);
sState.state[shift + 1] = (float)(Rates[b].high - open);
sState.state[shift + 2] = (float)(Rates[b].low - open);
sState.state[shift + 3] = (float)(Rates[b].tick_volume / 1000.0f);
sState.state[shift + 4] = rsi;
sState.state[shift + 5] = cci;
sState.state[shift + 6] = atr;
sState.state[shift + 7] = macd;
sState.state[shift + 8] = sign;
}
//--- Account description
sState.account[0] = (float)AccountInfoDouble(ACCOUNT_BALANCE);
sState.account[1] = (float)AccountInfoDouble(ACCOUNT_EQUITY);
//---
double buy_value = 0, sell_value = 0, buy_profit = 0, sell_profit = 0;
double position_discount = 0;
double multiplyer = 1.0 / (60.0 * 60.0 * 10.0);
int total = PositionsTotal();
datetime current = TimeCurrent();
for(int i = 0; i < total; i++)
{
if(PositionGetSymbol(i) != Symb.Name())
continue;
double profit = PositionGetDouble(POSITION_PROFIT);
switch((int)PositionGetInteger(POSITION_TYPE))
{
case POSITION_TYPE_BUY:
buy_value += PositionGetDouble(POSITION_VOLUME);
buy_profit += profit;
break;
case POSITION_TYPE_SELL:
sell_value += PositionGetDouble(POSITION_VOLUME);
sell_profit += profit;
break;
}
position_discount += profit - (current - PositionGetInteger(POSITION_TIME)) * multiplyer * MathAbs(profit);
}