last ...
This commit is contained in:
@@ -0,0 +1,647 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XCond2 MQL5 Script
|
||||
// -------------------------------------------------
|
||||
// Name: XCAEA
|
||||
// Description: an Exper Advisor which used Panels
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCAEA Cond2 Script"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
// Classes ...
|
||||
#include "../../Classes/x-saherelm.x-poi.class.mq5"
|
||||
|
||||
//
|
||||
// Libraries ...
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
|
||||
//
|
||||
// Helpers ...
|
||||
#include "../Helpers/xcaea.helper.mq5";
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Holds Drawn Objects ...
|
||||
CArrayObj mObjects;
|
||||
|
||||
//
|
||||
// Required Objects ...
|
||||
int mLoopback = 10;
|
||||
XCAEAInputs mInputs;
|
||||
XBarTracker mBarTracker;
|
||||
XCAEAConditions mConditions;
|
||||
XCXCAEAHelper *helper = NULL;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Script ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Initialize Helper ...
|
||||
bool isInited = InitHelper();
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Script ...
|
||||
*
|
||||
* @param reason: Argument 1
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
mInputs.Clean();
|
||||
mConditions.Clean();
|
||||
|
||||
//
|
||||
ZeroMemory(helper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Tick Event ...
|
||||
*/
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Run on New Bar ...
|
||||
bool isNewBar = mBarTracker.IsNewBar();
|
||||
if (!isNewBar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Bar Index ...
|
||||
int barIndex = 0;
|
||||
|
||||
//
|
||||
// Retrieve Conditions ...
|
||||
has = helper.GetConditions(
|
||||
mConditions,
|
||||
barIndex,
|
||||
mLoopback //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handling Logic ...
|
||||
HandleLogic();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Initialize Helper ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitHelper()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mInputs.Default();
|
||||
|
||||
//
|
||||
// Configure Inputs ...
|
||||
|
||||
//
|
||||
// Oscilators ...
|
||||
mInputs.showAC = false;
|
||||
mInputs.showAD = false;
|
||||
mInputs.showADX = false;
|
||||
mInputs.showATR = false;
|
||||
mInputs.showCCI = false;
|
||||
mInputs.showRSI = false;
|
||||
mInputs.showMFI = false;
|
||||
mInputs.showRVI = false;
|
||||
mInputs.showMACD = false;
|
||||
mInputs.showMomentum = false;
|
||||
mInputs.showStochastic = false;
|
||||
|
||||
//
|
||||
// XCT ...
|
||||
mInputs.ctInputs.showCandleTime = true;
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
mInputs.ccInputs.showCandles = true;
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
mInputs.x3maInputs.showFast = false;
|
||||
mInputs.x3maInputs.showSlow = false;
|
||||
mInputs.x3maInputs.showMedium = false;
|
||||
|
||||
//
|
||||
// XOSC ...
|
||||
// mInputs.oscsInputs;
|
||||
|
||||
//
|
||||
// XCA ...
|
||||
mInputs.caInputs.showKI = false;
|
||||
mInputs.caInputs.showSar = false;
|
||||
mInputs.caInputs.showTKI = false;
|
||||
mInputs.caInputs.showMAH = true;
|
||||
mInputs.caInputs.showMAL = true;
|
||||
mInputs.caInputs.showMAC = true;
|
||||
mInputs.caInputs.showVidya = false;
|
||||
mInputs.caInputs.showTrend = false;
|
||||
mInputs.caInputs.showSwings = false;
|
||||
mInputs.caInputs.showLongCycle = false;
|
||||
mInputs.caInputs.showHindCycle = false;
|
||||
mInputs.caInputs.showShortCycle = false;
|
||||
mInputs.caInputs.showFiboLevel1 = true;
|
||||
mInputs.caInputs.showFiboLevel2 = false;
|
||||
mInputs.caInputs.showFiboLevel3 = true;
|
||||
mInputs.caInputs.showMediumCycle = false;
|
||||
mInputs.caInputs.showPeaksAndVales = false;
|
||||
mInputs.caInputs.showPeakAndValeGolden = false;
|
||||
mInputs.caInputs.showSupportAndResistance = true;
|
||||
|
||||
//
|
||||
// Initialize Helper ...
|
||||
helper = new XCXCAEAHelper();
|
||||
result = helper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Bar Tracker ...
|
||||
result = mBarTracker.Init(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Logic of Script ...
|
||||
*/
|
||||
void HandleLogic()
|
||||
{
|
||||
//
|
||||
// Defining Requirements ...
|
||||
|
||||
//
|
||||
int zIDX = 0;
|
||||
int cIDX = zIDX + 1;
|
||||
int pIDX = cIDX + 1;
|
||||
int p2IDX = pIDX + 1;
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Reading Required Values ...
|
||||
|
||||
//
|
||||
// PEAK ...
|
||||
double zPeak = mConditions.peakBuffer[zIDX];
|
||||
double cPeak = mConditions.peakBuffer[cIDX];
|
||||
double pPeak = mConditions.peakBuffer[pIDX];
|
||||
double p2Peak = mConditions.peakBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// VALE ...
|
||||
double zVale = mConditions.valeBuffer[zIDX];
|
||||
double cVale = mConditions.valeBuffer[cIDX];
|
||||
double pVale = mConditions.valeBuffer[pIDX];
|
||||
double p2Vale = mConditions.valeBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
double zSar = mConditions.sarBuffer[zIDX];
|
||||
double cSar = mConditions.sarBuffer[cIDX];
|
||||
double pSar = mConditions.sarBuffer[pIDX];
|
||||
double p2Sar = mConditions.sarBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// KI ...
|
||||
double zKI = mConditions.kiBuffer[zIDX];
|
||||
double cKI = mConditions.kiBuffer[cIDX];
|
||||
double pKI = mConditions.kiBuffer[pIDX];
|
||||
double p2KI = mConditions.kiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// KI State ...
|
||||
double zKIState = mConditions.kiStateBuffer[zIDX];
|
||||
double cKIState = mConditions.kiStateBuffer[cIDX];
|
||||
double pKIState = mConditions.kiStateBuffer[pIDX];
|
||||
double p2KIState = mConditions.kiStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TKI ...
|
||||
double zTKI = mConditions.tkiBuffer[zIDX];
|
||||
double cTKI = mConditions.tkiBuffer[cIDX];
|
||||
double pTKI = mConditions.tkiBuffer[pIDX];
|
||||
double p2TKI = mConditions.tkiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TKI State ...
|
||||
double zTKIState = mConditions.tkiStateBuffer[zIDX];
|
||||
double cTKIState = mConditions.tkiStateBuffer[cIDX];
|
||||
double pTKIState = mConditions.tkiStateBuffer[pIDX];
|
||||
double p2TKIState = mConditions.tkiStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MAH ...
|
||||
double zMAH = mConditions.mahBuffer[zIDX];
|
||||
double cMAH = mConditions.mahBuffer[cIDX];
|
||||
double pMAH = mConditions.mahBuffer[pIDX];
|
||||
double p2MAH = mConditions.mahBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MAL ...
|
||||
double zMAL = mConditions.malBuffer[zIDX];
|
||||
double cMAL = mConditions.malBuffer[cIDX];
|
||||
double pMAL = mConditions.malBuffer[pIDX];
|
||||
double p2MAL = mConditions.malBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MAC ...
|
||||
double zMAC = mConditions.macBuffer[zIDX];
|
||||
double cMAC = mConditions.macBuffer[cIDX];
|
||||
double pMAC = mConditions.macBuffer[pIDX];
|
||||
double p2MAC = mConditions.macBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
double zTrend = mConditions.trendBuffer[zIDX];
|
||||
double cTrend = mConditions.trendBuffer[cIDX];
|
||||
double pTrend = mConditions.trendBuffer[pIDX];
|
||||
double p2Trend = mConditions.trendBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// TREND State ...
|
||||
double zTrendState = mConditions.trendStateBuffer[zIDX];
|
||||
double cTrendState = mConditions.trendStateBuffer[cIDX];
|
||||
double pTrendState = mConditions.trendStateBuffer[pIDX];
|
||||
double p2TrendState = mConditions.trendStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// RESISTANCE ...
|
||||
double zResistance = mConditions.resistanceBuffer[zIDX];
|
||||
double cResistance = mConditions.resistanceBuffer[cIDX];
|
||||
double pResistance = mConditions.resistanceBuffer[pIDX];
|
||||
double p2Resistance = mConditions.resistanceBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
double zSupport = mConditions.supportBuffer[zIDX];
|
||||
double cSupport = mConditions.supportBuffer[cIDX];
|
||||
double pSupport = mConditions.supportBuffer[pIDX];
|
||||
double p2Support = mConditions.supportBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// VIDYA ...
|
||||
double zVIDYA = mConditions.vidyaBuffer[zIDX];
|
||||
double cVIDYA = mConditions.vidyaBuffer[cIDX];
|
||||
double pVIDYA = mConditions.vidyaBuffer[pIDX];
|
||||
double p2VIDYA = mConditions.vidyaBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// VIDYA State ...
|
||||
double zVIDYAState = mConditions.vidyaStateBuffer[zIDX];
|
||||
double cVIDYAState = mConditions.vidyaStateBuffer[cIDX];
|
||||
double pVIDYAState = mConditions.vidyaStateBuffer[pIDX];
|
||||
double p2VIDYAState = mConditions.vidyaStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SWING Low ...
|
||||
double zSwingLow = mConditions.swingLowBuffer[zIDX];
|
||||
double cSwingLow = mConditions.swingLowBuffer[cIDX];
|
||||
double pSwingLow = mConditions.swingLowBuffer[pIDX];
|
||||
double p2SwingLow = mConditions.swingLowBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SWING High ...
|
||||
double zSwingHigh = mConditions.swingHighBuffer[zIDX];
|
||||
double cSwingHigh = mConditions.swingHighBuffer[cIDX];
|
||||
double pSwingHigh = mConditions.swingHighBuffer[pIDX];
|
||||
double p2SwingHigh = mConditions.swingHighBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// FIBO Level 1 ...
|
||||
double zFiboLevel1 = mConditions.fiboLevel1Buffer[zIDX];
|
||||
double cFiboLevel1 = mConditions.fiboLevel1Buffer[cIDX];
|
||||
double pFiboLevel1 = mConditions.fiboLevel1Buffer[pIDX];
|
||||
double p2FiboLevel1 = mConditions.fiboLevel1Buffer[p2IDX];
|
||||
|
||||
//
|
||||
// FIBO Level 2 ...
|
||||
double zFiboLevel2 = mConditions.fiboLevel2Buffer[zIDX];
|
||||
double cFiboLevel2 = mConditions.fiboLevel2Buffer[cIDX];
|
||||
double pFiboLevel2 = mConditions.fiboLevel2Buffer[pIDX];
|
||||
double p2FiboLevel2 = mConditions.fiboLevel2Buffer[p2IDX];
|
||||
|
||||
//
|
||||
// FIBO Level 3 ...
|
||||
double zFiboLevel3 = mConditions.fiboLevel3Buffer[zIDX];
|
||||
double cFiboLevel3 = mConditions.fiboLevel3Buffer[cIDX];
|
||||
double pFiboLevel3 = mConditions.fiboLevel3Buffer[pIDX];
|
||||
double p2FiboLevel3 = mConditions.fiboLevel3Buffer[p2IDX];
|
||||
|
||||
//
|
||||
// X3MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
double z3MAFast = mConditions.fastBuffer[zIDX];
|
||||
double c3MAFast = mConditions.fastBuffer[cIDX];
|
||||
double p3MAFast = mConditions.fastBuffer[pIDX];
|
||||
double p23MAFast = mConditions.fastBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double z3MAFastState = mConditions.fastStateBuffer[zIDX];
|
||||
double c3MAFastState = mConditions.fastStateBuffer[cIDX];
|
||||
double p3MAFastState = mConditions.fastStateBuffer[pIDX];
|
||||
double p23MAFastState = mConditions.fastStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// MEDIUM ...
|
||||
|
||||
//
|
||||
double z3MAMedium = mConditions.mediumBuffer[zIDX];
|
||||
double c3MAMedium = mConditions.mediumBuffer[cIDX];
|
||||
double p3MAMedium = mConditions.mediumBuffer[pIDX];
|
||||
double p23MAMedium = mConditions.mediumBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double z3MAMediumState = mConditions.mediumStateBuffer[zIDX];
|
||||
double c3MAMediumState = mConditions.mediumStateBuffer[cIDX];
|
||||
double p3MAMediumState = mConditions.mediumStateBuffer[pIDX];
|
||||
double p23MAMediumState = mConditions.mediumStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
double z3MASlow = mConditions.slowBuffer[zIDX];
|
||||
double c3MASlow = mConditions.slowBuffer[cIDX];
|
||||
double p3MASlow = mConditions.slowBuffer[pIDX];
|
||||
double p23MASlow = mConditions.slowBuffer[p2IDX];
|
||||
|
||||
//
|
||||
double z3MASlowState = mConditions.slowStateBuffer[zIDX];
|
||||
double c3MASlowState = mConditions.slowStateBuffer[cIDX];
|
||||
double p3MASlowState = mConditions.slowStateBuffer[pIDX];
|
||||
double p23MASlowState = mConditions.slowStateBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
double zRSI = mConditions.rsiBuffer[zIDX];
|
||||
double cRSI = mConditions.rsiBuffer[cIDX];
|
||||
double pRSI = mConditions.rsiBuffer[pIDX];
|
||||
double p2RSI = mConditions.rsiBuffer[p2IDX];
|
||||
|
||||
//
|
||||
// Reading Bars ...
|
||||
|
||||
//
|
||||
XOHCL zBar;
|
||||
XOHCL cBar;
|
||||
XOHCL pBar;
|
||||
XOHCL p2Bar;
|
||||
XOHCL p3Bar;
|
||||
XOHCL p4Bar;
|
||||
has = zBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
zIDX //
|
||||
);
|
||||
has =
|
||||
has &&
|
||||
zBar.GetPreviousBar(cBar);
|
||||
has =
|
||||
has &&
|
||||
cBar.GetPreviousBar(pBar);
|
||||
has =
|
||||
has &&
|
||||
pBar.GetPreviousBar(p2Bar);
|
||||
has =
|
||||
has &&
|
||||
p2Bar.GetPreviousBar(p3Bar);
|
||||
has =
|
||||
has &&
|
||||
p3Bar.GetPreviousBar(p4Bar);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
pBar.Clean();
|
||||
p2Bar.Clean();
|
||||
p3Bar.Clean();
|
||||
p4Bar.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Bars Related Data ...
|
||||
|
||||
//
|
||||
// Score ...
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
mConditions.GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
bool isScoreBullish =
|
||||
bullishScore > bearishScore;
|
||||
|
||||
//
|
||||
bool isScoreBearish =
|
||||
bearishScore > bullishScore;
|
||||
|
||||
//
|
||||
// Generating Conditions Summary ...
|
||||
string summary =
|
||||
mConditions
|
||||
.GenerateSummary();
|
||||
|
||||
//
|
||||
// Calculating Range Volumes ...
|
||||
|
||||
//
|
||||
double bullishVolume = 0;
|
||||
double bearishVolume = 0;
|
||||
int volumeRangeLoopback = 5;
|
||||
helper.barAnalyser.CalculateRangeVolume(
|
||||
cBar,
|
||||
bullishVolume,
|
||||
bearishVolume,
|
||||
volumeRangeLoopback //
|
||||
);
|
||||
|
||||
//
|
||||
double rangeVolume = bullishVolume = bearishVolume;
|
||||
double rangeVolumeAvg = rangeVolume / volumeRangeLoopback;
|
||||
|
||||
//
|
||||
// Preparing Complex Conditions ...
|
||||
|
||||
//
|
||||
bool isRSIBullish =
|
||||
cRSI > pRSI &&
|
||||
!mConditions.isRSIOB;
|
||||
|
||||
//
|
||||
bool isRSIBearish =
|
||||
cRSI < pRSI &&
|
||||
!mConditions.isRSIOS;
|
||||
|
||||
//
|
||||
bool isVolumeBullish = bullishVolume > bearishVolume;
|
||||
bool isVolumeBearish = bullishVolume < bearishVolume;
|
||||
bool isVolumeOverLast = cBar.volume > pBar.volume;
|
||||
bool isVolumeOverAvg = cBar.volume > rangeVolumeAvg;
|
||||
|
||||
//
|
||||
// Cond2 ...
|
||||
|
||||
//
|
||||
bool isCond2Bullish =
|
||||
//
|
||||
mConditions.isUnderMal &&
|
||||
mConditions.isValeIsPivot &&
|
||||
// mConditions.swingLowBuffer[cIDX] > mConditions.valeBuffer[cIDX] &&
|
||||
mConditions.swingLowBuffer[cIDX] < mConditions.fiboLevel3Buffer[cIDX]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond2Bearish =
|
||||
//
|
||||
false // &&
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool isCond2 = isCond2Bullish ||
|
||||
isCond2Bearish;
|
||||
if (isCond2)
|
||||
{
|
||||
//
|
||||
// Print("Cond2");
|
||||
// isCond2Bullish = false;
|
||||
// isCond2Bearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Results ...
|
||||
|
||||
//
|
||||
bool isBullish = isCond2Bullish;
|
||||
bool isBearish = isCond2Bearish;
|
||||
|
||||
//
|
||||
bool result = isBullish ||
|
||||
isBearish;
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
datetime time = zBar.time;
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION iDir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
// Handle Works ...
|
||||
if (isCond2)
|
||||
{
|
||||
//
|
||||
string name = "Cond2_" + ToString(iDir);
|
||||
|
||||
//
|
||||
color clr = isBullish
|
||||
? clrAqua
|
||||
: clrMagenta;
|
||||
|
||||
//
|
||||
CChartObjectHLine *iObj;
|
||||
iObj = new CChartObjectHLine();
|
||||
has = iObj.Create(
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
time //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Style Object ...
|
||||
iObj.Width(1);
|
||||
iObj.Color(clr);
|
||||
iObj.Style(STYLE_DOT);
|
||||
|
||||
//
|
||||
// Store Object ...
|
||||
mObjects.Add(iObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user