Files
xMQL5/MQLTestWorkspace/BKPS/BKP/x121 old style indicators/Providers/Test/x121.test.provider.mq5
T

917 lines
17 KiB
Plaintext

////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XTestPRVD Signal Provider Library
// --------------------------------------------------------
// Name: XTestPRVD
// Description: XTestPRVD Signal provider ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Imports/Includes ...
//
//
// Include Common Library ...
#include "../../Libraries/x-saherelm.common.lib.mq5"
//
// Include Logger Library ...
#include "../../Libraries/x-saherelm.log.lib.mq5"
//
// Include Alert Library ...
#include "../../Libraries/x-saherelm.alert.lib.mq5"
//
// Include Draw Library ...
#include "../../Libraries/x-saherelm.draw.lib.mq5"
//
#include "../../Helpers/Test/x121.xpv.test.helper.mq5"
#include "../../Helpers/Test/x121.xmc.test.helper.mq5"
#include "../../Helpers/Test/x121.xmrb.test.helper.mq5"
#include "../../Helpers/Test/x121.xichi.test.helper.mq5"
#include "../../Helpers/Test/x121.xtrnd.test.helper.mq5"
#include "../../Helpers/Test/x121.xatrsl.test.helper.mq5"
//
// END Imports/Includes ...
//
//
// START Enum/Constant Definitions ...
//
//
// Model Market Sence ...
struct X121MarketCondition
{
//
// XPV ...
//
bool isPVNewPeak;
bool isPVSamePeak;
bool isPVPeakBreakedUp;
bool isPVPeakBreakedDown;
//
bool isPVNewVale;
bool isPVSameVale;
bool isPVValeBreakedUp;
bool isPVValeBreakedDown;
//
// SSL Channel ...
bool isSSLUpOverDown;
bool isSSLUpUnderDown;
bool isSSLUpCrossedOverDown;
bool isSSLUpCrossedUnderDown;
//
// XICHI ...
//
// TNKIJ ...
bool isIchiTenkanSenOverKijunSen;
bool isIchiTenkanSenUnderKijunSen;
bool isIchiTenkanSenCrossedOverKijunSen;
bool isIchiTenkanSenCrossedUnderKijunSen;
//
// KUMO ...
bool isIchiKumoBullish;
bool isIchiKumoBearish;
bool isIchiFutureKumoBullish;
bool isIchiFutureKumoBearish;
bool isIchiKumoSwitchedToBullish;
bool isIchiKumoSwitchedToBearish;
bool isIchiFutureKumoSwitchedToBullish;
bool isIchiFutureKumoSwitchedToBearish;
//
// TNKUMO ...
bool isIchiTenkanSenOverSenkouSpanA;
bool isIchiTenkanSenOverSenkouSpanB;
bool isIchiTenkanSenCrossedOverSenkouSpanA;
bool isIchiTenkanSenCrossedOverSenkouSpanB;
bool isIchiTenkanSenUnderSenkouSpanA;
bool isIchiTenkanSenUnderSenkouSpanB;
bool isIchiTenkanSenCrossedUnderSenkouSpanA;
bool isIchiTenkanSenCrossedUnderSenkouSpanB;
//
// KIJUMO ...
bool isIchiKijunSenOverSenkouSpanA;
bool isIchiKijunSenOverSenkouSpanB;
bool isIchiKijunSenCrossedOverSenkouSpanA;
bool isIchiKijunSenCrossedOverSenkouSpanB;
bool isIchiKijunSenUnderSenkouSpanA;
bool isIchiKijunSenUnderSenkouSpanB;
bool isIchiKijunSenCrossedUnderSenkouSpanA;
bool isIchiKijunSenCrossedUnderSenkouSpanB;
//
// XTRND ...
//
// CURRENT ...
bool isTrendBullish;
bool isTrendBearish;
bool isTrendConsolidation;
bool isTrendSwitchedToBullish;
bool isTrendSwitchedToBearish;
bool isTrendSwitchedToConsolidation;
//
// LEVEL 1 ...
bool isTrendL1Bullish;
bool isTrendL1Bearish;
bool isTrendL1Consolidation;
bool isTrendL1SwitchedToBullish;
bool isTrendL1SwitchedToBearish;
bool isTrendL1SwitchedToConsolidation;
//
// LEVEL 2 ...
bool isTrendL2Bullish;
bool isTrendL2Bearish;
bool isTrendL2Consolidation;
bool isTrendL2SwitchedToBullish;
bool isTrendL2SwitchedToBearish;
bool isTrendL2SwitchedToConsolidation;
//
// LEVEL 3 ...
bool isTrendL3Bullish;
bool isTrendL3Bearish;
bool isTrendL3Consolidation;
bool isTrendL3SwitchedToBullish;
bool isTrendL3SwitchedToBearish;
bool isTrendL3SwitchedToConsolidation;
//
// XMRB ...
//
// MRIBBON ...
bool isRibbonBullish;
bool isRibbonBearish;
bool isRibbonSwitchedToBullish;
bool isRibbonSwitchedToBearish;
//
// RIBOON 1 ...
bool isRibbon1Bullish;
bool isRibbon1Bearish;
bool isRibbon1SwitchedToBullish;
bool isRibbon1SwitchedToBearish;
//
// RIBOON 2 ...
bool isRibbon2Bullish;
bool isRibbon2Bearish;
bool isRibbon2SwitchedToBullish;
bool isRibbon2SwitchedToBearish;
//
// RIBOON 3 ...
bool isRibbon3Bullish;
bool isRibbon3Bearish;
bool isRibbon3SwitchedToBullish;
bool isRibbon3SwitchedToBearish;
//
// RIBOON 4 ...
bool isRibbon4Bullish;
bool isRibbon4Bearish;
bool isRibbon4SwitchedToBullish;
bool isRibbon4SwitchedToBearish;
//
// RIBOON 5 ...
bool isRibbon5Bullish;
bool isRibbon5Bearish;
bool isRibbon5SwitchedToBullish;
bool isRibbon5SwitchedToBearish;
//
// XMC ...
bool isMCFastOverSlow;
bool isMCFastUnderSlow;
bool isMCFastCrossedOverSlow;
bool isMCFastCrossedUnderSlow;
bool isMCFastOverVerifier;
bool isMCFastUnderVerifier;
bool isMCFastCrossedOverVerifier;
bool isMCFastCrossedUnderVerifier;
bool isMCSlowOverVerifier;
bool isMCSlowUnderVerifier;
bool isMCSlowCrossedOverVerifier;
bool isMCSlowCrossedUnderVerifier;
//
// XAMA ...
bool isXAMABullish;
bool isXAMABearish;
bool isXAMANeutural;
bool isXAMAChangedToBullish;
bool isXAMAChangedToBearish;
bool isXAMAChangedToNeutural;
//
// XTM ...
bool isXTMBullish;
bool isXTMBearish;
bool isXTMNeutural;
bool isXTMChangedToBullish;
bool isXTMChangedToBearish;
bool isXTMChangedToNeutural;
}
//
// END Enum/Constant Definitions ...
//
//
// START Variables ...
//
//
int mcclearHandler = INVALID_HANDLE;
//
// END Variables ...
//
//
// START Signal Provider Functions ...
//
//
bool XTestPRVDOnInit()
{
//
bool result = false;
//
result = XATRSLHLPOnInit();
if (!result)
{
return result;
}
//
result = XICHIHLPOnInit();
if (!result)
{
return result;
}
//
result = XMCHLPOnInit();
if (!result)
{
return result;
}
//
result = XMRBHLPOnInit();
if (!result)
{
return result;
}
//
result = XPVHLPOnInit();
if (!result)
{
return result;
}
//
result = XTRNDHLPOnInit();
if (!result)
{
return result;
}
//
// Initial CCLear Handler ...
mcclearHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xcclear",
//
// Inputs ...
//
// CHARTSTYLE ...
"",
//
// Up Color ...
clrLime,
//
// Down Color ...
clrRed,
//
// Line mode and Doji candlestick Color ...
clrLime,
//
// Bullish Color ...
clrRed,
//
// Bearish Color ...
clrLime,
//
// Volumes Color ...
clrGreen,
//
// PRESENTATION ...
"",
true
//
);
result = mcclearHandler != INVALID_HANDLE;
//
return result;
}
//
void XTestPRVDOnDeInit()
{
//
XATRSLHLPOnDeInit();
XICHIHLPOnDeInit();
XMCHLPOnDeInit();
XMRBHLPOnDeInit();
XPVHLPOnDeInit();
XTRNDHLPOnDeInit();
}
//
void XTestPRVDOnTick()
{
XATRSLHLPReadBuffers();
XICHIHLPReadBuffers();
XMCHLPReadBuffers();
XMRBHLPReadBuffers();
XPVHLPReadBuffers();
XTRNDHLPReadBuffers();
}
//
bool XTestPRVDProcessSignals(XSignal &result)
{
//
bool mResult = false;
//
// BUY ...
//
Clean(result);
bool hasLongSignal = XTestPRVDHasLongSignal(result);
if (hasLongSignal)
{
//
mResult = true;
return mResult;
}
//
// SELL ...
//
Clean(result);
bool hasShortignal = XTestPRVDHasShortSignal(result);
if (hasShortignal)
{
//
mResult = true;
return mResult;
}
//
return mResult;
}
//
bool XTestPRVDHasLongSignal(XSignal &result)
{
//
bool mResult = false;
return mResult;
//
XOHCLSupRes supRes = XPVHLPFindCandleSupprtAndResistance(1, 6);
bool hasSupport = ArraySize(supRes.sup) > 0;
bool hasResistance = ArraySize(supRes.res) > 0;
//
double r2r = 1.2;
double riskAmount = 0.005;
double entry = GetEntry(
_Symbol,
POSITION_TYPE_BUY);
double sl = entry -
(hasSupport
? (supRes.sup[ArrayMaximum(supRes.sup)] - supRes.sup[ArrayMinimum(supRes.sup)])
: hasResistance
? (supRes.res[ArrayMaximum(supRes.res)] - supRes.res[ArrayMinimum(supRes.res)])
: PointToPrice(
_Symbol,
10))
//
;
//
bool isXTestHasSignal = XTestPRVDHasLongCondition();
if (isXTestHasSignal)
{
//
Add(
"XTest",
result.providers);
//
result.r2r = 1.5;
//
result.sl = atrslDownBuffer[1];
}
//
bool isXTRNDHasSignal = XTRNDHasLongCondition();
if (isXTRNDHasSignal)
{
//
Add(
"XTRND",
result.providers);
}
//
bool isXICHIHasSignal = XICHIHasLongCondition();
if (isXICHIHasSignal)
{
//
Add(
"XICHI",
result.providers);
}
//
mResult =
//
isXTRNDHasSignal
//
||
//
isXICHIHasSignal
//
;
//
if (mResult)
{
//
result.sl = sl;
result.r2r = r2r;
result.entry = entry;
result.symbol = _Symbol;
result.period = _Period;
result.riskAmount = riskAmount;
result.type = POSITION_TYPE_BUY;
result.supportAndResistance = supRes;
}
//
return mResult;
}
//
bool XTestPRVDHasShortSignal(XSignal &result)
{
//
bool mResult = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
XOHCLSupRes supRes = XPVHLPFindCandleSupprtAndResistance(1, 6);
bool hasSupport = ArraySize(supRes.sup) > 0;
bool hasResistance = ArraySize(supRes.res) > 0;
//
double r2r = 1.2;
double riskAmount = 0.005;
double entry = GetEntry(
_Symbol,
POSITION_TYPE_SELL);
double sl = entry + (supRes.res[ArrayMaximum(supRes.res)] - supRes.res[ArrayMinimum(supRes.res)]);
//
bool isXTRNDHasSignal = XTRNDHasShortCondition();
if (isXTRNDHasSignal)
{
//
Add(
"XTRND",
result.providers);
}
//
bool isICHIHasSignal = XICHIHasShortCondition();
if (isICHIHasSignal)
{
//
Add(
"XICHI",
result.providers);
}
//
mResult =
//
isXTRNDHasSignal
//
// ||
// //
// TODO:
// isICHIHasSignal
//
;
//
if (mResult)
{
//
result.sl = sl;
result.r2r = r2r;
result.entry = entry;
result.symbol = _Symbol;
result.period = _Period;
result.riskAmount = riskAmount;
result.type = POSITION_TYPE_SELL;
result.mode = X_ORDER_MODE_MARKET;
result.supportAndResistance = supRes;
//
if (!hasSupport)
{
//
// When there is no any Provided Support for a Singal ...
// Place Pending Order instead of Market Order and use
// PV's LL Buffers as Supprt area ...
result.mode = X_ORDER_MODE_STOP;
double supportArea = XPVHLPGetMaxLL(1) - GetCandleShadow(c1);
result.entry = supportArea;
}
}
//
return mResult;
}
//
// TODO: Implement it ...
bool XTestPRVDForceCloseAllShorts()
{
//
bool result = false;
// //
// XOHCL c1 = GetCandle(
// _Symbol,
// _Period,
// 1);
// //
// result =
// //
// c1.low < ichiKijunSenBuffer[1] &&
// c1.high > ichiKijunSenBuffer[1]
// //
// ;
//
return result;
}
//
bool XTestPRVDHasLongCondition()
{
//
bool result = false;
//
return result;
}
//
bool XTestPRVDHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
return result;
}
//
// XTRND ..
//
bool XTRNDForceCloseAllLongs()
{
//
bool result = false;
//
return result;
}
//
bool XTRNDForceCloseAllShorts()
{
//
bool result = false;
//
return result;
}
//
bool XTRNDHasLongCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
XIchiInfo ichi1 = XICHIHLPGetInfo(1);
//
bool isTrendSwitchedToBullish =
//
(
//
XTRNDHLPIsL3TrendSwitchedBullish(1) &&
XTRNDHLPIsTrendBullish(1) &&
XTRNDHLPIsL1TrendBullish(1) &&
XTRNDHLPIsL2TrendBullish(1)
//
)
//
||
//
(
//
XTRNDHLPIsL2TrendSwitchedBullish(1) &&
XTRNDHLPIsTrendBullish(1) &&
XTRNDHLPIsL1TrendBullish(1) &&
XTRNDHLPIsL3TrendBullish(1)
//
)
//
||
//
(
//
XTRNDHLPIsL1TrendSwitchedBullish(1) &&
XTRNDHLPIsTrendBullish(1) &&
XTRNDHLPIsL2TrendBullish(1) &&
XTRNDHLPIsL3TrendBullish(1)
//
)
//
;
//
bool signal1 =
//
isTrendSwitchedToBullish
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
bool XTRNDHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
//
bool isTrendSwitchedToBearish =
//
(
//
XTRNDHLPIsL3TrendSwitchedBearish(1) &&
XTRNDHLPIsTrendBearish(1) &&
XTRNDHLPIsL1TrendBearish(1) &&
XTRNDHLPIsL2TrendBearish(1)
//
)
//
||
//
(
//
XTRNDHLPIsL2TrendSwitchedBearish(1) &&
XTRNDHLPIsTrendBearish(1) &&
XTRNDHLPIsL1TrendBearish(1) &&
XTRNDHLPIsL3TrendBearish(1) &&
XTRNDHLPIsTrendBearish(2) &&
XTRNDHLPIsL1TrendBearish(2) &&
XTRNDHLPIsL3TrendBearish(2)
//
)
//
||
//
(
//
XTRNDHLPIsL1TrendSwitchedBearish(1) &&
XTRNDHLPIsTrendBearish(1) &&
XTRNDHLPIsL2TrendBearish(1) &&
XTRNDHLPIsL3TrendBearish(1) &&
XTRNDHLPIsTrendBearish(2) &&
XTRNDHLPIsL2TrendBearish(2) &&
XTRNDHLPIsL3TrendBearish(2) &&
XTRNDHLPIsTrendBearish(3) &&
XTRNDHLPIsL2TrendBearish(3) &&
XTRNDHLPIsL3TrendBearish(3)
//
)
//
;
//
bool signal1 =
//
isTrendSwitchedToBearish
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
// XICHI ...
//
bool XICHIForceCloseAllShorts()
{
//
bool result = false;
//
return result;
}
//
bool XICHIForceCloseAllLongs()
{
//
bool result = false;
//
return result;
}
//
bool XICHIHasLongCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
XIchiInfo info1 = XICHIHLPGetInfo(1);
//
bool isKumoSwitchedToBullish =
//
XICHIHLPIsKumoSwitchedToBullish(1)
//
;
//
bool signal1 =
//
isKumoSwitchedToBullish &&
c1.low > info1.tenkanSen &&
info1.tenkanSen > info1.kijunSen &&
info1.kijunSen > MathMax(info1.senkouSpanA, info1.senkouSpanB)
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
bool XICHIHasShortCondition()
{
//
bool result = false;
//
XOHCL c1 = GetCandle(
_Symbol,
_Period,
1);
XIchiInfo info1 = XICHIHLPGetInfo(1);
//
bool isKumoSwitchedToBearish =
//
XICHIHLPIsKumoSwitchedToBearish(1)
//
;
//
bool signal1 =
//
isKumoSwitchedToBearish &&
c1.high < info1.tenkanSen &&
info1.tenkanSen < info1.kijunSen &&
info1.kijunSen < MathMin(info1.senkouSpanA, info1.senkouSpanB)
//
;
//
result =
//
signal1
//
;
//
return result;
}
//
// END Signal Provider Functions ...
//