cleanup and backup old styles and try toimplement new POI Detector ...
This commit is contained in:
@@ -23,9 +23,8 @@
|
||||
// Imports ...
|
||||
|
||||
//
|
||||
#include "../../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
#include "../../Classes/x-saherelm.x-alert.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-trade.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
@@ -700,7 +699,7 @@ class X121SMCTradeCollector
|
||||
)
|
||||
{
|
||||
//
|
||||
mAccount = new XSCAccount();
|
||||
mAccount = new XCAccount();
|
||||
|
||||
//
|
||||
if (IsValid(_path))
|
||||
@@ -868,7 +867,7 @@ class X121SMCTradeCollector
|
||||
string mPath; // Base Path ...
|
||||
|
||||
//
|
||||
XSCAccount *mAccount;
|
||||
XCAccount *mAccount;
|
||||
|
||||
//
|
||||
string GetFilePath(X121SMCTradeData &item)
|
||||
@@ -1085,7 +1084,7 @@ class X121SMCTradeCollector
|
||||
|
||||
//
|
||||
// Trade Handler Class ...
|
||||
class XC121SMCTradeHandler : public XSCBaseAlert
|
||||
class XC121SMCTradeHandler : public XCBaseAlert
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
@@ -1094,7 +1093,7 @@ class XC121SMCTradeHandler : public XSCBaseAlert
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XC121SMCTradeHandler(XSCTrade *trader)
|
||||
void XC121SMCTradeHandler(XCTrade *trader)
|
||||
{
|
||||
//
|
||||
mTrader = trader;
|
||||
@@ -2743,7 +2742,7 @@ class XC121SMCTradeHandler : public XSCBaseAlert
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
XSCTrade *mTrader; // Instance of Trader Class
|
||||
XCTrade *mTrader; // Instance of Trader Class
|
||||
X121SMCTradeCollector *mCollector; // Instance of Trade Collector Class
|
||||
|
||||
//
|
||||
|
||||
@@ -0,0 +1,830 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XC121SMCExpert
|
||||
// Description: provides all based classes for use ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.x-expert.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-poi.class.mq5"
|
||||
// #include "../Classes/x-121.smc.xtradehandler.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
string XC121SMCExpertToken = "XC121SMCEA";
|
||||
|
||||
//
|
||||
// Implementation ...
|
||||
|
||||
class XC121SMCExpert : public XCBaseExpert
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
|
||||
//
|
||||
// Signal Event Listener ...
|
||||
TOnStopLoss OnPositionSLEventListener;
|
||||
TOnTakeProfit OnPositionTPEventListener;
|
||||
TOnPartialClose OnPositionPartialCloseEventListener;
|
||||
TOnModify OnPositionModifiedEventListener;
|
||||
TOnForceClose OnPositionForceCloseEventListener;
|
||||
|
||||
//
|
||||
// Getter(s) / Setter(s) ...
|
||||
|
||||
/**
|
||||
* Get Use Dynamic Volume State ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool UseDynamicVolume()
|
||||
{
|
||||
return mUseDynamicVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Use Dynamic Volume State ...
|
||||
*
|
||||
* @param value: Boolean ...
|
||||
*/
|
||||
void UseDynamicVolume(bool value)
|
||||
{
|
||||
mUseDynamicVolume = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Increase Volume Step ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double DynamicVolumeStep()
|
||||
{
|
||||
return mDynamicVolumeStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Increase Volume Step ...
|
||||
*
|
||||
* @param value: Double ...
|
||||
*/
|
||||
void DynamicVolumeStep(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0.01)
|
||||
{
|
||||
value = 0.01;
|
||||
}
|
||||
|
||||
//
|
||||
mDynamicVolumeStep = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Balance Factor for Generate Dynamic Volume ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double DynamicVolumeBalanceFactor()
|
||||
{
|
||||
return mDynamicVolumeBalanceFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Balance Factor for Generate Dynamic Volume ...
|
||||
*
|
||||
* @param value: Double ...
|
||||
*/
|
||||
void DynamicVolumeBalanceFactor(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mDynamicVolumeBalanceFactor = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Static Volume ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double Volume()
|
||||
{
|
||||
return mVolume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Static Volume ...
|
||||
*
|
||||
* @param value: Double ...
|
||||
*/
|
||||
void Volume(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0.01)
|
||||
{
|
||||
value = 0.01;
|
||||
}
|
||||
|
||||
//
|
||||
mVolume = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
//
|
||||
// Override Actions ...
|
||||
|
||||
/**
|
||||
* Apply Default Configurations ...
|
||||
*/
|
||||
void DefaultConfigure() override
|
||||
{
|
||||
//
|
||||
// Commons ...
|
||||
Slippage(10);
|
||||
TagPrefix("");
|
||||
MagicNumber(1694056);
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
SetSymbol(_Symbol);
|
||||
SetPeriod(_Period);
|
||||
MultiSymbol(false);
|
||||
Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb");
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
Disabled(false);
|
||||
AllowLong(true);
|
||||
AllowShort(true);
|
||||
|
||||
//
|
||||
string tag = GetTag();
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
SetAlertPrefix(tag);
|
||||
SetAlertLogAlerts(true);
|
||||
SetAlertPushAlerts(true);
|
||||
SetAlertMailAlerts(false);
|
||||
SetAlertEnableAlerts(true);
|
||||
SetAlertTerminalAlerts(false);
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
ReportNewDays(true);
|
||||
ReportNewWeeks(false);
|
||||
ReportNewHours(false);
|
||||
ReportNewMonths(false);
|
||||
|
||||
//
|
||||
// Volume Default Configurations ...
|
||||
Volume(0.01);
|
||||
UseDynamicVolume(false);
|
||||
DynamicVolumeStep(0.01);
|
||||
DynamicVolumeBalanceFactor(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vaslidate Inputs ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs() override
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string errMessage = "";
|
||||
|
||||
//
|
||||
bool isCommonValid = (
|
||||
//
|
||||
Slippage() > 0 &&
|
||||
MagicNumber() > 0
|
||||
//
|
||||
);
|
||||
if (!isCommonValid)
|
||||
{
|
||||
//
|
||||
errMessage += "common configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Volume ...
|
||||
bool isVolumeValid = true;
|
||||
if (UseDynamicVolume())
|
||||
{
|
||||
//
|
||||
isVolumeValid =
|
||||
DynamicVolumeStep() > 0 &&
|
||||
DynamicVolumeBalanceFactor() > 0;
|
||||
if (!isVolumeValid)
|
||||
{
|
||||
errMessage += "Dynamic Volume configurations error;" + "\n";
|
||||
}
|
||||
}
|
||||
isVolumeValid = isVolumeValid &&
|
||||
Volume() > 0;
|
||||
if (!isVolumeValid)
|
||||
{
|
||||
errMessage += "Static Volume configurations error;" + "\n";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// Common ...
|
||||
isCommonValid &&
|
||||
//
|
||||
// Volume Coniguration ...
|
||||
isVolumeValid &&
|
||||
//
|
||||
// Otere ...
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||
errMessage = " Errors: \n" + errMessage;
|
||||
Alert(errMessage);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initializers and DeInitializers ...
|
||||
|
||||
/**
|
||||
* Initial EA Requirements ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitEA() override
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Indicator Helpers ...
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
mPOIDetector = new XCPOIDetector(
|
||||
symbol,
|
||||
period //
|
||||
);
|
||||
mPOIDetector.Init();
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default(); // Default Configurations ...
|
||||
mCTHelper = new XCXCTHelper();
|
||||
result = mCTHelper.Init(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default(); // Default Configurations ...
|
||||
mCCHelper = new XCXCCHelper();
|
||||
result = mCCHelper.Init(
|
||||
GetSymbol(),
|
||||
GetPeriod(),
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Trader Instance and Configure it ...
|
||||
mTrader = new XCTrade(
|
||||
Slippage(),
|
||||
MagicNumber() //
|
||||
);
|
||||
mTrader.AddOnStopLossEventHandler(OnPositionSLEventListener);
|
||||
mTrader.AddOnTakeProfitEventHandler(OnPositionTPEventListener);
|
||||
mTrader.AddOnModifyPositionEventHandler(OnPositionModifiedEventListener);
|
||||
mTrader.AddOnForceClosePositionEventHandler(OnPositionForceCloseEventListener);
|
||||
mTrader.AddOnPartialClosePositionEventHandler(OnPositionPartialCloseEventListener);
|
||||
|
||||
// //
|
||||
// // Initialize Trade Handler ...
|
||||
// mTradeHandler = new XC121SMCTradeHandler(mTrader);
|
||||
// mTradeHandler.SaveTrades(true);
|
||||
// mTradeHandler.SaveSignals(true);
|
||||
// mTradeHandler.SaveConditions(true);
|
||||
|
||||
// //
|
||||
// // Configure Alerts ...
|
||||
// mTradeHandler.SetAlertPrefix(GetTag());
|
||||
// mTradeHandler.SetAlertEnableAlerts(GetAlertEnableAlerts());
|
||||
// mTradeHandler.SetAlertLogAlerts(GetAlertLogAlerts());
|
||||
// mTradeHandler.SetAlertMailAlerts(GetAlertMailAlerts());
|
||||
// mTradeHandler.SetAlertPushAlerts(GetAlertPushAlerts());
|
||||
// mTradeHandler.SetAlertTerminalAlerts(GetAlertTerminalAlerts());
|
||||
|
||||
// //
|
||||
// // TODO: Make This Configurable Later ...
|
||||
|
||||
// //
|
||||
// mTradeHandler.DelayBarBetweenTwoSignal(3);
|
||||
// mTradeHandler.MaxAllowedSLToPause(0);
|
||||
// mTradeHandler.MaxAllowedSLReachedPauseDelay(HoursToSeconds(24));
|
||||
|
||||
// //
|
||||
// // Configure Trade Management ...
|
||||
// mTradeHandler.AllowLong(AllowLong());
|
||||
// mTradeHandler.AllowShort(AllowShort());
|
||||
// mTradeHandler.MaxAllowedLongs(0);
|
||||
// mTradeHandler.MaxAllowedShorts(0);
|
||||
// mTradeHandler.UseMaxAllowedTradesPerSymbol(true);
|
||||
// mTradeHandler.MaxDrawdownPercentForOpenTrades(5);
|
||||
|
||||
// //
|
||||
// // Configure Position Protector ...
|
||||
|
||||
// //
|
||||
// mTradeHandler.UseForceMomentumsInProtection(true);
|
||||
// mTradeHandler.DelayBarBetweenTwoSignal(2);
|
||||
|
||||
// //
|
||||
// // Configure Hedging ...
|
||||
// mTradeHandler.AllowHedge(false);
|
||||
// mTradeHandler.HedgeMinVolumeStep(0.01);
|
||||
// mTradeHandler.MinimumOpenPositionsForHEHedge(2);
|
||||
// mTradeHandler.HedgeHEMinProfitPerVolumeStep(0.2);
|
||||
// mTradeHandler.HedgeBEMinProfitPerVolumeStep(0.06);
|
||||
|
||||
// //
|
||||
// // In Profit Position Protecting ...
|
||||
|
||||
// //
|
||||
// // Trail ...
|
||||
// mTradeHandler.AllowTrail(false);
|
||||
// mTradeHandler.TrailStep(15);
|
||||
// mTradeHandler.TrailStartDistance(30);
|
||||
// mTradeHandler.OnlyTrailUnprotected(true);
|
||||
// mTradeHandler.RemoveTPAfterTrailedLevel(4);
|
||||
|
||||
// //
|
||||
// // Partial Close (In Profit) ...
|
||||
// mTradeHandler.PartialCloseInProfitDistance(0);
|
||||
// mTradeHandler.PartialCloseInProfitVolume(0);
|
||||
|
||||
// //
|
||||
// // In Drawdown Positions Protecting ...
|
||||
|
||||
// //
|
||||
// // Protect ...
|
||||
// mTradeHandler.AllowProtect(false);
|
||||
// mTradeHandler.ProtectionDelay(20);
|
||||
// mTradeHandler.MaxAllowedProtection(0);
|
||||
// mTradeHandler.UseEntryAsProtectionSL(true);
|
||||
// mTradeHandler.ProtectOnConditions(true);
|
||||
// mTradeHandler.AllowDirectionProtct(false);
|
||||
// mTradeHandler.ProtectionStartDistance(50);
|
||||
// mTradeHandler.ProtectionVolumeMultiplier(2);
|
||||
|
||||
// //
|
||||
// // Partial Close (In Profit) ...
|
||||
// mTradeHandler.PartialCloseInDrawdownDistance(0);
|
||||
// mTradeHandler.PartialCloseInDrawdownVolume(0);
|
||||
|
||||
//
|
||||
// Parsers ...
|
||||
XSymbolParser _symbolParser;
|
||||
|
||||
//
|
||||
// Single Symbol ...
|
||||
if (!MultiSymbol())
|
||||
{
|
||||
//
|
||||
// Register Strategy ...
|
||||
|
||||
//
|
||||
// Create Class Instance ...
|
||||
// XCX121SMCBaseStrategy *iX121SMCStrategy;
|
||||
// iX121SMCStrategy = new XCX121SMCTestStrategy(
|
||||
// _Symbol,
|
||||
// _Period //
|
||||
// );
|
||||
|
||||
// //
|
||||
// iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener);
|
||||
|
||||
// //
|
||||
// ConfigureStrategy(iX121SMCStrategy);
|
||||
// RegisterStrategy(iX121SMCStrategy);
|
||||
}
|
||||
//
|
||||
// Multi Symbol ...
|
||||
else
|
||||
{
|
||||
//
|
||||
// Parse Symbols ...
|
||||
string symbols[];
|
||||
int symbolsCount = SplitContent(
|
||||
symbols,
|
||||
Symbols() //
|
||||
);
|
||||
result = IsValidSize(symbolsCount);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < symbolsCount; i++)
|
||||
{
|
||||
//
|
||||
// Select Symbol ...
|
||||
string iSymbol = symbols[i];
|
||||
|
||||
//
|
||||
// Register Strategy Based On Symbol ...
|
||||
|
||||
//
|
||||
// Parse Symbol ...
|
||||
bool isEURUSD = _symbolParser.IsEURUSD(_Symbol);
|
||||
bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol);
|
||||
bool isEURGBP = _symbolParser.IsEURGBP(_Symbol);
|
||||
bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol);
|
||||
bool isEURCHF = _symbolParser.IsEURCHF(_Symbol);
|
||||
bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol);
|
||||
bool isEURJPY = _symbolParser.IsEURJPY(_Symbol);
|
||||
bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol);
|
||||
bool isEURCAD = _symbolParser.IsEURCAD(_Symbol);
|
||||
bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol);
|
||||
bool isEURAUD = _symbolParser.IsEURAUD(_Symbol);
|
||||
bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol);
|
||||
bool isEURNZD = _symbolParser.IsEURNZD(_Symbol);
|
||||
|
||||
//
|
||||
// Check Symbol Can Register or not ...
|
||||
bool canRegisterStrategy = true;
|
||||
|
||||
//
|
||||
if (canRegisterStrategy)
|
||||
{
|
||||
// //
|
||||
// // Create Class Instance ...
|
||||
// XCX121SMCBaseStrategy *iX121SMCStrategy;
|
||||
// iX121SMCStrategy = new XCX121SMCTestStrategy(
|
||||
// iSymbol,
|
||||
// _Period //
|
||||
// );
|
||||
|
||||
// //
|
||||
// iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener);
|
||||
|
||||
// //
|
||||
// // Register Strategy ...
|
||||
// ConfigureStrategy(iX121SMCStrategy);
|
||||
// RegisterStrategy(iX121SMCStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all Initialized EA Requirements ...
|
||||
*/
|
||||
void DestroyEA() override
|
||||
{
|
||||
//
|
||||
delete mCTHelper;
|
||||
delete mCCHelper;
|
||||
// delete mTradeHandler;
|
||||
|
||||
//
|
||||
// Clean(mStrategies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call all Registered Strategies On Tick ...
|
||||
*/
|
||||
void HandleStrategiesOnTick() override
|
||||
{
|
||||
//
|
||||
ENUM_XPOI_EVENTS events[];
|
||||
mPOIDetector.Update(events);
|
||||
|
||||
//
|
||||
// int count = ArraySize(mStrategies);
|
||||
// if (!IsValidSize(count))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// for (int i = 0; i < count; i++)
|
||||
// {
|
||||
// //
|
||||
// // Call Tick Handler Function ...
|
||||
// mStrategies[i].HandleTick();
|
||||
// }
|
||||
}
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Calls When a Position's SL Triggered ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void HandleOnStopLossTriggered(const XDeal &deal) override
|
||||
{
|
||||
//
|
||||
// Finish ...
|
||||
// mTradeHandler.Finish(deal);
|
||||
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls When a Position's TP Triggered ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void HandleOnTakeProfitTriggered(const XDeal &deal) override
|
||||
{
|
||||
//
|
||||
// Finish ...
|
||||
// mTradeHandler.Finish(deal);
|
||||
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Force Close a Position ...
|
||||
*
|
||||
* @param ticket: Position Ticket ...
|
||||
* @param position: XPosition ...
|
||||
* @param comment: Closing Comment ...
|
||||
*/
|
||||
void HandleOnPositionForceClosed(
|
||||
const ulong ticket,
|
||||
const XPosition &position,
|
||||
const string comment //
|
||||
) override
|
||||
{
|
||||
//
|
||||
// Finish ...
|
||||
// mTradeHandler.Finish(
|
||||
// ticket,
|
||||
// position,
|
||||
// comment //
|
||||
// );
|
||||
|
||||
//
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset All Paused Symbols on Each New Days ...
|
||||
*/
|
||||
void HandleOnNewDay() override
|
||||
{
|
||||
// mTradeHandler.ResumePausedSymbols();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Identifier Tag ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag() override
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string tagPrefix = TagPrefix();
|
||||
if (IsValid(tagPrefix))
|
||||
{
|
||||
result = tagPrefix;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
XCBaseExpertToken + result;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
datetime mLastSignalOn;
|
||||
|
||||
//
|
||||
XCPOIDetector *mPOIDetector;
|
||||
|
||||
//
|
||||
// XC121SMCTradeHandler *mTradeHandler; // Trade Handler ...
|
||||
// XCX121SMCBaseStrategy *mStrategies[]; // Registere Strategies in EA ...
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
/**
|
||||
* Apply Volume Based On Configurations on Signal ...
|
||||
*
|
||||
* @param signal: XSignal instance
|
||||
*/
|
||||
void ApplyVolumeOnSignal(XSignal &signal)
|
||||
{
|
||||
//
|
||||
// Prepare Signal Dynamic Volume
|
||||
// if Provided ...
|
||||
if (UseDynamicVolume() &&
|
||||
DynamicVolumeStep() > 0 &&
|
||||
DynamicVolumeBalanceFactor() > 0)
|
||||
{
|
||||
//
|
||||
double dVolume = mTrader.GetDynamicVolume(
|
||||
signal.symbol,
|
||||
DynamicVolumeBalanceFactor(),
|
||||
DynamicVolumeStep() //
|
||||
);
|
||||
|
||||
//
|
||||
if (dVolume > 0)
|
||||
{
|
||||
signal.volume = dVolume;
|
||||
}
|
||||
else
|
||||
{
|
||||
signal.volume = Volume();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
signal.volume = Volume();
|
||||
}
|
||||
|
||||
//
|
||||
// mTradeHandler.UpdateSignal(signal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Startegy ...
|
||||
*/
|
||||
// void ConfigureStrategy(XCX121SMCBaseStrategy *&strategy)
|
||||
// {
|
||||
// //
|
||||
// if (strategy == NULL)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Configure Alerts ...
|
||||
// strategy.SetAlertPrefix(GetTag());
|
||||
// strategy.SetAlertLogAlerts(GetAlertLogAlerts());
|
||||
// strategy.SetAlertMailAlerts(GetAlertMailAlerts());
|
||||
// strategy.SetAlertPushAlerts(GetAlertPushAlerts());
|
||||
// strategy.SetAlertEnableAlerts(GetAlertEnableAlerts());
|
||||
// strategy.SetAlertTerminalAlerts(GetAlertTerminalAlerts());
|
||||
|
||||
// //
|
||||
// // Confiugre Signalling ...
|
||||
|
||||
// //
|
||||
// strategy.R2R(2);
|
||||
// strategy.AllowLong(AllowLong());
|
||||
// strategy.AllowShort(AllowShort());
|
||||
|
||||
// //
|
||||
// if (Disabled())
|
||||
// {
|
||||
// strategy.Disable();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// strategy.Enable();
|
||||
// }
|
||||
|
||||
// //
|
||||
// }
|
||||
|
||||
/**
|
||||
* Register an Strategy in EA ...
|
||||
*
|
||||
* @param strategy: XCX121SMCBaseStrategy instance ...
|
||||
*/
|
||||
// void RegisterStrategy(XCX121SMCBaseStrategy *strategy)
|
||||
// {
|
||||
// //
|
||||
// if (strategy == NULL)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// ArrayResize(
|
||||
// mStrategies,
|
||||
// ArraySize(mStrategies) + 1 //
|
||||
// );
|
||||
|
||||
// //
|
||||
// mStrategies[ArraySize(mStrategies) - 1] = strategy;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Re Configure All Registered Strategies ...
|
||||
*/
|
||||
// void ReConfigureAllStrategies()
|
||||
// {
|
||||
// //
|
||||
// int count = ArraySize(mStrategies);
|
||||
// if (!IsValidSize(count))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// for (int i = 0; i < count; i++)
|
||||
// {
|
||||
// //
|
||||
// ConfigureStrategy(mStrategies[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Volume Management ...
|
||||
bool mUseDynamicVolume; // Use Dynamic Volume ...
|
||||
double mDynamicVolumeStep; // Increase Volume Step ...
|
||||
double mDynamicVolumeBalanceFactor; // Balance Factor for Generate Dynamic Volume ...
|
||||
double mVolume; // Static Volume ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,752 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX3MAHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_X3MA_BUFFERS
|
||||
{
|
||||
//
|
||||
X3MA_FAST_LINE = 0,
|
||||
X3MA_MID_LINE = 1,
|
||||
X3MA_SLOW_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct X3MAInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int fastLength; // Fast Length
|
||||
int midLength; // Mid Length
|
||||
int slowLength; // Slow Length
|
||||
int shiftLength; // Shift
|
||||
ENUM_MA_METHOD method; // Mode
|
||||
ENUM_APPLIED_PRICE appliedTo; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
|
||||
//
|
||||
bool showFast; // Show Fast
|
||||
bool showMid; // Show Mid
|
||||
bool showSlow; // Show Slow
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
X3MAInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
fastLength = 0;
|
||||
midLength = 0;
|
||||
slowLength = 0;
|
||||
shiftLength = 0;
|
||||
method = MODE_SMA;
|
||||
appliedTo = PRICE_CLOSE;
|
||||
|
||||
//
|
||||
showFast = false;
|
||||
showMid = false;
|
||||
showSlow = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
fastLength = 50;
|
||||
midLength = 100;
|
||||
slowLength = 200;
|
||||
shiftLength = 0;
|
||||
method = MODE_SMA;
|
||||
appliedTo = PRICE_CLOSE;
|
||||
|
||||
//
|
||||
showFast = true;
|
||||
showMid = true;
|
||||
showSlow = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
midLength > fastLength &&
|
||||
slowLength > midLength &&
|
||||
//
|
||||
shiftLength >= 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(fastLength, midLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct X3MAConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double fasts[];
|
||||
double mids[];
|
||||
double slows[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isFastOverMid;
|
||||
bool isMidOverSlow;
|
||||
|
||||
//
|
||||
bool isFastUnderMid;
|
||||
bool isMidUnderSlow;
|
||||
|
||||
//
|
||||
bool isBullishOrdered;
|
||||
bool isBearishOrdered;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullishOrdered;
|
||||
bool isSwitchedToBearishOrdered;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(fasts);
|
||||
Clean(mids);
|
||||
Clean(slows);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fasts, true);
|
||||
ArraySetAsSeries(mids, true);
|
||||
ArraySetAsSeries(slows, true);
|
||||
|
||||
//
|
||||
isFastOverMid = false;
|
||||
isMidOverSlow = false;
|
||||
isFastUnderMid = false;
|
||||
isMidUnderSlow = false;
|
||||
isBullishOrdered = false;
|
||||
isBearishOrdered = false;
|
||||
isSwitchedToBullishOrdered = false;
|
||||
isSwitchedToBearishOrdered = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
// Since We have to Use this
|
||||
// Only for Filtering Signals ...
|
||||
// We Can Ignore Scoring ...
|
||||
// or Complete this later ...
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "X3MA";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCX3MAHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCX3MAHelper()
|
||||
: XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCX3MAHelper()
|
||||
{
|
||||
//
|
||||
Clean(fastBuffer);
|
||||
Clean(midBuffer);
|
||||
Clean(slowBuffer);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
X3MAInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.x3ma",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.fastLength,
|
||||
mInputs.midLength,
|
||||
mInputs.slowLength,
|
||||
mInputs.shiftLength,
|
||||
mInputs.method,
|
||||
mInputs.appliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
//
|
||||
mInputs.showFast,
|
||||
mInputs.showMid,
|
||||
mInputs.showSlow
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
X3MAInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
X3MAInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetFast(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(fastBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return fastBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyFast(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
fastBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetMid(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(midBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return midBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyMid(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
midBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetSlow(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(slowBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return slowBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopySlow(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
slowBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
X3MAConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
CopyFast(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.fasts //
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
CopyMid(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.mids //
|
||||
);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
CopySlow(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.slows //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isFastOverMid =
|
||||
conditions.fasts[cIndex] > conditions.mids[cIndex];
|
||||
bool isFastOverMidPrev =
|
||||
conditions.fasts[pIndex] > conditions.mids[pIndex];
|
||||
|
||||
//
|
||||
bool isMidOverSlow =
|
||||
conditions.mids[cIndex] > conditions.slows[cIndex];
|
||||
bool isMidOverSlowPrev =
|
||||
conditions.mids[pIndex] > conditions.slows[pIndex];
|
||||
|
||||
//
|
||||
bool isFastUnderMid =
|
||||
conditions.fasts[cIndex] < conditions.mids[cIndex];
|
||||
bool isFastUnderMidPrev =
|
||||
conditions.fasts[pIndex] < conditions.mids[pIndex];
|
||||
|
||||
//
|
||||
bool isMidUnderSlow =
|
||||
conditions.mids[cIndex] < conditions.slows[cIndex];
|
||||
bool isMidUnderSlowPrev =
|
||||
conditions.mids[pIndex] < conditions.slows[pIndex];
|
||||
|
||||
//
|
||||
bool isBullishOrdered = isFastOverMid &&
|
||||
isMidOverSlow;
|
||||
bool isBullishOrderedPrev = isFastOverMidPrev &&
|
||||
isMidOverSlowPrev;
|
||||
|
||||
//
|
||||
bool isBearishOrdered = isFastUnderMid &&
|
||||
isMidUnderSlow;
|
||||
bool isBearishOrderedPrev = isFastUnderMidPrev &&
|
||||
isMidUnderSlowPrev;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullishOrdered = isBullishOrdered &&
|
||||
!isBullishOrderedPrev;
|
||||
bool isSwitchedToBearishOrdered = isBearishOrdered &&
|
||||
!isBearishOrderedPrev;
|
||||
|
||||
//
|
||||
conditions.isFastOverMid = isFastOverMid;
|
||||
conditions.isMidOverSlow = isMidOverSlow;
|
||||
conditions.isFastUnderMid = isFastUnderMid;
|
||||
conditions.isMidUnderSlow = isMidUnderSlow;
|
||||
conditions.isBullishOrdered = isBullishOrdered;
|
||||
conditions.isBearishOrdered = isBearishOrdered;
|
||||
conditions.isSwitchedToBullishOrdered = isSwitchedToBullishOrdered;
|
||||
conditions.isSwitchedToBearishOrdered = isSwitchedToBearishOrdered;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X3MAInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double fastBuffer[];
|
||||
double midBuffer[];
|
||||
double slowBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000)
|
||||
{
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X3MA_FAST_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
fastBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X3MA_MID_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
midBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X3MA_SLOW_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
slowBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,245 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCCHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XCCInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Chart Style ...
|
||||
ENUM_CHART_MODE mode; // Mode
|
||||
color upColor; // Up Color
|
||||
color downColor; // Down Color
|
||||
color lineColor; // Line mode and Doji candlestick Color
|
||||
color bearishColor; // Bullish Color
|
||||
color bullishColor; // Bearish Color
|
||||
color volumesColor; // Volumes Color
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandles; // Show Candles
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XCCInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = CLR_NONE;
|
||||
downColor = CLR_NONE;
|
||||
lineColor = CLR_NONE;
|
||||
bearishColor = CLR_NONE;
|
||||
bullishColor = CLR_NONE;
|
||||
volumesColor = CLR_NONE;
|
||||
|
||||
//
|
||||
showCandles = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = clrLime;
|
||||
downColor = clrRed;
|
||||
lineColor = clrLime;
|
||||
bearishColor = clrRed;
|
||||
bullishColor = clrLime;
|
||||
volumesColor = clrGreen;
|
||||
//
|
||||
showCandles = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXCCHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXCCHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XCCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
mInputs.mode, // Mode
|
||||
mInputs.upColor, // Up Color
|
||||
mInputs.downColor, // Down Color
|
||||
mInputs.lineColor, // Line mode and Doji candlestick Color
|
||||
mInputs.bearishColor, // Bullish Color
|
||||
mInputs.bullishColor, // Bearish Color
|
||||
mInputs.volumesColor, // Volumes Color
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandles // Show Candles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XCCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XCCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XCCInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -1,220 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XCTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
color clr; // Text Color
|
||||
ENUM_BASE_CORNER corner; // Text Position
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XCTInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
clr = clrYellow;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXCTHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXCTHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xct",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.clr, // Text Color
|
||||
mInputs.corner, // Text Position
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandleTime // Show Candle Time
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XCTInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -1,394 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X3MA
|
||||
// Description: X3MA Trend Detector ...
|
||||
//
|
||||
// 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 X3MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X3MA"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int fastLength = 50; // Fast Length
|
||||
input int midLength = 100; // Mid Length
|
||||
input int slowLength = 200; // Slow Length
|
||||
input int shiftLength = 0; // Shift
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Mode
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
// Parts ...
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showMid = true; // Show Mid
|
||||
input bool showSlow = true; // Show Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
#define fastBufferIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "X3MA F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
#define midBufferIndex 1
|
||||
double midBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "X3MA M"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrOrange
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
#define slowBufferIndex 2
|
||||
double slowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "X3MA S"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMagenta
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Handlers ...
|
||||
int fastHandler = INVALID_HANDLE;
|
||||
int midHandler = INVALID_HANDLE;
|
||||
int slowHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitHandlers())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Release Handlers ...
|
||||
IndicatorRelease(fastHandler);
|
||||
IndicatorRelease(midHandler);
|
||||
IndicatorRelease(slowHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
BarsCalculated(fastHandler) >= maxLength &&
|
||||
BarsCalculated(midHandler) >= maxLength &&
|
||||
BarsCalculated(slowHandler) >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
//
|
||||
int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer);
|
||||
int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer);
|
||||
int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
copiedFasts > 0 &&
|
||||
copiedMids > 0 &&
|
||||
copiedSlows > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
midLength > fastLength &&
|
||||
slowLength > midLength &&
|
||||
//
|
||||
shiftLength >= 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
result = MathMax(fastLength, midLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
bool canShowFast = showFast;
|
||||
ENUM_DRAW_TYPE fastDrawType = canShowFast ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, canShowFast);
|
||||
PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
bool canShowMid = showMid;
|
||||
ENUM_DRAW_TYPE midDrawType = canShowMid ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, canShowMid);
|
||||
PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
bool canShowSlow = showSlow;
|
||||
ENUM_DRAW_TYPE slowDrawType = canShowSlow ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, canShowSlow);
|
||||
PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Indicator Handlers ...
|
||||
bool InitHandlers()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initialize Handlers ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
fastHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastLength,
|
||||
shiftLength,
|
||||
method,
|
||||
appliedTo //
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
midHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
midLength,
|
||||
shiftLength,
|
||||
method,
|
||||
appliedTo //
|
||||
);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
slowHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowLength,
|
||||
shiftLength,
|
||||
method,
|
||||
appliedTo //
|
||||
);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
fastHandler != INVALID_HANDLE &&
|
||||
midHandler != INVALID_HANDLE &&
|
||||
slowHandler != INVALID_HANDLE
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,564 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: X3VWAP
|
||||
// Description: X3VWAP Trend Detector ...
|
||||
//
|
||||
// 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 X3VWAP Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X3VWAP"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int fastLength = 50; // Fast Length
|
||||
input int midLength = 100; // Mid Length
|
||||
input int slowLength = 200; // Slow Length
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showFast = true; // Show Fast
|
||||
input bool showMid = true; // Show Mid
|
||||
input bool showSlow = true; // Show Slow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 11
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
#define fastBufferIndex 0
|
||||
double fastBuffer[];
|
||||
|
||||
#define fastColorBufferIndex 1
|
||||
double fastColorBuffer[];
|
||||
|
||||
//
|
||||
#define fastPlotBufferIndex 0
|
||||
#property indicator_label1 "X3VWAP F"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
#define midBufferIndex 2
|
||||
double midBuffer[];
|
||||
|
||||
#define midColorBufferIndex 3
|
||||
double midColorBuffer[];
|
||||
|
||||
//
|
||||
#define midPlotBufferIndex 1
|
||||
#property indicator_label2 "X3VWAP M"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
#define slowBufferIndex 4
|
||||
double slowBuffer[];
|
||||
|
||||
#define slowColorBufferIndex 5
|
||||
double slowColorBuffer[];
|
||||
|
||||
//
|
||||
#define slowPlotBufferIndex 2
|
||||
#property indicator_label3 "X3VWAP S"
|
||||
#property indicator_type3 DRAW_COLOR_LINE
|
||||
#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
#define volumeBufferIndex 6
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// Price ...
|
||||
#define priceBufferIndex 7
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
#define fastStateBufferIndex 8
|
||||
double fastStateBuffer[];
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
#define midStateBufferIndex 9
|
||||
double midStateBuffer[];
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
#define slowStateBufferIndex 10
|
||||
double slowStateBuffer[];
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit =
|
||||
(prev_calculated > rates_total || prev_calculated <= 0)
|
||||
? rates_total
|
||||
: (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
fastLength > 2 &&
|
||||
midLength > fastLength &&
|
||||
slowLength > midLength
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
result = MathMax(fastLength, midLength);
|
||||
result = MathMax(result, slowLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
ArraySetAsSeries(fastBuffer, true);
|
||||
ArraySetAsSeries(fastColorBuffer, true);
|
||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
ArraySetAsSeries(midBuffer, true);
|
||||
ArraySetAsSeries(midColorBuffer, true);
|
||||
SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(midColorBufferIndex, midColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
ArraySetAsSeries(slowBuffer, true);
|
||||
ArraySetAsSeries(slowColorBuffer, true);
|
||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
// Volumes ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Price ...
|
||||
ArraySetAsSeries(priceBuffer, true);
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Fast State ...
|
||||
ArraySetAsSeries(fastStateBuffer, true);
|
||||
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Mid State ...
|
||||
ArraySetAsSeries(midStateBuffer, true);
|
||||
SetIndexBuffer(midStateBufferIndex, midStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Slow State ...
|
||||
ArraySetAsSeries(slowStateBuffer, true);
|
||||
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate Volumes and Price ...
|
||||
|
||||
//
|
||||
if (ratesTotal - bar_index <= maxLength)
|
||||
{
|
||||
//
|
||||
CalculateDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
CalculateDataBuffers(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
|
||||
//
|
||||
CalculateVWAPS(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Required Data Buffers ...
|
||||
void CalculateDataBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double price = GetAppliedPrice(
|
||||
appliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
priceBuffer[bar_index] = price;
|
||||
volumeBuffer[bar_index] = (double)tickVolume[bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Different VWaps ...
|
||||
void CalculateVWAPS(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Fast ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
fastLength,
|
||||
showFast,
|
||||
fastBuffer,
|
||||
fastColorBuffer,
|
||||
fastStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Mid ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
midLength,
|
||||
showMid,
|
||||
midBuffer,
|
||||
midColorBuffer,
|
||||
midStateBuffer //
|
||||
);
|
||||
|
||||
//
|
||||
// Fast ...
|
||||
CalculateVWAP(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume,
|
||||
//
|
||||
slowLength,
|
||||
showSlow,
|
||||
slowBuffer,
|
||||
slowColorBuffer,
|
||||
slowStateBuffer //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate VWAP ...
|
||||
void CalculateVWAP(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[],
|
||||
//
|
||||
int _length, // Calculation Length
|
||||
bool _show,
|
||||
double &_buffer[],
|
||||
double &_colorBuffer[],
|
||||
double &_stateBuffer[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double vSum = 0;
|
||||
double pSum = 0;
|
||||
double mSum = 0;
|
||||
for (int x = 0; x < _length; x++)
|
||||
{
|
||||
//
|
||||
pSum += priceBuffer[x + bar_index];
|
||||
vSum += volumeBuffer[x + bar_index];
|
||||
mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = mSum / vSum;
|
||||
iValue = NormalizeDouble(iValue, _Digits);
|
||||
|
||||
//
|
||||
_buffer[bar_index] = iValue;
|
||||
|
||||
//
|
||||
bool isBullish = low[bar_index] > iValue;
|
||||
bool isBearish = high[bar_index] < iValue;
|
||||
|
||||
//
|
||||
double iColor =
|
||||
isBullish
|
||||
? bullishColorIDX
|
||||
: isBearish
|
||||
? bearishColorIDX
|
||||
: neuturalColorIDX;
|
||||
|
||||
//
|
||||
_colorBuffer[bar_index] = hideColorIDX;
|
||||
_stateBuffer[bar_index] = iColor;
|
||||
if (_show)
|
||||
{
|
||||
_colorBuffer[bar_index] = iColor;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,437 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: XCC
|
||||
// Description: Candle Styles ...
|
||||
//
|
||||
//
|
||||
// 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 XCC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XCC"
|
||||
|
||||
//
|
||||
// Holds an SnapShot of Charts Configuration ...
|
||||
struct XChartStyle
|
||||
{
|
||||
//
|
||||
// chart's ID ...
|
||||
long chartId;
|
||||
//
|
||||
// chart's mode ...
|
||||
ENUM_CHART_MODE mode;
|
||||
//
|
||||
// show bid line ...
|
||||
bool showBidLine;
|
||||
//
|
||||
// show ask line ...
|
||||
bool showAskLine;
|
||||
//
|
||||
// show grids on chart ...
|
||||
bool showGrid;
|
||||
//
|
||||
// show volumes ...
|
||||
bool showVolumes;
|
||||
//
|
||||
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
|
||||
bool showTradeLevels;
|
||||
//
|
||||
// chart autoscroll ...
|
||||
bool autoScroll;
|
||||
//
|
||||
// chart quick navigation state ...
|
||||
bool quickNavigation;
|
||||
//
|
||||
// chart's foreground color ...
|
||||
color foreGroundColor;
|
||||
//
|
||||
// chart's background color ...
|
||||
color backGroundColor;
|
||||
//
|
||||
// Up Color ...
|
||||
color upColor;
|
||||
//
|
||||
// Down Color ...
|
||||
color downColor;
|
||||
//
|
||||
// Bullish color ...
|
||||
color bullishColor;
|
||||
//
|
||||
// Bearish color ...
|
||||
color bearishColor;
|
||||
//
|
||||
// grid color ...
|
||||
color gridColor;
|
||||
//
|
||||
// bid line color ...
|
||||
color bidLineColor;
|
||||
//
|
||||
// ask line color ...
|
||||
color askLineColor;
|
||||
//
|
||||
// line mode and doji candlestick color ...
|
||||
color lineColor;
|
||||
//
|
||||
// Color of stop order levels (Stop Loss and Take Profit) ...
|
||||
color stopColor;
|
||||
//
|
||||
// volumes color ...
|
||||
color volumesColor;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Chart Style";
|
||||
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
|
||||
input color upColor = clrLime; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrLime; // Line mode and Doji candlestick Color
|
||||
input color bearishColor = clrRed; // Bullish Color
|
||||
input color bullishColor = clrLime; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XChartStyle chartStyle;
|
||||
XChartStyle clearStyle;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Apply Chart Style ...
|
||||
ApplyCustomChartStyle();
|
||||
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Custom Chart Style ...
|
||||
void ApplyCustomChartStyle()
|
||||
{
|
||||
//
|
||||
// Read Current Chart Config and Store it ...
|
||||
ReadChartStyle();
|
||||
|
||||
//
|
||||
// After Reading Current Chart Style ...
|
||||
// we have to Save Configs and Change Styles ...
|
||||
clearStyle = chartStyle;
|
||||
|
||||
//
|
||||
clearStyle.upColor = CLR_NONE;
|
||||
clearStyle.downColor = CLR_NONE;
|
||||
clearStyle.lineColor = CLR_NONE;
|
||||
clearStyle.bullishColor = CLR_NONE;
|
||||
clearStyle.bearishColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Decide to Show or not Candles based on User Input ...
|
||||
if (showCandles)
|
||||
{
|
||||
SetChartStyle(chartStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChartStyle(clearStyle);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read Previous Chart Style ...
|
||||
void ReadChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
chartStyle.chartId = chartId;
|
||||
|
||||
//
|
||||
// Retrieve Chart Mode ...
|
||||
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
|
||||
|
||||
//
|
||||
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
|
||||
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
|
||||
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
|
||||
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
|
||||
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
|
||||
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
|
||||
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
|
||||
|
||||
//
|
||||
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
|
||||
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
|
||||
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
|
||||
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
|
||||
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
|
||||
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
|
||||
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
|
||||
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
|
||||
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
|
||||
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
|
||||
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
|
||||
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
|
||||
|
||||
//
|
||||
chartStyle.mode = mode;
|
||||
chartStyle.upColor = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
void SetChartStyle(
|
||||
XChartStyle &mChartStyle // Chart Style to Apply
|
||||
)
|
||||
{
|
||||
//
|
||||
ApplyChartStyle(
|
||||
mChartStyle.chartId,
|
||||
mChartStyle.mode,
|
||||
mChartStyle.showBidLine,
|
||||
mChartStyle.showAskLine,
|
||||
mChartStyle.showGrid,
|
||||
mChartStyle.showVolumes,
|
||||
mChartStyle.showTradeLevels,
|
||||
mChartStyle.autoScroll,
|
||||
mChartStyle.quickNavigation,
|
||||
mChartStyle.foreGroundColor,
|
||||
mChartStyle.backGroundColor,
|
||||
mChartStyle.upColor,
|
||||
mChartStyle.downColor,
|
||||
mChartStyle.bullishColor,
|
||||
mChartStyle.bearishColor,
|
||||
mChartStyle.gridColor,
|
||||
mChartStyle.bidLineColor,
|
||||
mChartStyle.askLineColor,
|
||||
mChartStyle.lineColor,
|
||||
mChartStyle.stopColor,
|
||||
mChartStyle.volumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -1,270 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XCT
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// 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 XCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "XCT"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandleTime = true; // Show Candle Time
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (showCandleTime)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectDelete(0, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
ulong chID = FindChartID(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(chID, ShortName);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(time, true);
|
||||
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
ulong chID = FindChartID(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
XBarRemainsTime barRemains;
|
||||
barRemains.Init(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
string msg = barRemains
|
||||
.ToString(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
":",
|
||||
true
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
|
||||
|
||||
//
|
||||
string _sp = "";
|
||||
if (mSpread < 10)
|
||||
_sp = "..";
|
||||
else if (mSpread < 100)
|
||||
_sp = ".";
|
||||
|
||||
//
|
||||
// int offset = TimeGMTOffset();
|
||||
// string timeString =
|
||||
// ", Time: " + string(TimeCurrent()) + "\n" +
|
||||
// ", ServerTime: " + string(TimeTradeServer()) + "\n" +
|
||||
// ", GMT Offset: " + (string)offset;
|
||||
// timeString = timeString;
|
||||
// Comment(timeString);
|
||||
|
||||
//
|
||||
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
|
||||
|
||||
//
|
||||
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
|
||||
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
|
||||
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
|
||||
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier");
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
void CreateIndicatorObject()
|
||||
{
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
|
||||
|
||||
//
|
||||
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
||||
switch (corner)
|
||||
{
|
||||
case CORNER_LEFT_UPPER:
|
||||
Anchor = ANCHOR_LEFT_UPPER;
|
||||
break;
|
||||
case CORNER_RIGHT_UPPER:
|
||||
Anchor = ANCHOR_RIGHT_UPPER;
|
||||
break;
|
||||
case CORNER_LEFT_LOWER:
|
||||
Anchor = ANCHOR_LEFT_LOWER;
|
||||
break;
|
||||
case CORNER_RIGHT_LOWER:
|
||||
Anchor = ANCHOR_RIGHT_LOWER;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -1,856 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Seriallize Library
|
||||
// ---------------------------------------
|
||||
// Name: X121SMCLib
|
||||
// Description: All models related to X121SMC ...
|
||||
//
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.base.class.mq5"
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.xtrade.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Specific Identifier(s) of XStrategy ...
|
||||
string X121SMCStrategyToken = "X121SMC";
|
||||
string X121SMCOBStrategyToken = "X121SMCOB";
|
||||
string X121SMCSUPDEMStrategyToken = "X121SMCSUPDEM";
|
||||
string X121SMCConditionsToken = "X121SMCConditions";
|
||||
string X121SMCMarketStructureToken = "X121SMCMarketStructure";
|
||||
|
||||
//
|
||||
// Condition Structure ...
|
||||
struct X121SMCStrategyConditions
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
XOHCL swingHigh;
|
||||
XZone supplyZone;
|
||||
XZone bearishFVG;
|
||||
XOHCL resistance;
|
||||
XZone bearishOrderBlock;
|
||||
XOHCL bullishMomentumBar;
|
||||
XOHCL bullishRejectionBar;
|
||||
|
||||
//
|
||||
XZone demandZones[];
|
||||
XZone bearishFVGs[];
|
||||
XZone bearishOrderBlocks[];
|
||||
XOHCL swingHighs[];
|
||||
XOHCL resistances[];
|
||||
XOHCL bearishMomentumBars[];
|
||||
XOHCL bearishRejectionBars[];
|
||||
|
||||
//
|
||||
XOHCL support;
|
||||
XOHCL swingLow;
|
||||
XZone demandZone;
|
||||
XZone bullishFVG;
|
||||
XZone bullishOrderBlock;
|
||||
XOHCL bearishMomentumBar;
|
||||
XOHCL bearishRejectionBar;
|
||||
|
||||
//
|
||||
XZone supplyZones[];
|
||||
XZone bullishFVGs[];
|
||||
XZone bullishOrderBlocks[];
|
||||
XOHCL supports[];
|
||||
XOHCL swingLows[];
|
||||
XOHCL bullishMomentumBars[];
|
||||
XOHCL bullishRejectionBars[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XStrategyConditions()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
time = NULL;
|
||||
|
||||
//
|
||||
CleanDemand();
|
||||
CleanSupply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup Demand Related ...
|
||||
*/
|
||||
void CleanDemand()
|
||||
{
|
||||
//
|
||||
support.Clean();
|
||||
swingLow.Clean();
|
||||
demandZone.Clean();
|
||||
bullishFVG.Clean();
|
||||
bullishOrderBlock.Clean();
|
||||
bullishMomentumBar.Clean();
|
||||
bullishRejectionBar.Clean();
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
Clean(swingLows);
|
||||
Clean(supplyZones);
|
||||
Clean(bullishFVGs);
|
||||
Clean(bullishOrderBlocks);
|
||||
Clean(bullishMomentumBars);
|
||||
Clean(bullishRejectionBars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup Supply Related ...
|
||||
*/
|
||||
void CleanSupply()
|
||||
{
|
||||
//
|
||||
swingHigh.Clean();
|
||||
supplyZone.Clean();
|
||||
bearishFVG.Clean();
|
||||
resistance.Clean();
|
||||
bearishOrderBlock.Clean();
|
||||
bearishMomentumBar.Clean();
|
||||
bearishRejectionBar.Clean();
|
||||
|
||||
//
|
||||
Clean(swingHighs);
|
||||
Clean(demandZones);
|
||||
Clean(bearishFVGs);
|
||||
Clean(resistances);
|
||||
Clean(bearishOrderBlocks);
|
||||
Clean(bearishMomentumBars);
|
||||
Clean(bearishRejectionBars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Demand ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateDemand()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
support.IsValid() &&
|
||||
swingLow.IsValid() &&
|
||||
demandZone.IsValid() &&
|
||||
bullishFVG.IsValid() &&
|
||||
bullishOrderBlock.IsValid() &&
|
||||
bullishMomentumBar.IsValid() &&
|
||||
bullishRejectionBar.IsValid() &&
|
||||
//
|
||||
(ArraySize(supports) > 0 ||
|
||||
ArraySize(swingLows) > 0 ||
|
||||
ArraySize(supplyZones) > 0 ||
|
||||
ArraySize(bullishFVGs) > 0 ||
|
||||
ArraySize(bullishOrderBlocks) > 0 ||
|
||||
ArraySize(bullishMomentumBars) > 0 ||
|
||||
ArraySize(bullishRejectionBars) > 0)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Supply ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateSupply()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
swingHigh.IsValid() &&
|
||||
supplyZone.IsValid() &&
|
||||
bearishFVG.IsValid() &&
|
||||
resistance.IsValid() &&
|
||||
bearishOrderBlock.IsValid() &&
|
||||
bearishMomentumBar.IsValid() &&
|
||||
bearishRejectionBar.IsValid() &&
|
||||
//
|
||||
(ArraySize(swingHighs) > 0 ||
|
||||
ArraySize(demandZones) > 0 ||
|
||||
ArraySize(bearishFVGs) > 0 ||
|
||||
ArraySize(resistances) > 0 ||
|
||||
ArraySize(bearishOrderBlocks) > 0 ||
|
||||
ArraySize(bearishMomentumBars) > 0 ||
|
||||
ArraySize(bearishRejectionBars) > 0)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(time) &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Provided Scores ...
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double bullScore = 0;
|
||||
double bearScore = 0;
|
||||
|
||||
//
|
||||
// Generate Helpers Conitions Scores ...
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Summary ...
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
// Generate Helpers Conditions Strings ...
|
||||
|
||||
//
|
||||
// Combine Helpers Conditions Strings ...
|
||||
string conditionsStr =
|
||||
//
|
||||
"" + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
"----------" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag(
|
||||
bool fullTag = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (fullTag)
|
||||
{
|
||||
//
|
||||
result =
|
||||
//
|
||||
symbol + "," +
|
||||
ToString(period) + "," +
|
||||
ToFormatString(time) + "_" +
|
||||
demandZone.GetTag() + "," +
|
||||
supplyZone.GetTag() + "_" +
|
||||
bullishOrderBlock.GetTag() + "," +
|
||||
bearishOrderBlock.GetTag()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result = X121SMCConditionsToken + "_" + ToMD5(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = X121SMCConditionsToken;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Market Structure Models ...
|
||||
struct X121SMCMarketStructure
|
||||
{
|
||||
//
|
||||
XZone demandZone;
|
||||
XZone supplyZone;
|
||||
|
||||
//
|
||||
XZone bullishOrderBlock;
|
||||
XZone bearishOrderBlock;
|
||||
|
||||
//
|
||||
XZone demandZones[];
|
||||
XZone supplyZones[];
|
||||
|
||||
//
|
||||
XZone bearishOrderBlocks[];
|
||||
XZone bearishFVGs[];
|
||||
|
||||
//
|
||||
XOHCL swingHighs[];
|
||||
XOHCL resistances[];
|
||||
XOHCL bearishMomentumBars[];
|
||||
XOHCL bearishRejectionBars[];
|
||||
|
||||
//
|
||||
XZone bullishOrderBlocks[];
|
||||
XZone bullishFVGs[];
|
||||
|
||||
//
|
||||
XOHCL supports[];
|
||||
XOHCL swingLows[];
|
||||
XOHCL bullishMomentumBars[];
|
||||
XOHCL bullishRejectionBars[];
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
demandZone.Clean();
|
||||
supplyZone.Clean();
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
Clean(swingLows);
|
||||
Clean(swingHighs);
|
||||
Clean(demandZones);
|
||||
Clean(supplyZones);
|
||||
Clean(bearishFVGs);
|
||||
Clean(resistances);
|
||||
Clean(bullishFVGs);
|
||||
Clean(bearishOrderBlocks);
|
||||
Clean(bullishOrderBlocks);
|
||||
Clean(bearishMomentumBars);
|
||||
Clean(bearishRejectionBars);
|
||||
Clean(bullishMomentumBars);
|
||||
Clean(bullishRejectionBars);
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
demandZone.GetTag() + "," +
|
||||
supplyZone.GetTag() + "_" +
|
||||
bullishOrderBlock.GetTag() + "," +
|
||||
bearishOrderBlock.GetTag()
|
||||
//
|
||||
;
|
||||
result = X121SMCMarketStructureToken + "_" + ToMD5(X121SMCMarketStructureToken);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// On Signal Event Handler ...
|
||||
typedef void (*TOnX121SMCSignal)(
|
||||
XSignal &signal,
|
||||
X121SMCStrategyConditions &conditions //
|
||||
);
|
||||
|
||||
//
|
||||
struct XRange
|
||||
{
|
||||
//
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
double upper;
|
||||
double lower;
|
||||
|
||||
//
|
||||
datetime from;
|
||||
datetime to;
|
||||
|
||||
//
|
||||
void XRange()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Initial ...
|
||||
*
|
||||
* @param _symbol: String ...
|
||||
* @param _period: ENUM_TIMEFRAMES member ...
|
||||
* @param _upper: Double ...
|
||||
* @param _lower: Double ...
|
||||
* @param _from: DateTime ...
|
||||
* @param _to: DateTime ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Init(
|
||||
string _symbol,
|
||||
ENUM_TIMEFRAMES _period,
|
||||
double _upper,
|
||||
double _lower,
|
||||
datetime _from,
|
||||
datetime _to //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(_symbol) &&
|
||||
IsValid(_period) &&
|
||||
IsValid(_from) &&
|
||||
IsValid(_to) &&
|
||||
_upper > 0 &&
|
||||
_lower > 0 &&
|
||||
_to > _from
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
symbol = _symbol;
|
||||
period = _period;
|
||||
|
||||
//
|
||||
upper = _upper;
|
||||
lower = _lower;
|
||||
|
||||
//
|
||||
from = _from;
|
||||
to = _to;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
|
||||
//
|
||||
upper = 0;
|
||||
lower = 0;
|
||||
|
||||
//
|
||||
from = NULL;
|
||||
to = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(from) &&
|
||||
IsValid(to) &&
|
||||
upper > 0 &&
|
||||
lower > 0 &&
|
||||
to > from
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Unique Tag ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string hash =
|
||||
ToString(upper) + "," +
|
||||
ToString(lower) +
|
||||
ToFormatString(from);
|
||||
hash = ToMD5(hash);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"XRNG_" + symbol + "_" +
|
||||
ToString(period) + "_" +
|
||||
hash
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Tooltip ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTooltip()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"XRNG" + "\n" +
|
||||
symbol + "\n" +
|
||||
ToString(period) + "\n" +
|
||||
ToString(from) + "\n" +
|
||||
ToString(to)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
struct XRangeStructure
|
||||
{
|
||||
//
|
||||
XRange range;
|
||||
|
||||
//
|
||||
XZone demandZones[];
|
||||
XZone supplyZones[];
|
||||
|
||||
//
|
||||
XZone bearishOrderBlocks[];
|
||||
XZone bearishFVGs[];
|
||||
|
||||
//
|
||||
XOHCL swingHighs[];
|
||||
XOHCL resistances[];
|
||||
XOHCL bearishMomentumBars[];
|
||||
XOHCL bearishRejectionBars[];
|
||||
|
||||
//
|
||||
XZone bullishOrderBlocks[];
|
||||
XZone bullishFVGs[];
|
||||
|
||||
//
|
||||
XOHCL supports[];
|
||||
XOHCL swingLows[];
|
||||
XOHCL bullishMomentumBars[];
|
||||
XOHCL bullishRejectionBars[];
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XRangeStructure()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
range.Clean();
|
||||
|
||||
//
|
||||
Clean(supports);
|
||||
Clean(swingLows);
|
||||
Clean(swingHighs);
|
||||
Clean(demandZones);
|
||||
Clean(supplyZones);
|
||||
Clean(bearishFVGs);
|
||||
Clean(resistances);
|
||||
Clean(bullishFVGs);
|
||||
Clean(bearishOrderBlocks);
|
||||
Clean(bullishOrderBlocks);
|
||||
Clean(bearishMomentumBars);
|
||||
Clean(bearishRejectionBars);
|
||||
Clean(bullishMomentumBars);
|
||||
Clean(bullishRejectionBars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = range.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
ArraySize(supports) > 0 ||
|
||||
ArraySize(swingLows) > 0 ||
|
||||
ArraySize(swingHighs) > 0 ||
|
||||
ArraySize(demandZones) > 0 ||
|
||||
ArraySize(supplyZones) > 0 ||
|
||||
ArraySize(bearishFVGs) > 0 ||
|
||||
ArraySize(resistances) > 0 ||
|
||||
ArraySize(bullishFVGs) > 0 ||
|
||||
ArraySize(bearishOrderBlocks) > 0 ||
|
||||
ArraySize(bullishOrderBlocks) > 0 ||
|
||||
ArraySize(bearishMomentumBars) > 0 ||
|
||||
ArraySize(bearishRejectionBars) > 0 ||
|
||||
ArraySize(bullishMomentumBars) > 0 ||
|
||||
ArraySize(bullishRejectionBars) > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Tag ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
string hash = range.GetTag();
|
||||
hash = ToMD5(hash);
|
||||
|
||||
//
|
||||
result = X121SMCMarketStructureToken + "_" + hash;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check a Zone is Between to other Zones ...
|
||||
*
|
||||
* @param source: XZone instance ...
|
||||
* @param upper: XZone instance ...
|
||||
* @param lower: XZone instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsBetween(
|
||||
XZone &source,
|
||||
XRange &range //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = source.IsValid() &&
|
||||
range.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = source.upper <= range.upper &&
|
||||
source.lower >= range.lower;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
bool IsBetween(
|
||||
XOHCL &source,
|
||||
XRange &range //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = source.IsValid() &&
|
||||
range.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = source.high <= range.upper &&
|
||||
source.low >= range.lower;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Binary file not shown.
Reference in New Issue
Block a user