1941 lines
38 KiB
Plaintext
1941 lines
38 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
|
|
// -------------------------------------------------
|
|
// Name: XSAMPLE
|
|
// Description: an Exper Advisor which used RSI and MA
|
|
// to Analyse Market ...
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////x
|
|
//
|
|
// Global Properties ...
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://saherelm.ir"
|
|
#property version "1.00"
|
|
#property description "SaherElm XSAMPLE"
|
|
#property strict
|
|
|
|
//
|
|
#define ShortName "XSAMPLE"
|
|
|
|
//
|
|
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
|
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
|
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
|
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
#include "../Classes/x-saherelm.xalert.class.mq5"
|
|
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
|
|
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
input group "Market";
|
|
|
|
//
|
|
input group "Short";
|
|
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES scPeriod = NULL; // Period
|
|
|
|
//
|
|
input group "Medium";
|
|
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES mcPeriod = NULL; // Period
|
|
|
|
//
|
|
input group "Long";
|
|
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES lcPeriod = NULL; // Period
|
|
|
|
//
|
|
input group "Hind";
|
|
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // Method
|
|
input ENUM_TIMEFRAMES hcPeriod = NULL; // Period
|
|
|
|
//
|
|
long xSampleEAMagicNumber = 78692110; // Magic Number
|
|
int xSampleEASlippage = 10; // Slippgae
|
|
|
|
//
|
|
double xSampleEAVolume = 0.01;
|
|
|
|
//
|
|
// Vars ...
|
|
string xSampleEASymbol;
|
|
ENUM_TIMEFRAMES xSampleEAPeriod;
|
|
|
|
//
|
|
int maxBuys = 1;
|
|
int maxSells = 1;
|
|
int buyCount = 0;
|
|
int sellCount = 0;
|
|
|
|
//
|
|
double _tp = 0;
|
|
double _sl = 0;
|
|
double _entry = 0;
|
|
ENUM_POSITION_TYPE _type = NULL;
|
|
|
|
//
|
|
MqlTick xSampleEATick;
|
|
|
|
//
|
|
XBarTracker xSamplEABarTracker;
|
|
|
|
//
|
|
// Cycles ...
|
|
|
|
//
|
|
double bullishBuffer[];
|
|
double bearishBuffer[];
|
|
double nBullishBuffer[];
|
|
double nBearishBuffer[];
|
|
|
|
//
|
|
double lastVale = 0;
|
|
double lastPeak = 0;
|
|
double lastSupport = 0;
|
|
double lastResistance = 0;
|
|
|
|
//
|
|
double xBullishScore = 0;
|
|
double xBearishScore = 0;
|
|
|
|
//
|
|
double normalizeBullishScore = 0;
|
|
double normalizeBearishScore = 0;
|
|
|
|
//
|
|
int xLongVerifications = 0;
|
|
int xShortVerifications = 0;
|
|
bool isScoreBalanced = false;
|
|
|
|
//
|
|
int normalizationLength = 15;
|
|
|
|
//
|
|
datetime lastTradeOn = NULL;
|
|
|
|
//
|
|
// Indicators ...
|
|
XCCInputs ccInputs;
|
|
XCTInputs ctInputs;
|
|
|
|
//
|
|
XZGInputs zgInputs;
|
|
XPVInputs pvInputs;
|
|
XHKInputs hkInputs;
|
|
XMCInputs mcInputs;
|
|
XTDInputs tdInputs;
|
|
XMRBInputs mrbInputs;
|
|
XICHInputs ichInputs;
|
|
XCHEInputs cheInputs;
|
|
XSTRInputs strInputs;
|
|
XDONInputs donInputs;
|
|
XOSCInputs oscInputs;
|
|
|
|
//
|
|
X121MCycleInputs cMarketInputs; // Curent Market Inputs
|
|
X121MCycleInputs sMarketInputs; // Short Market Inputs
|
|
X121MCycleInputs mMarketInputs; // Medium Market Inputs
|
|
X121MCycleInputs lMarketInputs; // Long Market Inputs
|
|
X121MCycleInputs hMarketInputs; // Hind Market Inputs
|
|
|
|
//
|
|
XSCX121Market *cMarket;
|
|
XSCX121Market *sMarket;
|
|
XSCX121Market *mMarket;
|
|
XSCX121Market *lMarket;
|
|
XSCX121Market *hMarket;
|
|
|
|
//
|
|
X121MCycleConditions cConditions;
|
|
X121MCycleConditions sConditions;
|
|
X121MCycleConditions mConditions;
|
|
X121MCycleConditions lConditions;
|
|
X121MCycleConditions hConditions;
|
|
|
|
//
|
|
XSCTrade *mTrader;
|
|
XSCAlert *mAlert;
|
|
|
|
//
|
|
XPivotTracker mPivotTracker;
|
|
XSignal mSignals[];
|
|
|
|
//
|
|
// Event Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0)
|
|
{
|
|
xSampleEASymbol = _Symbol;
|
|
}
|
|
|
|
//
|
|
if (xSampleEAPeriod == NULL)
|
|
{
|
|
xSampleEAPeriod = _Period;
|
|
}
|
|
|
|
//
|
|
// Validate Inputs ...
|
|
if (!XSampleEAValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
if (!InitialTrader())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// Initial Cycles ...
|
|
if (!InitCycles())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
drawPrefix = ShortName;
|
|
|
|
//
|
|
// Init Succeed ...
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//
|
|
// DeInitialization ...
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//
|
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
// REASON_REMOVE 1 Program removed from a chart
|
|
// REASON_RECOMPILE 2 Program recompiled
|
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
// REASON_CHARTCLOSE 4 Chart closed
|
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
// REASON_TEMPLATE 7 Another chart template applied
|
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
// REASON_CLOSE 9 Terminal closed
|
|
|
|
//
|
|
// De Initialize XSampleEA Providers ...
|
|
|
|
//
|
|
delete mAlert;
|
|
delete mTrader;
|
|
|
|
//
|
|
delete cMarket;
|
|
delete sMarket;
|
|
delete mMarket;
|
|
delete lMarket;
|
|
delete hMarket;
|
|
}
|
|
|
|
//
|
|
// On Tick Handler ...
|
|
void OnTick()
|
|
{
|
|
//
|
|
if (!xSamplEABarTracker.IsNewBar())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Reading Tick ...
|
|
if (!GetTick(
|
|
xSampleEASymbol,
|
|
xSampleEATick //
|
|
))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
Analyze();
|
|
|
|
//
|
|
Manage();
|
|
}
|
|
|
|
//
|
|
// Custom Functions ...
|
|
|
|
//
|
|
// Validate Variables nd Inputs ...
|
|
bool XSampleEAValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
xSampleEASlippage > 0 &&
|
|
xSampleEAMagicNumber > 0 &&
|
|
IsValid(scMethod, scPeriod) &&
|
|
IsValid(mcMethod, mcPeriod) &&
|
|
IsValid(lcMethod, lcPeriod) &&
|
|
IsValid(hcMethod, hcPeriod)
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Do Market Analyziation ...
|
|
void Analyze()
|
|
{
|
|
//
|
|
GenerateMarketConditions();
|
|
|
|
//
|
|
xBullishScore = 0;
|
|
xBearishScore = 0;
|
|
CalculateScores(
|
|
xBullishScore,
|
|
xBearishScore //
|
|
);
|
|
|
|
//
|
|
normalizeBullishScore = 0;
|
|
normalizeBearishScore = 0;
|
|
CalculateNormalizedScores(
|
|
normalizeBullishScore,
|
|
normalizeBearishScore //
|
|
);
|
|
|
|
//
|
|
xLongVerifications = 0;
|
|
xShortVerifications = 0;
|
|
CalculateVerifications(
|
|
xLongVerifications,
|
|
xShortVerifications //
|
|
);
|
|
|
|
//
|
|
// Detecting Pivots ...
|
|
HandlePivotDetection();
|
|
|
|
//
|
|
// Check Conditions on Pivots ...
|
|
HandleCheckConditions();
|
|
|
|
//
|
|
// Execute Signals ...
|
|
HandleSignalExecution();
|
|
|
|
//
|
|
// SUMMARY ...
|
|
|
|
//
|
|
string strSuumarry =
|
|
"[XTEA]" + "\n" +
|
|
"---------------------" + "\n" +
|
|
ToString(cMarketInputs.cycle.cycle) + ": " + ToString(cMarket.GetPeriod()) + "\n" +
|
|
ToString(sMarketInputs.cycle.cycle) + ": " + ToString(sMarket.GetPeriod()) + "\n" +
|
|
ToString(mMarketInputs.cycle.cycle) + ": " + ToString(mMarket.GetPeriod()) + "\n" +
|
|
ToString(lMarketInputs.cycle.cycle) + ": " + ToString(lMarket.GetPeriod()) + "\n" +
|
|
ToString(hMarketInputs.cycle.cycle) + ": " + ToString(hMarket.GetPeriod()) + "\n" +
|
|
"---------------------" + "\n" +
|
|
"Scores:" + "\n" +
|
|
"---------------------" + "\n" +
|
|
"Bullish: " + ToString(xBullishScore) + ", " + ToString(normalizeBullishScore) + ", " + ToString(xLongVerifications) + "\n" +
|
|
"Bearish: " + ToString(xBearishScore) + ", " + ToString(normalizeBearishScore) + ", " + ToString(xShortVerifications) + "\n" +
|
|
"";
|
|
|
|
//
|
|
Comment(strSuumarry);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
void Manage()
|
|
{
|
|
//
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(
|
|
positions //
|
|
);
|
|
if (!IsValidSize(positionsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
double profit = mTrader.Profit();
|
|
if (profit > 60)
|
|
{
|
|
//
|
|
string comment = "EQM Close ...";
|
|
|
|
//
|
|
int closed = mTrader.Close(
|
|
positions,
|
|
comment //
|
|
);
|
|
if (closed > 0)
|
|
{
|
|
//
|
|
string message = "EQM Close (" + ToString(closed) + ") Position in: " + ToString(profit);
|
|
|
|
//
|
|
mAlert.Alert(message);
|
|
|
|
//
|
|
int pivotsCount = mPivotTracker.Count();
|
|
if (pivotsCount > 0)
|
|
{
|
|
//
|
|
for (int i = 0; i < pivotsCount; i++)
|
|
{
|
|
//
|
|
double iPivot = mPivotTracker.Get(i);
|
|
|
|
//
|
|
RemovePivotDraw(iPivot);
|
|
|
|
//
|
|
lastPeak = 0;
|
|
lastVale = 0;
|
|
lastSupport = 0;
|
|
lastResistance = 0;
|
|
}
|
|
|
|
//
|
|
mPivotTracker.Clean();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Inbitial Classes ...
|
|
bool InitialTrader()
|
|
{
|
|
//
|
|
bool result = true;
|
|
|
|
//
|
|
mAlert = new XSCAlert();
|
|
mAlert.SetLogAlerts(true);
|
|
mAlert.SetPrefix(ShortName);
|
|
mAlert.SetEnableAlerts(true);
|
|
mAlert.SetPushAlerts(false);
|
|
mAlert.SetMailAlerts(false);
|
|
mAlert.SetTerminalAlerts(false);
|
|
|
|
//
|
|
mTrader = new XSCTrade(
|
|
xSampleEASlippage,
|
|
xSampleEAMagicNumber,
|
|
0,
|
|
0,
|
|
0,
|
|
0 //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initial Market Conditions ...
|
|
bool InitCycles()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Define an Input Object and Configure it ...
|
|
// then use same Input for Separate Markets ...
|
|
|
|
//
|
|
string symbol = _Symbol;
|
|
ENUM_TIMEFRAMES period = _Period;
|
|
|
|
//
|
|
// Set Inputs to Default ...
|
|
ccInputs.Default();
|
|
ctInputs.Default();
|
|
zgInputs.Default();
|
|
pvInputs.Default();
|
|
hkInputs.Default();
|
|
mcInputs.Default();
|
|
tdInputs.Default();
|
|
mrbInputs.Default();
|
|
ichInputs.Default();
|
|
cheInputs.Default();
|
|
strInputs.Default();
|
|
donInputs.Default();
|
|
oscInputs.Default();
|
|
|
|
//
|
|
cMarketInputs.Default();
|
|
sMarketInputs.Default();
|
|
mMarketInputs.Default();
|
|
lMarketInputs.Default();
|
|
hMarketInputs.Default();
|
|
|
|
//
|
|
// XHK ...
|
|
hkInputs.drawHikenAshi = false;
|
|
hkInputs.drawSmoothedHikenAshi = false;
|
|
|
|
//
|
|
// XMRB ...
|
|
mrbInputs.showFastMa = false;
|
|
mrbInputs.showSlowMa = false;
|
|
mrbInputs.showRibbon = false;
|
|
|
|
//
|
|
// XMC ...
|
|
mcInputs.showFastMa = false;
|
|
mcInputs.showSlowMa = false;
|
|
mcInputs.showVerifierMa = false;
|
|
|
|
//
|
|
// XICH ...
|
|
ichInputs.showKumo = false;
|
|
ichInputs.showKijunSen = false;
|
|
ichInputs.showTenkanSen = false;
|
|
ichInputs.showChikouSpan = false;
|
|
ichInputs.showSenkouSpanA = false;
|
|
ichInputs.showSenkouSpanB = false;
|
|
ichInputs.showKijunSenPlus = false;
|
|
ichInputs.showKijunSenNegative = false;
|
|
|
|
//
|
|
// XCHE ...
|
|
cheInputs.showLongExit1Line = false;
|
|
cheInputs.showShortExit1Line = false;
|
|
cheInputs.showLongExit2Line = false;
|
|
cheInputs.showShortExit2Line = false;
|
|
|
|
//
|
|
// XPV ...
|
|
pvInputs.showPeaksAndVales = true;
|
|
pvInputs.showLevels = false;
|
|
pvInputs.showConsolidations = false;
|
|
pvInputs.showFibo1Levels = false;
|
|
pvInputs.showFibo2Levels = false;
|
|
pvInputs.showFibo3Levels = false;
|
|
pvInputs.showFibo4Levels = false;
|
|
pvInputs.showFibo5Levels = false;
|
|
|
|
//
|
|
// XZG ...
|
|
zgInputs.showZigZag = false;
|
|
zgInputs.showPeaksAndVales = false;
|
|
|
|
//
|
|
// XDON ...
|
|
donInputs.showOpen = false;
|
|
donInputs.showHigh = false;
|
|
donInputs.showClose = false;
|
|
donInputs.showLow = false;
|
|
|
|
//
|
|
// XSTR ...
|
|
strInputs.showTrends = false;
|
|
strInputs.fillTrends = false;
|
|
|
|
//
|
|
// Current Cycle ...
|
|
|
|
//
|
|
ConfigureCurrentCycles();
|
|
|
|
//
|
|
cMarketInputs.cycle.symbol = symbol;
|
|
cMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
cMarketInputs.pvInputs = pvInputs;
|
|
cMarketInputs.zgInputs = zgInputs;
|
|
cMarketInputs.tdInputs = tdInputs;
|
|
cMarketInputs.mcInputs = mcInputs;
|
|
cMarketInputs.hkInputs = hkInputs;
|
|
cMarketInputs.mrbInputs = mrbInputs;
|
|
cMarketInputs.strInputs = strInputs;
|
|
cMarketInputs.oscInputs = oscInputs;
|
|
cMarketInputs.cheInputs = cheInputs;
|
|
cMarketInputs.ichInputs = ichInputs;
|
|
cMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = cMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_SHORT,
|
|
period,
|
|
X_PERIOD_MANUALLY,
|
|
"HOST",
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
cMarket = new XSCX121Market();
|
|
result = cMarket.Init(cMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Short Cycle ...
|
|
|
|
//
|
|
ConfigureShortCycles();
|
|
|
|
//
|
|
sMarketInputs.cycle.symbol = symbol;
|
|
sMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
sMarketInputs.pvInputs = pvInputs;
|
|
sMarketInputs.zgInputs = zgInputs;
|
|
sMarketInputs.tdInputs = tdInputs;
|
|
sMarketInputs.mcInputs = mcInputs;
|
|
sMarketInputs.hkInputs = hkInputs;
|
|
sMarketInputs.mrbInputs = mrbInputs;
|
|
sMarketInputs.strInputs = strInputs;
|
|
sMarketInputs.oscInputs = oscInputs;
|
|
sMarketInputs.cheInputs = cheInputs;
|
|
sMarketInputs.ichInputs = ichInputs;
|
|
sMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = sMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_SHORT,
|
|
scPeriod,
|
|
scMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
sMarket = new XSCX121Market();
|
|
result = sMarket.Init(sMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Medium Cycle ...
|
|
|
|
//
|
|
ConfigureMediumCycles();
|
|
|
|
//
|
|
mMarketInputs.cycle.symbol = symbol;
|
|
mMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
mMarketInputs.pvInputs = pvInputs;
|
|
mMarketInputs.zgInputs = zgInputs;
|
|
mMarketInputs.tdInputs = tdInputs;
|
|
mMarketInputs.mcInputs = mcInputs;
|
|
mMarketInputs.hkInputs = hkInputs;
|
|
mMarketInputs.mrbInputs = mrbInputs;
|
|
mMarketInputs.strInputs = strInputs;
|
|
mMarketInputs.oscInputs = oscInputs;
|
|
mMarketInputs.cheInputs = cheInputs;
|
|
mMarketInputs.ichInputs = ichInputs;
|
|
mMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = mMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_MEDIUM,
|
|
mcPeriod,
|
|
mcMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mMarket = new XSCX121Market();
|
|
result = mMarket.Init(mMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Long Cycle ...
|
|
|
|
//
|
|
ConfigureLongCycles();
|
|
|
|
//
|
|
lMarketInputs.cycle.symbol = symbol;
|
|
lMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
lMarketInputs.pvInputs = pvInputs;
|
|
lMarketInputs.zgInputs = zgInputs;
|
|
lMarketInputs.tdInputs = tdInputs;
|
|
lMarketInputs.mcInputs = mcInputs;
|
|
lMarketInputs.hkInputs = hkInputs;
|
|
lMarketInputs.mrbInputs = mrbInputs;
|
|
lMarketInputs.strInputs = strInputs;
|
|
lMarketInputs.oscInputs = oscInputs;
|
|
lMarketInputs.cheInputs = cheInputs;
|
|
lMarketInputs.ichInputs = ichInputs;
|
|
lMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = lMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_LONG,
|
|
lcPeriod,
|
|
lcMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
lMarket = new XSCX121Market();
|
|
result = lMarket.Init(lMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Hind Cycle ...
|
|
|
|
//
|
|
ConfigureHindCycles();
|
|
|
|
//
|
|
hMarketInputs.cycle.symbol = symbol;
|
|
hMarketInputs.cycle.period = period;
|
|
|
|
//
|
|
hMarketInputs.pvInputs = pvInputs;
|
|
hMarketInputs.zgInputs = zgInputs;
|
|
hMarketInputs.tdInputs = tdInputs;
|
|
hMarketInputs.mcInputs = mcInputs;
|
|
hMarketInputs.hkInputs = hkInputs;
|
|
hMarketInputs.mrbInputs = mrbInputs;
|
|
hMarketInputs.strInputs = strInputs;
|
|
hMarketInputs.oscInputs = oscInputs;
|
|
hMarketInputs.cheInputs = cheInputs;
|
|
hMarketInputs.ichInputs = ichInputs;
|
|
hMarketInputs.donInputs = donInputs;
|
|
|
|
//
|
|
result = hMarketInputs.Init(
|
|
symbol,
|
|
period,
|
|
X_MARKET_CYCLE_HIND,
|
|
hcPeriod,
|
|
hcMethod,
|
|
NULL,
|
|
false //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
hMarket = new XSCX121Market();
|
|
result = hMarket.Init(hMarketInputs);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Generate and Update Market Conditions ...
|
|
void GenerateMarketConditions()
|
|
{
|
|
//
|
|
cConditions.Clear();
|
|
cMarket.GetMarketConditions(cConditions);
|
|
|
|
//
|
|
sConditions.Clear();
|
|
sMarket.GetMarketConditions(sConditions);
|
|
|
|
//
|
|
mConditions.Clear();
|
|
mMarket.GetMarketConditions(mConditions);
|
|
|
|
//
|
|
lConditions.Clear();
|
|
lMarket.GetMarketConditions(lConditions);
|
|
|
|
//
|
|
hConditions.Clear();
|
|
hMarket.GetMarketConditions(hConditions);
|
|
}
|
|
|
|
//
|
|
// Calculate Markets Score Summary ...
|
|
void CalculateScores(
|
|
double &mBullishScore,
|
|
double &mBearishScore //
|
|
)
|
|
{
|
|
//
|
|
// Current Market ...
|
|
|
|
//
|
|
double cBullScore = 0;
|
|
double cBearScore = 0;
|
|
double cScoreMultiplier = 1;
|
|
|
|
//
|
|
cConditions.GenerateScore(
|
|
cBullScore,
|
|
cBearScore,
|
|
cScoreMultiplier //
|
|
);
|
|
|
|
//
|
|
// Short Market ...
|
|
|
|
//
|
|
double sBullScore = 0;
|
|
double sBearScore = 0;
|
|
double sScoreMultiplier = 1.25;
|
|
|
|
//
|
|
sConditions.GenerateScore(
|
|
sBullScore,
|
|
sBearScore,
|
|
sScoreMultiplier //
|
|
);
|
|
|
|
//
|
|
// Medium Market ...
|
|
|
|
//
|
|
double mBullScore = 0;
|
|
double mBearScore = 0;
|
|
double mScoreMultiplier = 1.5;
|
|
|
|
//
|
|
mConditions.GenerateScore(
|
|
mBullScore,
|
|
mBearScore,
|
|
mScoreMultiplier //
|
|
);
|
|
|
|
//
|
|
// Long Market ...
|
|
|
|
//
|
|
double lBullScore = 0;
|
|
double lBearScore = 0;
|
|
double lScoreMultiplier = 2;
|
|
|
|
//
|
|
lConditions.GenerateScore(
|
|
lBullScore,
|
|
lBearScore,
|
|
lScoreMultiplier //
|
|
);
|
|
|
|
//
|
|
// Hind Market ...
|
|
|
|
//
|
|
double hBullScore = 0;
|
|
double hBearScore = 0;
|
|
double hScoreMultiplier = 2.5;
|
|
|
|
//
|
|
hConditions.GenerateScore(
|
|
hBullScore,
|
|
hBearScore,
|
|
hScoreMultiplier //
|
|
);
|
|
|
|
//
|
|
mBullishScore = cBullScore +
|
|
sBullScore +
|
|
mBullScore +
|
|
lBullScore +
|
|
hBullScore;
|
|
|
|
//
|
|
mBearishScore = cBearScore +
|
|
sBearScore +
|
|
mBearScore +
|
|
lBearScore +
|
|
hBearScore;
|
|
|
|
//
|
|
Add(
|
|
mBullishScore,
|
|
bullishBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
Add(
|
|
mBearishScore,
|
|
bearishBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Calculate Market Normalized Scores ...
|
|
void CalculateNormalizedScores(
|
|
double &mBullishScore,
|
|
double &mBearishScore //
|
|
)
|
|
{
|
|
//
|
|
CalculateNormalization(
|
|
mBullishScore,
|
|
mBearishScore
|
|
//
|
|
);
|
|
|
|
Add(
|
|
mBullishScore,
|
|
nBullishBuffer //
|
|
);
|
|
|
|
Add(
|
|
mBearishScore,
|
|
nBearishBuffer //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Calculate Normalization Value ...
|
|
void CalculateNormalization(
|
|
double &normalBullish,
|
|
double &normalBearish //
|
|
)
|
|
{
|
|
//
|
|
normalBullish = GetNormalizedValueMethod2(
|
|
bullishBuffer,
|
|
ArraySize(bullishBuffer),
|
|
1,
|
|
-1,
|
|
0 //
|
|
);
|
|
|
|
//
|
|
normalBearish = GetNormalizedValueMethod2(
|
|
bearishBuffer,
|
|
ArraySize(bearishBuffer),
|
|
1,
|
|
-1,
|
|
0 //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Calculate Market Verifications ...
|
|
void CalculateVerifications(
|
|
int &longVerifications,
|
|
int &shortVerifications //
|
|
)
|
|
{
|
|
//
|
|
// Generate Long ans Short Verifiers ...
|
|
|
|
//
|
|
// XSTR ...
|
|
|
|
//
|
|
bool isTrendBullish =
|
|
//
|
|
hConditions.isTrendBullish &&
|
|
lConditions.isTrendBullish &&
|
|
mConditions.isTrendBullish &&
|
|
sConditions.isTrendBullish &&
|
|
cConditions.isTrendBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isTrendBullish)
|
|
{
|
|
longVerifications++;
|
|
}
|
|
|
|
//
|
|
bool isTrendBearish =
|
|
//
|
|
hConditions.isTrendBearish &&
|
|
lConditions.isTrendBearish &&
|
|
mConditions.isTrendBearish &&
|
|
sConditions.isTrendBearish &&
|
|
cConditions.isTrendBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isTrendBearish)
|
|
{
|
|
shortVerifications++;
|
|
}
|
|
|
|
//
|
|
// XTD ...
|
|
|
|
//
|
|
bool isTDBullish =
|
|
//
|
|
hConditions.isTDBullish &&
|
|
lConditions.isTDBullish &&
|
|
mConditions.isTDBullish &&
|
|
sConditions.isTDBullish &&
|
|
cConditions.isTDBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isTDBullish)
|
|
{
|
|
longVerifications++;
|
|
}
|
|
|
|
//
|
|
bool isTDBearish =
|
|
//
|
|
hConditions.isTDBearish &&
|
|
lConditions.isTDBearish &&
|
|
mConditions.isTDBearish &&
|
|
sConditions.isTDBearish &&
|
|
cConditions.isTDBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isTDBearish)
|
|
{
|
|
shortVerifications++;
|
|
}
|
|
|
|
//
|
|
// XCHE ...
|
|
|
|
//
|
|
bool isCHEBullish =
|
|
//
|
|
hConditions.isCHEBullish &&
|
|
lConditions.isCHEBullish &&
|
|
mConditions.isCHEBullish &&
|
|
sConditions.isCHEBullish &&
|
|
cConditions.isCHEBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isCHEBullish)
|
|
{
|
|
longVerifications++;
|
|
}
|
|
|
|
//
|
|
bool isCHEBearish =
|
|
//
|
|
hConditions.isCHEBearish &&
|
|
lConditions.isCHEBearish &&
|
|
mConditions.isCHEBearish &&
|
|
sConditions.isCHEBearish &&
|
|
cConditions.isCHEBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isCHEBearish)
|
|
{
|
|
shortVerifications++;
|
|
}
|
|
|
|
//
|
|
// XHK ...
|
|
|
|
//
|
|
bool isHKBullish =
|
|
//
|
|
(hConditions.isHKBullish &&
|
|
lConditions.isHKBullish &&
|
|
mConditions.isHKBullish &&
|
|
sConditions.isHKBullish &&
|
|
cConditions.isHKBullish)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isSMHKBullish &&
|
|
lConditions.isSMHKBullish &&
|
|
mConditions.isSMHKBullish &&
|
|
sConditions.isSMHKBullish &&
|
|
cConditions.isSMHKBullish)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isHKBullish)
|
|
{
|
|
longVerifications++;
|
|
}
|
|
|
|
//
|
|
bool isHKBearish =
|
|
//
|
|
(hConditions.isHKBearish &&
|
|
lConditions.isHKBearish &&
|
|
mConditions.isHKBearish &&
|
|
sConditions.isHKBearish &&
|
|
cConditions.isHKBearish)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isSMHKBearish &&
|
|
lConditions.isSMHKBearish &&
|
|
mConditions.isSMHKBearish &&
|
|
sConditions.isSMHKBearish &&
|
|
cConditions.isSMHKBearish)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isHKBearish)
|
|
{
|
|
shortVerifications++;
|
|
}
|
|
|
|
//
|
|
// XMC ...
|
|
|
|
//
|
|
bool isMCBullish =
|
|
//
|
|
(hConditions.isMCFastOverSlow &&
|
|
lConditions.isMCFastOverSlow &&
|
|
mConditions.isMCFastOverSlow &&
|
|
sConditions.isMCFastOverSlow &&
|
|
cConditions.isMCFastOverSlow)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isMCFastOverVerifier &&
|
|
lConditions.isMCFastOverVerifier &&
|
|
mConditions.isMCFastOverVerifier &&
|
|
sConditions.isMCFastOverVerifier &&
|
|
cConditions.isMCFastOverVerifier)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isMCBullish)
|
|
{
|
|
longVerifications++;
|
|
}
|
|
|
|
//
|
|
bool isMCBearish =
|
|
//
|
|
(hConditions.isMCFastUnderSlow &&
|
|
lConditions.isMCFastUnderSlow &&
|
|
mConditions.isMCFastUnderSlow &&
|
|
sConditions.isMCFastUnderSlow &&
|
|
cConditions.isMCFastUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isMCFastUnderVerifier &&
|
|
lConditions.isMCFastUnderVerifier &&
|
|
mConditions.isMCFastUnderVerifier &&
|
|
sConditions.isMCFastUnderVerifier &&
|
|
cConditions.isMCFastUnderVerifier)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isMCBearish)
|
|
{
|
|
shortVerifications++;
|
|
}
|
|
|
|
//
|
|
// XMRB ...
|
|
|
|
//
|
|
bool isMRBBullish =
|
|
//
|
|
(hConditions.isMRBFastOverSlow &&
|
|
lConditions.isMRBFastOverSlow &&
|
|
mConditions.isMRBFastOverSlow &&
|
|
sConditions.isMRBFastOverSlow &&
|
|
cConditions.isMRBFastOverSlow)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isMRBFastOverVerifier &&
|
|
lConditions.isMRBFastOverVerifier &&
|
|
mConditions.isMRBFastOverVerifier &&
|
|
sConditions.isMRBFastOverVerifier &&
|
|
cConditions.isMRBFastOverVerifier)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isMRBSlowOverVerifier &&
|
|
lConditions.isMRBSlowOverVerifier &&
|
|
mConditions.isMRBSlowOverVerifier &&
|
|
sConditions.isMRBSlowOverVerifier &&
|
|
cConditions.isMRBSlowOverVerifier)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isMRBBullish)
|
|
{
|
|
longVerifications++;
|
|
}
|
|
|
|
//
|
|
bool isMRBBearish =
|
|
//
|
|
(hConditions.isMRBFastUnderSlow &&
|
|
lConditions.isMRBFastUnderSlow &&
|
|
mConditions.isMRBFastUnderSlow &&
|
|
sConditions.isMRBFastUnderSlow &&
|
|
cConditions.isMRBFastUnderSlow)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isMRBFastUnderVerifier &&
|
|
lConditions.isMRBFastUnderVerifier &&
|
|
mConditions.isMRBFastUnderVerifier &&
|
|
sConditions.isMRBFastUnderVerifier &&
|
|
cConditions.isMRBFastUnderVerifier)
|
|
//
|
|
||
|
|
//
|
|
(hConditions.isMRBSlowUnderVerifier &&
|
|
lConditions.isMRBSlowUnderVerifier &&
|
|
mConditions.isMRBSlowUnderVerifier &&
|
|
sConditions.isMRBSlowUnderVerifier &&
|
|
cConditions.isMRBSlowUnderVerifier)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (isMRBBearish)
|
|
{
|
|
shortVerifications++;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Detect Probably Pivots ...
|
|
void HandlePivotDetection()
|
|
{
|
|
//
|
|
// Detect Pivots Based On Score Pressures ...
|
|
bool hasLastSupportAndResistance = lastSupport > 0 && lastResistance > 0;
|
|
isScoreBalanced = MathAbs(xBullishScore - xBearishScore) <= 10;
|
|
if (isScoreBalanced && !hasLastSupportAndResistance)
|
|
{
|
|
//
|
|
XOHCL xBar = cConditions.bars[0];
|
|
|
|
//
|
|
double high = xBar.FindHighest(
|
|
3,
|
|
MODE_HIGH //
|
|
);
|
|
|
|
//
|
|
double low = xBar.FindLowest(
|
|
3,
|
|
MODE_LOW //
|
|
);
|
|
|
|
//
|
|
lastSupport = low;
|
|
lastResistance = high;
|
|
|
|
//
|
|
mPivotTracker.Add(lastSupport);
|
|
mPivotTracker.Add(lastResistance);
|
|
}
|
|
|
|
//
|
|
// Detect Pivots Based on Peaks and Vales ...
|
|
|
|
// //
|
|
// // Vale ...
|
|
// bool hasLastValePivot = false; // lastVale > 0;
|
|
// bool hasValePivotCMarket =
|
|
// //
|
|
// !hasLastValePivot &&
|
|
// //
|
|
// (
|
|
// //
|
|
// (cConditions.zigzagPVs[0] == cConditions.pvVales[0] &&
|
|
// cConditions.zigzagPVs[1] == cConditions.pvVales[1] &&
|
|
// cConditions.zigzagPVs[2] == cConditions.pvVales[2] &&
|
|
// cConditions.zigzagPVs[3] == cConditions.pvVales[3])
|
|
// //
|
|
// ||
|
|
// //
|
|
// (cConditions.pvVales[0] == cConditions.pvVales[1] &&
|
|
// cConditions.pvVales[1] == cConditions.pvVales[2] &&
|
|
// cConditions.pvVales[2] == cConditions.pvVales[3] &&
|
|
// cConditions.pvVales[3] == cConditions.pvVales[4] &&
|
|
// cConditions.pvVales[4] == cConditions.pvVales[5])
|
|
// //
|
|
// )
|
|
// //
|
|
// ;
|
|
// if (hasValePivotCMarket)
|
|
// {
|
|
// //
|
|
// lastVale = cConditions.pvVales[0];
|
|
// mPivotTracker.Add(lastVale);
|
|
// }
|
|
|
|
// //
|
|
// // Peak ...
|
|
// bool hasLastPeakPivot = false; // lastPeak > 0;
|
|
// bool hasPeakPivotCMarket =
|
|
// //
|
|
// !hasLastPeakPivot &&
|
|
// //
|
|
// (
|
|
// //
|
|
// (cConditions.zigzagPVs[0] == cConditions.pvPeaks[0] &&
|
|
// cConditions.zigzagPVs[1] == cConditions.pvPeaks[1] &&
|
|
// cConditions.zigzagPVs[2] == cConditions.pvPeaks[2] &&
|
|
// cConditions.zigzagPVs[3] == cConditions.pvPeaks[3])
|
|
// //
|
|
// ||
|
|
// //
|
|
// (cConditions.pvPeaks[0] == cConditions.pvPeaks[1] &&
|
|
// cConditions.pvPeaks[1] == cConditions.pvPeaks[2] &&
|
|
// cConditions.pvPeaks[2] == cConditions.pvPeaks[3] &&
|
|
// cConditions.pvPeaks[3] == cConditions.pvPeaks[4] &&
|
|
// cConditions.pvPeaks[4] == cConditions.pvPeaks[5])
|
|
// //
|
|
// )
|
|
// //
|
|
// ;
|
|
// if (hasPeakPivotCMarket)
|
|
// {
|
|
// //
|
|
// lastPeak = cConditions.pvPeaks[0];
|
|
// mPivotTracker.Add(lastPeak);
|
|
// }
|
|
|
|
//
|
|
// Handle Draw Pivots ...
|
|
HandleDrawPivots();
|
|
}
|
|
|
|
//
|
|
// Check Conditions arround Pivots
|
|
// and Generate Signal based on them ...
|
|
// then Execute probabley Signals ...
|
|
void HandleCheckConditions()
|
|
{
|
|
//
|
|
// Here we Can Execute Signals based on Pivots ...
|
|
int pivotsCount = mPivotTracker.Count();
|
|
if (!IsValidSize(pivotsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Loop Through Pivots and Check Conditions For Trading ...
|
|
for (int i = 0; i < pivotsCount; i++)
|
|
{
|
|
//
|
|
double iPivot = mPivotTracker.Get(i);
|
|
|
|
//
|
|
HandleGeneratePivotSignal(iPivot);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Handle Trade On Pivot ...
|
|
void HandleGeneratePivotSignal(
|
|
double pivot //
|
|
)
|
|
{
|
|
//
|
|
if (pivot <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XOHCL zBar = cConditions.bars[0];
|
|
XOHCL cBar = cConditions.bars[1];
|
|
XOHCL pBar = cConditions.bars[2];
|
|
|
|
//
|
|
// Current Bar HIghest and Lowest ...
|
|
// double cHigh = cBar.FindHighest(
|
|
// 2,
|
|
// MODE_HIGH //
|
|
// );
|
|
// double cLow = cBar.FindLowest(
|
|
// 2,
|
|
// MODE_LOW //
|
|
// );
|
|
|
|
//
|
|
bool isSupportRejected =
|
|
//
|
|
// (cLow > pivot &&
|
|
// cHigh > pivot)
|
|
// //
|
|
// &&
|
|
//
|
|
cBar.HasStrongBody()
|
|
//
|
|
&&
|
|
//
|
|
cBar.IsSupportRejected(pivot)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isSupportBreaked =
|
|
//
|
|
// (cHigh < pivot &&
|
|
// cLow < pivot)
|
|
// //
|
|
// &&
|
|
//
|
|
cBar.HasStrongBody()
|
|
//
|
|
&&
|
|
//
|
|
cBar.IsSupportBreaked(pivot)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isResistanceRejected =
|
|
//
|
|
// (cLow < pivot &&
|
|
// cHigh < pivot)
|
|
// //
|
|
// &&
|
|
//
|
|
cBar.HasStrongBody()
|
|
//
|
|
&&
|
|
//
|
|
cBar.IsResistanceRejected(pivot)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isResistanceBreaked =
|
|
//
|
|
// (cHigh > pivot &&
|
|
// cLow > pivot)
|
|
// //
|
|
// &&
|
|
//
|
|
cBar.HasStrongBody()
|
|
//
|
|
&&
|
|
//
|
|
cBar.IsResistanceBreaked(pivot)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Check has Signal or not ...
|
|
bool hasLong = (isSupportRejected || isResistanceBreaked);
|
|
bool hasShort = (isSupportBreaked || isResistanceRejected);
|
|
|
|
//
|
|
if (hasLong)
|
|
{
|
|
//
|
|
Print("Has Long ...");
|
|
}
|
|
else if (hasShort)
|
|
{
|
|
//
|
|
Print("Has Short ...");
|
|
}
|
|
|
|
//
|
|
// Here we Have Calculate and Get Verifications based on Long or Short Conditions ...
|
|
|
|
//
|
|
bool longPassed =
|
|
//
|
|
(
|
|
//
|
|
(normalizeBullishScore < 0 &&
|
|
normalizeBearishScore < 0)
|
|
//
|
|
? !isScoreBalanced
|
|
: true
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
xLongVerifications >= 2
|
|
//
|
|
&&
|
|
//
|
|
xBullishScore > (xBearishScore * 1.2)
|
|
//
|
|
;
|
|
|
|
bool shortPassed =
|
|
//
|
|
(
|
|
//
|
|
(normalizeBullishScore < 0 &&
|
|
normalizeBearishScore < 0)
|
|
//
|
|
? !isScoreBalanced
|
|
: true
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
xShortVerifications >= 3
|
|
//
|
|
&&
|
|
//
|
|
xBearishScore > (xBullishScore * 1.2)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Apply Verifications to Conditions ...
|
|
|
|
//
|
|
hasLong =
|
|
!hasLong
|
|
? false
|
|
: longPassed;
|
|
|
|
//
|
|
hasShort =
|
|
!hasShort
|
|
? false
|
|
: shortPassed;
|
|
|
|
//
|
|
bool hasSignal = hasLong || hasShort;
|
|
if (!hasSignal)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Define Global Variables ...
|
|
double r2r = 1.5;
|
|
double tpPrice = 0;
|
|
double slPrice = 0;
|
|
|
|
//
|
|
// Generate Signal ...
|
|
|
|
//
|
|
ENUM_POSITION_TYPE mType =
|
|
hasLong
|
|
? POSITION_TYPE_BUY
|
|
: POSITION_TYPE_SELL;
|
|
|
|
//
|
|
double mEntry = GetEntry(
|
|
xSampleEASymbol,
|
|
mType //
|
|
);
|
|
|
|
//
|
|
// TODO: Fix SL ...
|
|
slPrice =
|
|
hasLong
|
|
? lastSupport
|
|
: lastResistance;
|
|
|
|
//
|
|
double mSL = 0;
|
|
double mTP = 0;
|
|
CalculateTPSL(
|
|
mSL,
|
|
mTP,
|
|
mType,
|
|
mEntry,
|
|
r2r,
|
|
slPrice //
|
|
);
|
|
|
|
//
|
|
XSignal signal;
|
|
bool isPrepared = signal.Prepare(
|
|
xSampleEASymbol,
|
|
"X92",
|
|
xSampleEAPeriod,
|
|
mType,
|
|
X_ORDER_MODE_MARKET,
|
|
mEntry,
|
|
0.01,
|
|
mSL,
|
|
mTP //
|
|
);
|
|
|
|
//
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
signal.comment = ToString(pivot);
|
|
|
|
//
|
|
AddRef(
|
|
signal,
|
|
mSignals //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Execute Signals ...
|
|
void HandleSignalExecution()
|
|
{
|
|
//
|
|
int signalsCount = ArraySize(mSignals);
|
|
if (!IsValidSize(signalsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XSignal tmp[];
|
|
Copy(
|
|
mSignals,
|
|
tmp //
|
|
);
|
|
|
|
//
|
|
for (int i = 0; i < signalsCount; i++)
|
|
{
|
|
//
|
|
XSignal iSignal = tmp[i];
|
|
double iPivot = (double)iSignal.comment;
|
|
iSignal.comment = NULL;
|
|
|
|
//
|
|
if (!iSignal.IsValid())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// TODO:
|
|
// Validate Signal Execution based on lastTradeOn ...
|
|
|
|
//
|
|
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
|
bool isExecuted = mTrader.ExecuteSignal(
|
|
iSignal,
|
|
state //
|
|
);
|
|
if (isExecuted)
|
|
{
|
|
//
|
|
// Remove Signal from mSignals ...
|
|
|
|
//
|
|
bool isRemoved = ArrayRemove(
|
|
mSignals,
|
|
i,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
if (isRemoved)
|
|
{
|
|
//
|
|
string message = "Signal Executed Successfully ...";
|
|
|
|
//
|
|
mAlert.Alert(message);
|
|
|
|
//
|
|
long chartID = ChartID();
|
|
|
|
//
|
|
iSignal.Draw(
|
|
chartID //
|
|
);
|
|
|
|
//
|
|
// Reset Last Values ...
|
|
if (iPivot == lastSupport)
|
|
{
|
|
lastSupport = 0;
|
|
}
|
|
else if (iPivot == lastResistance)
|
|
{
|
|
lastResistance = 0;
|
|
}
|
|
else if (iPivot == lastPeak)
|
|
{
|
|
lastPeak = 0;
|
|
}
|
|
else if (iPivot == lastVale)
|
|
{
|
|
lastVale = 0;
|
|
}
|
|
|
|
//
|
|
// Check Last Trade ON ...
|
|
lastTradeOn =
|
|
//
|
|
TimeCurrent()
|
|
//
|
|
;
|
|
|
|
//
|
|
// Remove Drawn Pivot ...
|
|
RemovePivotDraw(iPivot);
|
|
|
|
//
|
|
// Add Signal Entry Point / TP and SL as Pivots ...
|
|
mPivotTracker.Add(iSignal.entry);
|
|
mPivotTracker.Add(iSignal.tp);
|
|
mPivotTracker.Add(iSignal.sl);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
void ApplyPreDefineConfigurations()
|
|
{
|
|
//
|
|
bool isX786 = false;
|
|
bool isX121 = false;
|
|
|
|
//
|
|
if (isX786)
|
|
{
|
|
}
|
|
|
|
//
|
|
if (isX121)
|
|
{
|
|
}
|
|
}
|
|
|
|
//
|
|
void HandleDrawPivots()
|
|
{
|
|
//
|
|
// return;
|
|
bool hasChild = mPivotTracker.HasChild();
|
|
if (!hasChild)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int pivotsCount = mPivotTracker.Count();
|
|
|
|
//
|
|
for (int i = 0; i < pivotsCount; i++)
|
|
{
|
|
//
|
|
XPivot iPivot = mPivotTracker.GetPivot(i);
|
|
if (!iPivot.IsValid())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
DrawPivot(iPivot);
|
|
}
|
|
}
|
|
|
|
//
|
|
void RemovePivotDraw(double pivot)
|
|
{
|
|
//
|
|
if (pivot <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
long chartID = ChartID();
|
|
|
|
//
|
|
string pPrefix = "P_" +
|
|
ToString(pivot);
|
|
|
|
//
|
|
if (!IsDrawExists(pPrefix))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
RemoveDraw(pPrefix);
|
|
}
|
|
|
|
//
|
|
void DrawPivot(
|
|
XPivot &pivot,
|
|
color clrSupport = clrLime,
|
|
color clrResistance = clrOrangeRed //
|
|
)
|
|
{
|
|
//
|
|
if (!pivot.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
long chartID = ChartID();
|
|
datetime time1 = iTime(
|
|
xSampleEASymbol,
|
|
xSampleEAPeriod,
|
|
2 //
|
|
);
|
|
datetime time = iTime(
|
|
xSampleEASymbol,
|
|
xSampleEAPeriod,
|
|
0 //
|
|
);
|
|
|
|
//
|
|
bool currentPrice = MathMax(xSampleEATick.ask, xSampleEATick.bid);
|
|
|
|
//
|
|
bool isSupport = currentPrice > pivot.pivot;
|
|
|
|
//
|
|
color crl = isSupport
|
|
? clrSupport
|
|
: clrResistance;
|
|
|
|
//
|
|
string pPrefix = "P_" +
|
|
ToString(pivot.pivot);
|
|
|
|
//
|
|
// RemoveDraws(pPrefix);
|
|
|
|
//
|
|
if (IsDrawExists(pPrefix))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
string name =
|
|
//
|
|
(isSupport
|
|
? "SUP_"
|
|
: "RES_") +
|
|
//
|
|
pPrefix
|
|
//
|
|
;
|
|
|
|
//
|
|
DrawTrendLine(
|
|
chartID,
|
|
name,
|
|
0,
|
|
time1,
|
|
pivot.pivot,
|
|
time,
|
|
pivot.pivot,
|
|
crl,
|
|
STYLE_SOLID,
|
|
2,
|
|
false,
|
|
false,
|
|
true //
|
|
);
|
|
}
|
|
|
|
//
|
|
void ConfigureCurrentCycles() {}
|
|
|
|
//
|
|
void ConfigureShortCycles() {}
|
|
|
|
//
|
|
void ConfigureMediumCycles() {}
|
|
|
|
//
|
|
void ConfigureLongCycles() {}
|
|
|
|
//
|
|
void ConfigureHindCycles() {}
|
|
|
|
// |