last preparation of XCATB indicator, helper and tester EA ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,316 @@
|
|||||||
|
//
|
||||||
|
// Market ...
|
||||||
|
ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Short Period
|
||||||
|
ENUM_TIMEFRAMES scPeriod = NULL; // Short Period
|
||||||
|
ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Medium Period
|
||||||
|
ENUM_TIMEFRAMES mcPeriod = NULL; // Medium Period
|
||||||
|
ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Long Period
|
||||||
|
ENUM_TIMEFRAMES lcPeriod = NULL; // Long Period
|
||||||
|
ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Hind Period
|
||||||
|
ENUM_TIMEFRAMES hcPeriod = NULL; // Hind Period
|
||||||
|
ENUM_X_MARKET_CYCLES appliedCycle = X_MARKET_CYCLE_HIND; // Applied Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ...
|
||||||
|
int signalR2R = 4; // Risk Reward Ratio
|
||||||
|
bool drawSignals = true; // Draw Signal
|
||||||
|
double slAtrMultiplier = 1.0; // ATR Multiplier for SL
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validating ...
|
||||||
|
bool forceHasSwing = false; // Force Blocks to Have Swing
|
||||||
|
bool forceObBarType = false; // Force Block Has Reversal Bar
|
||||||
|
bool forceOBFVGBarType = false; // Force FVG Has Same Bars
|
||||||
|
bool forceHasFLiquidity = false; // Force Blocks to Have Following Liquidity
|
||||||
|
bool forceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity
|
||||||
|
bool validateGapSequence = false; // Validate Block's Gap Sequence
|
||||||
|
bool validateBlockEdgeBreakout = false; // Validate Block's Edge Breakout
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filtering ...
|
||||||
|
bool filterBasedOnPV = false; // Filter Based on Peak and Vale
|
||||||
|
bool filterBasedOnSar = false; // Filter Based on Sar
|
||||||
|
bool filterBasedOnRSI = false; // Filter Based on RSI
|
||||||
|
bool filterBasedOnADX = false; // Filter Based on ADX
|
||||||
|
bool filterBasedOnATR = false; // Filter Based on ATR
|
||||||
|
bool filterBasedOnTrend = false; // Filter Based on Trend
|
||||||
|
bool filterBasedOnDelta = false; // Filter Based on Delta
|
||||||
|
bool filterBasedOnVolume = false; // Filter Based on Volume
|
||||||
|
bool filterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||||
|
bool filterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar
|
||||||
|
|
||||||
|
//
|
||||||
|
// Alert ...
|
||||||
|
string mAlertPrefix = ""; // Alert Prefix
|
||||||
|
bool _logAlerts = true; // Log Alerts
|
||||||
|
bool _pushAlerts = false; // Push Alerts
|
||||||
|
bool _mailAlerts = false; // Mail Alerts
|
||||||
|
bool _terminalAlerts = true; // Terminal Alerts
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
bool showBars = true; // Show Bars
|
||||||
|
bool showPV = false; // Show PV
|
||||||
|
bool showPVGolden = false; // Show PV Golden
|
||||||
|
bool showSar = false; // Show Sar
|
||||||
|
bool showTrend = false; // Show Trend
|
||||||
|
bool showATRBand = false; // Show ATR Band
|
||||||
|
bool showTrendBars = false; // Show Trend Bars
|
||||||
|
bool showSignalBars = false; // Show Signal Bars
|
||||||
|
bool showHKSignalBars = false; // Show Hiken Ashi Signal Bars
|
||||||
|
|
||||||
|
//
|
||||||
|
int startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//
|
||||||
|
// Market ...
|
||||||
|
ENUM_X_PERIOD_METHOD scMethod; // How to Find Short Period
|
||||||
|
ENUM_TIMEFRAMES scPeriod; // Short Period
|
||||||
|
ENUM_X_PERIOD_METHOD mcMethod; // How to Find Medium Period
|
||||||
|
ENUM_TIMEFRAMES mcPeriod; // Medium Period
|
||||||
|
ENUM_X_PERIOD_METHOD lcMethod; // How to Find Long Period
|
||||||
|
ENUM_TIMEFRAMES lcPeriod; // Long Period
|
||||||
|
ENUM_X_PERIOD_METHOD hcMethod; // How to Find Hind Period
|
||||||
|
ENUM_TIMEFRAMES hcPeriod; // Hind Period
|
||||||
|
ENUM_X_MARKET_CYCLES appliedCycle; // Applied Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ...
|
||||||
|
int signalR2R; // Risk Reward Ratio
|
||||||
|
bool drawSignals; // Draw Signal
|
||||||
|
double slAtrMultiplier; // ATR Multiplier for SL
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validating ...
|
||||||
|
bool forceHasSwing; // Force Blocks to Have Swing
|
||||||
|
bool forceObBarType; // Force Block Has Reversal Bar
|
||||||
|
bool forceOBFVGBarType; // Force FVG Has Same Bars
|
||||||
|
bool forceHasFLiquidity; // Force Blocks to Have Following Liquidity
|
||||||
|
bool forceHasRLiquidity; // Force Blocks to Have Reversal Liquidity
|
||||||
|
bool validateGapSequence; // Validate Block's Gap Sequence
|
||||||
|
bool validateBlockEdgeBreakout; // Validate Block's Edge Breakout
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filtering ...
|
||||||
|
bool filterBasedOnPV; // Filter Based on Peak and Vale
|
||||||
|
bool filterBasedOnSar; // Filter Based on Sar
|
||||||
|
bool filterBasedOnRSI; // Filter Based on RSI
|
||||||
|
bool filterBasedOnADX; // Filter Based on ADX
|
||||||
|
bool filterBasedOnATR; // Filter Based on ATR
|
||||||
|
bool filterBasedOnTrend; // Filter Based on Trend
|
||||||
|
bool filterBasedOnDelta; // Filter Based on Delta
|
||||||
|
bool filterBasedOnVolume; // Filter Based on Volume
|
||||||
|
bool filterBasedOnSignalBar; // Filter Based on Signal Bar
|
||||||
|
bool filterBasedOnHKSignalBar; // Filter Based on Hiken Ashi Signal Bar
|
||||||
|
|
||||||
|
//
|
||||||
|
// Alert ...
|
||||||
|
string alertPrefix; // Alert Prefix
|
||||||
|
bool logAlerts; // Log Alerts
|
||||||
|
bool pushAlerts; // Push Alerts
|
||||||
|
bool mailAlerts; // Mail Alerts
|
||||||
|
bool terminalAlerts; // Terminal Alerts
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
bool showBars; // Show Bars
|
||||||
|
bool showPV; // Show PV
|
||||||
|
bool showPVGolden; // Show PV Golden
|
||||||
|
bool showSar; // Show Sar
|
||||||
|
bool showTrend; // Show Trend
|
||||||
|
bool showATRBand; // Show ATR Band
|
||||||
|
bool showTrendBars; // Show Trend Bars
|
||||||
|
bool showSignalBars; // Show Signal Bars
|
||||||
|
bool showHKSignalBars; // Show Hiken Ashi Signal Bars
|
||||||
|
|
||||||
|
//
|
||||||
|
int startCalculationForLastBars; // Calculate Last n Bars
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//
|
||||||
|
// Market ...
|
||||||
|
scMethod = X_PERIOD_AUTO; // How to Find Short Period
|
||||||
|
scPeriod = NULL; // Short Period
|
||||||
|
mcMethod = X_PERIOD_AUTO; // How to Find Medium Period
|
||||||
|
mcPeriod = NULL; // Medium Period
|
||||||
|
lcMethod = X_PERIOD_AUTO; // How to Find Long Period
|
||||||
|
lcPeriod = NULL; // Long Period
|
||||||
|
hcMethod = X_PERIOD_AUTO; // How to Find Hind Period
|
||||||
|
hcPeriod = NULL; // Hind Period
|
||||||
|
appliedCycle = X_MARKET_CYCLE_HIND; // Applied Cycle
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ...
|
||||||
|
signalR2R = 4; // Risk Reward Ratio
|
||||||
|
drawSignals = true; // Draw Signal
|
||||||
|
slAtrMultiplier = 1.0; // ATR Multiplier for SL
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validating ...
|
||||||
|
forceHasSwing = false; // Force Blocks to Have Swing
|
||||||
|
forceObBarType = false; // Force Block Has Reversal Bar
|
||||||
|
forceOBFVGBarType = false; // Force FVG Has Same Bars
|
||||||
|
forceHasFLiquidity = false; // Force Blocks to Have Following Liquidity
|
||||||
|
forceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity
|
||||||
|
validateGapSequence = false; // Validate Block's Gap Sequence
|
||||||
|
validateBlockEdgeBreakout = false; // Validate Block's Edge Breakout
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filtering ...
|
||||||
|
filterBasedOnPV = false; // Filter Based on Peak and Vale
|
||||||
|
filterBasedOnSar = false; // Filter Based on Sar
|
||||||
|
filterBasedOnRSI = false; // Filter Based on RSI
|
||||||
|
filterBasedOnADX = false; // Filter Based on ADX
|
||||||
|
filterBasedOnATR = false; // Filter Based on ATR
|
||||||
|
filterBasedOnTrend = false; // Filter Based on Trend
|
||||||
|
filterBasedOnDelta = false; // Filter Based on Delta
|
||||||
|
filterBasedOnVolume = false; // Filter Based on Volume
|
||||||
|
filterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||||
|
filterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar
|
||||||
|
|
||||||
|
//
|
||||||
|
// Alert ...
|
||||||
|
mAlertPrefix = ""; // Alert Prefix
|
||||||
|
_logAlerts = true; // Log Alerts
|
||||||
|
_pushAlerts = false; // Push Alerts
|
||||||
|
_mailAlerts = false; // Mail Alerts
|
||||||
|
_terminalAlerts = true; // Terminal Alerts
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation ...
|
||||||
|
showBars = true; // Show Bars
|
||||||
|
showPV = false; // Show PV
|
||||||
|
showPVGolden = false; // Show PV Golden
|
||||||
|
showSar = false; // Show Sar
|
||||||
|
showTrend = false; // Show Trend
|
||||||
|
showATRBand = false; // Show ATR Band
|
||||||
|
showTrendBars = false; // Show Trend Bars
|
||||||
|
showSignalBars = false; // Show Signal Bars
|
||||||
|
showHKSignalBars = false; // Show Hiken Ashi Signal Bars
|
||||||
|
|
||||||
|
//
|
||||||
|
startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
X121_XCATB_SAR_LINE
|
||||||
|
sarBuffer
|
||||||
|
|
||||||
|
X121_XCATB_SAR_STATE_LINE
|
||||||
|
sarStateBuffer
|
||||||
|
|
||||||
|
X121_XCATB_PEAK_LINE
|
||||||
|
peakBuffer
|
||||||
|
|
||||||
|
X121_XCATB_VALE_LINE
|
||||||
|
valeBuffer
|
||||||
|
|
||||||
|
X121_XCATB_PEAK_GOLDEN_LINE
|
||||||
|
peakGoldenBuffer
|
||||||
|
|
||||||
|
X121_XCATB_VALE_GOLDEN_LINE
|
||||||
|
valeGoldenBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ATR_BAND_UPPER_LINE
|
||||||
|
atrUpperBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ATR_BAND_LOWER_LINE
|
||||||
|
atrLowerBuffer
|
||||||
|
|
||||||
|
X121_XCATB_TREND_LINE
|
||||||
|
trendBuffer
|
||||||
|
|
||||||
|
X121_XCATB_TREND_STATE_LINE
|
||||||
|
trendStateBuffer
|
||||||
|
|
||||||
|
X121_XCATB_SBAR_O_LINE
|
||||||
|
sBarOpenSBuffer
|
||||||
|
|
||||||
|
X121_XCATB_SBAR_C_LINE
|
||||||
|
sBarCloseBuffer
|
||||||
|
|
||||||
|
X121_XCATB_HK_SBAR_O_LINE
|
||||||
|
hkSBarOpenBuffer
|
||||||
|
|
||||||
|
X121_XCATB_HK_SBAR_C_LINE
|
||||||
|
hkSBarCloseBuffer
|
||||||
|
|
||||||
|
X121_XCATB_S_HH_LINE
|
||||||
|
sHHBuffer
|
||||||
|
|
||||||
|
X121_XCATB_S_LL_LINE
|
||||||
|
sLLBuffer
|
||||||
|
|
||||||
|
X121_XCATB_M_HH_LINE
|
||||||
|
mHHBuffer
|
||||||
|
|
||||||
|
X121_XCATB_M_LL_LINE
|
||||||
|
mLLBuffer
|
||||||
|
|
||||||
|
X121_XCATB_L_HH_LINE
|
||||||
|
lHHBuffer
|
||||||
|
|
||||||
|
X121_XCATB_L_LL_LINE
|
||||||
|
lLLBuffer
|
||||||
|
|
||||||
|
X121_XCATB_H_HH_LINE
|
||||||
|
hHHBuffer
|
||||||
|
|
||||||
|
X121_XCATB_H_LL_LINE
|
||||||
|
hLLBuffer
|
||||||
|
|
||||||
|
X121_XCATB_RSI_LINE
|
||||||
|
rsiBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ADX_LINE
|
||||||
|
adxBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ADXP_LINE
|
||||||
|
adxpBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ADXN_LINE
|
||||||
|
adxnBuffer
|
||||||
|
|
||||||
|
X121_XCATB_DELTA_LINE
|
||||||
|
deltaBuffer
|
||||||
|
|
||||||
|
X121_XCATB_DELTA_SIGNAL_LINE
|
||||||
|
deltaSignalBuffer
|
||||||
|
|
||||||
|
X121_XCATB_VOLUME_BULLISH_LINE
|
||||||
|
bullishVolumeBuffer
|
||||||
|
|
||||||
|
X121_XCATB_VOLUME_BEARISH_LINE
|
||||||
|
bearishVolumeBuffer
|
||||||
|
|
||||||
|
X121_XCATB_VOLUME_VOLUME_BULLISH_SIGNAL_LINE
|
||||||
|
bullishVolumeSignalBuffer
|
||||||
|
|
||||||
|
X121_XCATB_VOLUME_VOLUME_BEARISH_SIGNAL_LINE
|
||||||
|
bearishVolumeSignalBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ATR_LINE
|
||||||
|
atrBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ATR_BAND_RAW_UPPER_LINE
|
||||||
|
atrUpperBuffer
|
||||||
|
|
||||||
|
X121_XCATB_ATR_BAND_RAW_LOWER_LINE
|
||||||
|
atrLowerBuffer
|
||||||
|
|
||||||
|
X121_XCATB_HK_BAR_O_LINE
|
||||||
|
hkOpenBuffer
|
||||||
|
|
||||||
|
X121_XCATB_HK_BAR_H_LINE
|
||||||
|
hkHighBuffer
|
||||||
|
|
||||||
|
X121_XCATB_HK_BAR_L_LINE
|
||||||
|
hkLowBuffer
|
||||||
|
|
||||||
|
X121_XCATB_HK_BAR_C_LINE
|
||||||
|
hkCloseBuffer
|
||||||
|
|
||||||
@@ -0,0 +1,836 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center XCATB MQL5 Expert Advisor
|
||||||
|
// -------------------------------------------------
|
||||||
|
// Name: XCAEA
|
||||||
|
// Description: an Exper Advisor which used XCATB
|
||||||
|
//
|
||||||
|
// 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 "EA based on X121 XCATB indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// Include Common Library ...
|
||||||
|
#include "../Classes/x-saherelm.x-alert.class.mq5"
|
||||||
|
#include "../Classes/x-saherelm.x-trade.class.mq5"
|
||||||
|
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||||
|
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||||
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
|
#include "../Libraries/x-saherelm.x121.xcatb.lib.mq5"
|
||||||
|
#include "../XCAEA/Classes/xcaea.x-trade.manager.class.mq5"
|
||||||
|
|
||||||
|
//
|
||||||
|
#define ShortName "XCATBEA"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Common ...
|
||||||
|
input group "Common";
|
||||||
|
input long eaMagicNumber = 78692110; // Magic Number
|
||||||
|
input int eaSlippage = 10; // Slippgae
|
||||||
|
input string eaLogSuffix = ""; // Log Suffix
|
||||||
|
|
||||||
|
//
|
||||||
|
// Detector ...
|
||||||
|
input group "Detector";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validating ...
|
||||||
|
input group "Validations";
|
||||||
|
input bool eaForceHasSwing = false; // Force Blocks to Have Swing
|
||||||
|
input bool eaForceObBarType = false; // Force Block Has Reversal Bar
|
||||||
|
input bool eaForceOBFVGBarType = false; // Force FVG Has Same Bars
|
||||||
|
input bool eaForceHasFLiquidity = false; // Force Blocks to Have Following Liquidity
|
||||||
|
input bool eaForceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity
|
||||||
|
input bool eaValidateGapSequence = false; // Validate Block's Gap Sequence
|
||||||
|
input bool eaValidateBlockEdgeBreakout = false; // Validate Block's Edge Breakout
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filtering ...
|
||||||
|
input group "Filters";
|
||||||
|
input bool eaFilterBasedOnPV = false; // Filter Based on Peak and Vale
|
||||||
|
input bool eaFilterBasedOnSar = false; // Filter Based on Sar
|
||||||
|
input bool eaFilterBasedOnRSI = false; // Filter Based on RSI
|
||||||
|
input bool eaFilterBasedOnADX = false; // Filter Based on ADX
|
||||||
|
input bool eaFilterBasedOnATR = false; // Filter Based on ATR
|
||||||
|
input bool eaFilterBasedOnTrend = false; // Filter Based on Trend
|
||||||
|
input bool eaFilterBasedOnDelta = false; // Filter Based on Delta
|
||||||
|
input bool eaFilterBasedOnVolume = false; // Filter Based on Volume
|
||||||
|
input bool eaFilterBasedOnSignalBar = false; // Filter Based on Signal Bar
|
||||||
|
input bool eaFilterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ...
|
||||||
|
input group "Signal";
|
||||||
|
input int eaSignalR2R = 3; // Risk Reward Ratio
|
||||||
|
input double eaSLAtrMultiplier = 0.5; // ATR Multiplier for SL
|
||||||
|
|
||||||
|
//
|
||||||
|
// Volume ...
|
||||||
|
input group "Volume";
|
||||||
|
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_EQUITY; // Volume Applying Type
|
||||||
|
input double eaStaticVoluem = 0.0; // Static Volume
|
||||||
|
input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
|
||||||
|
input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
|
||||||
|
input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
|
||||||
|
input double eaConstantPercent = 0.5; // Constant Percent of Balance Per Trade
|
||||||
|
input double eaConstantBalance = 0.0; // Constant Balance for Calculations
|
||||||
|
|
||||||
|
//
|
||||||
|
// Management ...
|
||||||
|
input group "Management";
|
||||||
|
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||||
|
input bool eaAllowLongs = true; // Allow Long Trades
|
||||||
|
input bool eaAllowShorts = true; // Allow Short Trades
|
||||||
|
input ENUM_XCAEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCAEA_TRADE_RESTRICATION_NONE; // Trade Restrictions Period
|
||||||
|
input int eaMaxAllowedTPs = 0; // Max Allowed TP(s) per Day
|
||||||
|
input int eaMaxAllowedSLs = 0; // Max Allowed SL(s) per Day
|
||||||
|
input int eaMaxAllowedTrades = 0; // Max Allowed Trades per Day
|
||||||
|
input int eaMaxAllowedPositions = 5; // Max Allowed Same Time Trades
|
||||||
|
input double eaMaxAllowedSpread = 25; // Max Allowed Spread For Trade
|
||||||
|
input double eaMaxAllowedDrawdownFactor = 0.3; // Max Allowed DrawDown for Trade
|
||||||
|
input string eaCloseAllOpenTradesAt = ""; // Close All Open Trades per Day At Specified Time
|
||||||
|
|
||||||
|
//
|
||||||
|
// Alert ...
|
||||||
|
// Here we Provider All Requirements for
|
||||||
|
// Configuring Alert Provider ...
|
||||||
|
input group "Alert";
|
||||||
|
input bool eaEnableAlerts = true; // Enable Alerts
|
||||||
|
input bool eaLogAlerts = true; // Log Alerts
|
||||||
|
input bool eaMailAlerts = false; // Mail Alerts
|
||||||
|
input bool eaPushAlerts = true; // Push Alerts
|
||||||
|
input bool eaTerminalAlerts = true; // Terminal Alerts
|
||||||
|
|
||||||
|
//
|
||||||
|
// Time Report ...
|
||||||
|
input group "Reports";
|
||||||
|
input bool eaReportNewMonths = false; // Report New Month
|
||||||
|
input bool eaReportNewWeeks = false; // Report New Weeks
|
||||||
|
input bool eaReportNewDays = true; // Report New Days
|
||||||
|
input bool eaReportNewHours = false; // Report New Hours
|
||||||
|
input bool eaReportTrades = true; // Report Trades
|
||||||
|
input bool eaReportSignals = true; // Report Signals
|
||||||
|
input bool eaReportProtector = true; // Report Protector Actions
|
||||||
|
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
|
||||||
|
|
||||||
|
//
|
||||||
|
// Variables ...
|
||||||
|
|
||||||
|
//
|
||||||
|
XCAlert *eaAlert;
|
||||||
|
XCTrade *eaTrade;
|
||||||
|
XSignal eaSignal;
|
||||||
|
XCVolume *eaVolume;
|
||||||
|
X121XCatbInputs eaInputs;
|
||||||
|
XCX121XCatbHelper *eaHelper;
|
||||||
|
XBarTracker eaBarTraker;
|
||||||
|
XTimeTracker eaTimeTracker;
|
||||||
|
XCXCAEATradeManager *eaTradeManager;
|
||||||
|
XCAEAStrategyConditions eaConditions;
|
||||||
|
|
||||||
|
//
|
||||||
|
XTriggerBlock eaTB;
|
||||||
|
|
||||||
|
//
|
||||||
|
CArrayObj *eaObjects;
|
||||||
|
|
||||||
|
//
|
||||||
|
string eaTag = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Event Handlers ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate Inputs and Required Parameters
|
||||||
|
// for EA to Works fine ...
|
||||||
|
if (!ValidateInputs())
|
||||||
|
{
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initial Requirements ...
|
||||||
|
InitRequirements();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize Volume Manger ...
|
||||||
|
if (!InitVolume())
|
||||||
|
{
|
||||||
|
return INIT_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
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
|
||||||
|
|
||||||
|
//
|
||||||
|
// eaObjects.Clear();
|
||||||
|
|
||||||
|
//
|
||||||
|
delete eaHelper;
|
||||||
|
ZeroMemory(eaHelper);
|
||||||
|
|
||||||
|
//
|
||||||
|
delete eaAlert;
|
||||||
|
ZeroMemory(eaAlert);
|
||||||
|
|
||||||
|
//
|
||||||
|
delete eaTrade;
|
||||||
|
ZeroMemory(eaTrade);
|
||||||
|
|
||||||
|
//
|
||||||
|
delete eaVolume;
|
||||||
|
ZeroMemory(eaVolume);
|
||||||
|
|
||||||
|
//
|
||||||
|
eaSignal.Clean();
|
||||||
|
eaBarTraker.Clean();
|
||||||
|
eaConditions.Clean();
|
||||||
|
eaTimeTracker.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
DestroyTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// On Tick Handler ...
|
||||||
|
void OnTick()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
HandleTimeReport();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Position Management / Protections ...
|
||||||
|
eaTradeManager.Manage();
|
||||||
|
|
||||||
|
//
|
||||||
|
eaSignal.Clean();
|
||||||
|
eaConditions.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Bar Processing ...
|
||||||
|
if (!eaBarTraker.CanProcessBar())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool has = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Bars ...
|
||||||
|
XOHCL zBar;
|
||||||
|
XOHCL cBar;
|
||||||
|
has = zBar.Init(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
0 //
|
||||||
|
);
|
||||||
|
has =
|
||||||
|
has &&
|
||||||
|
zBar.GetPreviousBar(cBar);
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
zBar.Clean();
|
||||||
|
cBar.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double bid = GetBid(zBar.symbol);
|
||||||
|
|
||||||
|
//
|
||||||
|
XTriggerBlock iTB;
|
||||||
|
has = GetNewestX121TriggerBlock(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
iTB //
|
||||||
|
);
|
||||||
|
if (has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Newest TB is Newer Than Exists TB ...
|
||||||
|
bool canPass =
|
||||||
|
!eaTB.IsValid()
|
||||||
|
? true
|
||||||
|
: iTB.ToIndex() < eaTB.ToIndex();
|
||||||
|
if (canPass)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
eaTB = iTB;
|
||||||
|
eaSignal = iTB.signal;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare eaConditions if Reuqired ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
has = eaSignal.IsValid();
|
||||||
|
if (has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Here we ensure which has a New Signal and must
|
||||||
|
// prepare and Execute it ...
|
||||||
|
Print("new Signal Detected ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// eaTB.Clean();
|
||||||
|
zBar.Clean();
|
||||||
|
cBar.Clean();
|
||||||
|
eaSignal.Clean();
|
||||||
|
eaConditions.Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle On Trade Event ...
|
||||||
|
void OnTrade()
|
||||||
|
{
|
||||||
|
eaTrade.HandleOnTrade();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// On Timer ...
|
||||||
|
void OnTimer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Chart Event Handler ...
|
||||||
|
void OnChartEvent(
|
||||||
|
const int id,
|
||||||
|
const long &lparam,
|
||||||
|
const double &dparam,
|
||||||
|
const string &sparam //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Event Listeners ...
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle StopLoss Triggered Positions ...
|
||||||
|
*
|
||||||
|
* @param deal: XDeal instance ...
|
||||||
|
*/
|
||||||
|
void OnStopLossTriggered(const XDeal &deal)
|
||||||
|
{
|
||||||
|
eaTradeManager.HandleSL(deal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Take Profit Triggered Positions ...
|
||||||
|
*
|
||||||
|
* @param deal: XDeal instance ...
|
||||||
|
*/
|
||||||
|
void OnTakeProfitTriggered(const XDeal &deal)
|
||||||
|
{
|
||||||
|
eaTradeManager.HandleTP(deal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Force Close a Position ...
|
||||||
|
*
|
||||||
|
* @param ticket: ULONG ...
|
||||||
|
* @param position: XPosition instance ...
|
||||||
|
* @param comment: string ...
|
||||||
|
*/
|
||||||
|
void OnPositionForceClosed(
|
||||||
|
const ulong ticket,
|
||||||
|
const XPosition &position,
|
||||||
|
const string comment //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
eaTradeManager.HandleForceClose(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Position Partially Closed Event ...
|
||||||
|
*
|
||||||
|
* @param ticket: ULONG ...
|
||||||
|
* @param profit: double ...
|
||||||
|
* @param comment: string ...
|
||||||
|
*/
|
||||||
|
void OnPositionPartiallyClosed(
|
||||||
|
const ulong ticket,
|
||||||
|
const double profit,
|
||||||
|
const string comment //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
eaTradeManager.HandlePartiallyClosed(
|
||||||
|
ticket,
|
||||||
|
profit,
|
||||||
|
comment //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Deals Changes ...
|
||||||
|
*
|
||||||
|
* @param count: Integer, Number of Changes ...
|
||||||
|
*/
|
||||||
|
void OnDealsChanged(int count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Orders Changes ...
|
||||||
|
*
|
||||||
|
* @param count: Integer, Number of Changes ...
|
||||||
|
*/
|
||||||
|
void OnOrdersChanged(int count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Positions Changes ...
|
||||||
|
*
|
||||||
|
* @param count: Integer, Number of Changes ...
|
||||||
|
*/
|
||||||
|
void OnPositionsChanged(int count)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Custom Functions ...
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate all Inputs of Expert Adviser ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool ValidateInputs()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
string errMessage = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isCommonValid = (
|
||||||
|
//
|
||||||
|
eaSlippage > 0 &&
|
||||||
|
eaMagicNumber > 0
|
||||||
|
//
|
||||||
|
);
|
||||||
|
if (!isCommonValid)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
errMessage += "common configurations error;" + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
// Common ...
|
||||||
|
isCommonValid &&
|
||||||
|
//
|
||||||
|
// Otere ...
|
||||||
|
true
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Since here Logger not Initiallized, we Use Raw Print Command ...
|
||||||
|
Print(ShortName + " Errors: \n", errMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize Timer ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool InitTimer()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: Initialize Timer if necessary ...
|
||||||
|
// result = EventSetTimer(1);
|
||||||
|
// result = EventSetMillisecondTimer(100);
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy Timer ...
|
||||||
|
*/
|
||||||
|
void DestroyTimer()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// TODO: Use This ...
|
||||||
|
// EventKillTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial Volume Manager Class Based on Given Configuration ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool InitVolume()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
eaVolume = new XCVolume();
|
||||||
|
|
||||||
|
//
|
||||||
|
result = eaVolume.Init(
|
||||||
|
eaVolumeSelect,
|
||||||
|
eaStaticVoluem,
|
||||||
|
eaDynamicVolumeStepBalance,
|
||||||
|
eaDynamicVolumeStepVolume,
|
||||||
|
eaConstantRiskBalance,
|
||||||
|
eaConstantPercent,
|
||||||
|
eaConstantBalance //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial Requirements of EA ...
|
||||||
|
*/
|
||||||
|
void InitRequirements()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Preparing Tags ...
|
||||||
|
eaTag =
|
||||||
|
(IsValid(eaLogSuffix)
|
||||||
|
? eaLogSuffix + "_"
|
||||||
|
: "") +
|
||||||
|
ShortName;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initial Bar Tracker ...
|
||||||
|
eaBarTraker.Init(
|
||||||
|
_Symbol,
|
||||||
|
_Period //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Objects ...
|
||||||
|
eaObjects = new CArrayObj();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Configure XCA ...
|
||||||
|
eaInputs.Default();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hide all Visible Buffers ...
|
||||||
|
eaInputs.Hide();
|
||||||
|
|
||||||
|
//
|
||||||
|
// we Can make Show all requirements here ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ...
|
||||||
|
eaInputs.signalR2R = eaSignalR2R;
|
||||||
|
eaInputs.slAtrMultiplier = eaSLAtrMultiplier;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Validators ...
|
||||||
|
eaInputs.forceHasSwing = eaForceHasSwing;
|
||||||
|
eaInputs.forceObBarType = eaForceObBarType;
|
||||||
|
eaInputs.forceOBFVGBarType = eaForceOBFVGBarType;
|
||||||
|
eaInputs.forceHasFLiquidity = eaForceHasFLiquidity;
|
||||||
|
eaInputs.forceHasRLiquidity = eaForceHasRLiquidity;
|
||||||
|
eaInputs.validateGapSequence = eaValidateGapSequence;
|
||||||
|
eaInputs.validateBlockEdgeBreakout = eaValidateBlockEdgeBreakout;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Filters ...
|
||||||
|
eaInputs.filterBasedOnPV = eaFilterBasedOnPV;
|
||||||
|
eaInputs.filterBasedOnSar = eaFilterBasedOnSar;
|
||||||
|
eaInputs.filterBasedOnRSI = eaFilterBasedOnRSI;
|
||||||
|
eaInputs.filterBasedOnADX = eaFilterBasedOnADX;
|
||||||
|
eaInputs.filterBasedOnATR = eaFilterBasedOnATR;
|
||||||
|
eaInputs.filterBasedOnTrend = eaFilterBasedOnTrend;
|
||||||
|
eaInputs.filterBasedOnDelta = eaFilterBasedOnDelta;
|
||||||
|
eaInputs.filterBasedOnVolume = eaFilterBasedOnVolume;
|
||||||
|
eaInputs.filterBasedOnSignalBar = eaFilterBasedOnSignalBar;
|
||||||
|
eaInputs.filterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Alerts ...
|
||||||
|
eaInputs.alertPrefix = eaTag;
|
||||||
|
eaInputs.logAlerts = eaLogAlerts;
|
||||||
|
eaInputs.pushAlerts = eaMailAlerts;
|
||||||
|
eaInputs.mailAlerts = eaPushAlerts;
|
||||||
|
eaInputs.terminalAlerts = eaTerminalAlerts;
|
||||||
|
|
||||||
|
//
|
||||||
|
eaHelper = new XCX121XCatbHelper();
|
||||||
|
bool isInited = eaHelper.Init(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
eaInputs //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// EA Alert ...
|
||||||
|
eaAlert = new XCAlert(
|
||||||
|
eaTag,
|
||||||
|
eaEnableAlerts,
|
||||||
|
eaLogAlerts,
|
||||||
|
eaTerminalAlerts,
|
||||||
|
eaMailAlerts,
|
||||||
|
eaPushAlerts //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// EA Trade ...
|
||||||
|
eaTrade = new XCTrade(
|
||||||
|
eaSlippage,
|
||||||
|
eaMagicNumber,
|
||||||
|
eaMaxAllowedSpread,
|
||||||
|
eaMaxAllowedPositions,
|
||||||
|
eaMaxAllowedDrawdownFactor //
|
||||||
|
);
|
||||||
|
eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||||
|
eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||||
|
eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||||
|
eaTrade.AddOnPartialClosePositionEventHandler(OnPositionPartiallyClosed);
|
||||||
|
|
||||||
|
//
|
||||||
|
// EA Trae Manager ...
|
||||||
|
eaTradeManager = new XCXCAEATradeManager(
|
||||||
|
eaTrade //
|
||||||
|
);
|
||||||
|
eaTradeManager.SaveTrades(true);
|
||||||
|
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||||
|
eaTradeManager.SetAlertPrefix(eaTag);
|
||||||
|
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||||
|
eaTradeManager.SetAlertMailAlerts(eaMailAlerts);
|
||||||
|
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||||
|
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Trade Reports ...
|
||||||
|
eaTradeManager
|
||||||
|
.SetTradeReports(
|
||||||
|
eaReportTrades,
|
||||||
|
eaReportSignals,
|
||||||
|
eaReportProtector,
|
||||||
|
eaReportAfterTradesBalance //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Trade Permissions ...
|
||||||
|
eaTradeManager
|
||||||
|
.SetTradePermissions(
|
||||||
|
eaAllowTrade,
|
||||||
|
eaAllowLongs,
|
||||||
|
eaAllowShorts //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Trade Restrictions ...
|
||||||
|
eaTradeManager
|
||||||
|
.SetTradeRestrictions(
|
||||||
|
eaRestrictionsPeriod,
|
||||||
|
eaMaxAllowedTPs,
|
||||||
|
eaMaxAllowedSLs,
|
||||||
|
eaMaxAllowedTrades //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handling Time Reporting ...
|
||||||
|
*/
|
||||||
|
void HandleTimeReport()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Monthly Report ....
|
||||||
|
if (eaReportNewMonths &&
|
||||||
|
eaTimeTracker.IsNewMonth())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string msg = "New Month ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
eaAlert.Alert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Weekly Report ....
|
||||||
|
if (eaReportNewWeeks &&
|
||||||
|
eaTimeTracker.IsNewWeek())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string msg = "New Week ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
eaAlert.Alert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Daily Report ....
|
||||||
|
if (eaReportNewDays &&
|
||||||
|
eaTimeTracker.IsNewDay())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string msg = "New Day ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
eaAlert.Alert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Hourly Report ....
|
||||||
|
if (eaReportNewHours &&
|
||||||
|
eaTimeTracker.IsNewHour())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string msg = "New Hour ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
eaAlert.Alert(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Apply Signal Targets ...
|
||||||
|
void ApplySignalTargets(XSignal &signal)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool has = signal.IsValid();
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Clean Signal Targets ...
|
||||||
|
Clean(signal.targets);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Requirements ...
|
||||||
|
double r2r = 1;
|
||||||
|
// maxAllowedR2R > 0
|
||||||
|
// ? maxAllowedR2R
|
||||||
|
// : 1;
|
||||||
|
double risk = signal.GetRisk();
|
||||||
|
double reward = risk * r2r;
|
||||||
|
|
||||||
|
//
|
||||||
|
double isLong = IsLong(signal.type);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handling Signal TP ...
|
||||||
|
signal.tp =
|
||||||
|
isLong
|
||||||
|
? signal.entry + reward
|
||||||
|
: signal.entry - reward;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to Apply Money Management ...
|
||||||
|
|
||||||
|
//
|
||||||
|
if (r2r <= 1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// XTarget iTarget;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Partial Close 0.5 of Position on Reward 1 ...
|
||||||
|
// reward = risk * 1;
|
||||||
|
// iTarget.target =
|
||||||
|
// isLong
|
||||||
|
// ? signal.entry + reward
|
||||||
|
// : signal.entry - reward;
|
||||||
|
// iTarget.volumeMultiplier = 0.5;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// AddRef(iTarget, signal.targets);
|
||||||
|
// iTarget.Clean();
|
||||||
|
|
||||||
|
// //
|
||||||
|
// if (r2r <= 2)
|
||||||
|
// {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
// Making Loop ...
|
||||||
|
// for (int i = 2; i < ((int)r2r - 1); i++)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// iTarget.Clean();
|
||||||
|
|
||||||
|
// //
|
||||||
|
// reward = i * risk;
|
||||||
|
// iTarget.target =
|
||||||
|
// isLong
|
||||||
|
// ? signal.entry + reward
|
||||||
|
// : signal.entry - reward;
|
||||||
|
// iTarget.volumeMultiplier = 1 / (r2r - 2);
|
||||||
|
|
||||||
|
// //
|
||||||
|
// AddRef(iTarget, signal.targets);
|
||||||
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
// Sort Targets ...
|
||||||
|
ENUM_X_DIRECTION sortingDir =
|
||||||
|
isLong
|
||||||
|
? X_DIRECTION_BULLISH
|
||||||
|
: X_DIRECTION_BEARISH;
|
||||||
|
ApplySortOnTargets(
|
||||||
|
sortingDir,
|
||||||
|
signal.targets //
|
||||||
|
);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,65 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Helper Class Library
|
|
||||||
// ----------------------------------------------
|
|
||||||
// Name: XCX121XCTBHelper
|
|
||||||
// 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.x-helper.class.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Definitions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
enum ENUM_X121_XTB_BUFFERS
|
|
||||||
{
|
|
||||||
X121_XTB_TREND_LINE = 0,
|
|
||||||
X121_XTB_SAR_LINE = 2,
|
|
||||||
X121_XTB_SBAR_O_LINE = 4,
|
|
||||||
X121_XTB_SBAR_H_LINE = 5,
|
|
||||||
X121_XTB_SBAR_L_LINE = 6,
|
|
||||||
X121_XTB_SBAR_C_LINE = 7,
|
|
||||||
X121_XTB_HK_BAR_O_LINE = 9,
|
|
||||||
X121_XTB_HK_BAR_H_LINE = 10,
|
|
||||||
X121_XTB_HK_BAR_L_LINE = 11,
|
|
||||||
X121_XTB_HK_BAR_C_LINE = 12,
|
|
||||||
X121_XTB_HK_SBAR_O_LINE = 14,
|
|
||||||
X121_XTB_HK_SBAR_H_LINE = 15,
|
|
||||||
X121_XTB_HK_SBAR_L_LINE = 16,
|
|
||||||
X121_XTB_HK_SBAR_C_LINE = 17,
|
|
||||||
X121_XTB_ATR_BAND_UPPER_LINE = 19,
|
|
||||||
X121_XTB_ATR_BAND_LOWER_LINE = 20,
|
|
||||||
X121_XTB_TREND_STATE_LINE = 21,
|
|
||||||
X121_XTB_SAR_STATE_LINE = 22,
|
|
||||||
X121_XTB_RSI_LINE = 23,
|
|
||||||
X121_XTB_ADX_LINE = 24,
|
|
||||||
X121_XTB_ADXP_LINE = 25,
|
|
||||||
X121_XTB_ADXN_LINE = 26,
|
|
||||||
X121_XTB_DELTA_LINE = 27,
|
|
||||||
X121_XTB_DELTA_SIGNAL_LINE = 28,
|
|
||||||
X121_XTB_VOLUME_BULLISH_LINE = 29,
|
|
||||||
X121_XTB_VOLUME_BEARISH_LINE = 30,
|
|
||||||
X121_XTB_VOLUME_VOLUME_BULLISH_SIGNAL_LINE = 31,
|
|
||||||
X121_XTB_VOLUME_VOLUME_BEARISH_SIGNAL_LINE = 32,
|
|
||||||
X121_XTB_ATR_LINE = 33,
|
|
||||||
X121_XTB_ATR_BAND_RAW_UPPER_LINE = 34,
|
|
||||||
X121_XTB_ATR_BAND_RAW_LOWER_LINE = 35,
|
|
||||||
};
|
|
||||||
@@ -29,58 +29,6 @@
|
|||||||
//
|
//
|
||||||
// Definiions ...
|
// Definiions ...
|
||||||
|
|
||||||
//
|
|
||||||
enum ENUM_XCAEA_TIGGER_TYPE
|
|
||||||
{
|
|
||||||
XCA_TRIGGER_NONE, // None
|
|
||||||
XCA_TRIGGER_BULL, // TriggerBull
|
|
||||||
XCA_TRIGGER_BEAR, // TriggerBear
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
bool IsValid(ENUM_XCAEA_TIGGER_TYPE value)
|
|
||||||
{
|
|
||||||
return value != XCA_TRIGGER_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string ToString(ENUM_XCAEA_TIGGER_TYPE value)
|
|
||||||
{
|
|
||||||
return EnumToString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_XCAEA_TIGGER_TYPE GetType(string type)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ENUM_XCAEA_TIGGER_TYPE result = XCA_TRIGGER_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isTriggerBull = type == ToString(XCA_TRIGGER_BULL);
|
|
||||||
bool isTriggerBear = type == ToString(XCA_TRIGGER_BEAR);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (isTriggerBull)
|
|
||||||
{
|
|
||||||
result = XCA_TRIGGER_BULL;
|
|
||||||
}
|
|
||||||
else if (isTriggerBear)
|
|
||||||
{
|
|
||||||
result = XCA_TRIGGER_BEAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_X_DIRECTION GetDirection(ENUM_XCAEA_TIGGER_TYPE value)
|
|
||||||
{
|
|
||||||
return value == XCA_TRIGGER_BULL
|
|
||||||
? X_DIRECTION_BULLISH
|
|
||||||
: X_DIRECTION_BEARISH;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
struct XTriggerBlock
|
struct XTriggerBlock
|
||||||
{
|
{
|
||||||
@@ -200,9 +148,70 @@ int CountX121TriggerBlocks()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void CleanX121TriggerBlocks()
|
void CleanX121TriggerBlocks(int maxAllowed = 0)
|
||||||
{
|
{
|
||||||
Clean(mX121TriggerBlocks) l
|
//
|
||||||
|
if (maxAllowed <= 0)
|
||||||
|
{
|
||||||
|
Clean(mX121TriggerBlocks);
|
||||||
|
}
|
||||||
|
else if (maxAllowed > 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
CleanupArray(
|
||||||
|
mX121TriggerBlocks,
|
||||||
|
maxAllowed //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetNewestX121TriggerBlock(
|
||||||
|
string forSymbol,
|
||||||
|
ENUM_TIMEFRAMES forPeriod,
|
||||||
|
XTriggerBlock &tb //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
tb.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
IsValid(forSymbol) &&
|
||||||
|
IsValid(forPeriod) &&
|
||||||
|
HasX121TriggerBlocks();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop Through Trigger Blocks to Find Filtered Newest ...
|
||||||
|
int count = CountX121TriggerBlocks();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool canSet = !tb.IsValid()
|
||||||
|
? true
|
||||||
|
: tb.ToIndex() < mX121TriggerBlocks[i].ToIndex();
|
||||||
|
if (canSet)
|
||||||
|
{
|
||||||
|
tb = mX121TriggerBlocks[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = tb.IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
tb.Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -365,7 +374,9 @@ bool DetectTriggerBlock(
|
|||||||
// Clone Trigger Block ...
|
// Clone Trigger Block ...
|
||||||
if (has)
|
if (has)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
tb.trigger = tb.ob;
|
tb.trigger = tb.ob;
|
||||||
|
tb.trigger.type = "XTRGB";
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -713,29 +724,29 @@ bool DetectTriggerBlock(
|
|||||||
double rsiTrend = (_rsiOBLevel + _rsiOSLevel) / 2;
|
double rsiTrend = (_rsiOBLevel + _rsiOSLevel) / 2;
|
||||||
|
|
||||||
//
|
//
|
||||||
double iRSI = rsiBuffer[barIndex];
|
double iRSI = _rsiBuffer[barIndex];
|
||||||
double iPRSI = rsiBuffer[barIndex + 1];
|
double iPRSI = _rsiBuffer[barIndex + 1];
|
||||||
double iP2RSI = rsiBuffer[barIndex + 2];
|
double iP2RSI = _rsiBuffer[barIndex + 2];
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isRSICrossedOverOS =
|
bool isRSICrossedOverOS =
|
||||||
iRSI > rsiOSLevel &&
|
iRSI > _rsiOSLevel &&
|
||||||
iPRSI <= rsiOSLevel;
|
iPRSI <= _rsiOSLevel;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isRSICrossedUnderOB =
|
bool isRSICrossedUnderOB =
|
||||||
iRSI < rsiOBLevel &&
|
iRSI < _rsiOBLevel &&
|
||||||
iPRSI >= rsiOBLevel;
|
iPRSI >= _rsiOBLevel;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isPRSICrossedOverOS =
|
bool isPRSICrossedOverOS =
|
||||||
iPRSI > rsiOSLevel &&
|
iPRSI > _rsiOSLevel &&
|
||||||
iP2RSI <= rsiOSLevel;
|
iP2RSI <= _rsiOSLevel;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isPRSICrossedUnderOB =
|
bool isPRSICrossedUnderOB =
|
||||||
iPRSI < rsiOBLevel &&
|
iPRSI < _rsiOBLevel &&
|
||||||
iP2RSI >= rsiOBLevel;
|
iP2RSI >= _rsiOBLevel;
|
||||||
|
|
||||||
//
|
//
|
||||||
has =
|
has =
|
||||||
@@ -754,36 +765,36 @@ bool DetectTriggerBlock(
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// ADX ...
|
// ADX ...
|
||||||
double iADX = adxBuffer[barIndex];
|
double iADX = _adxBuffer[barIndex];
|
||||||
double iPADX = adxBuffer[barIndex + 1];
|
double iPADX = _adxBuffer[barIndex + 1];
|
||||||
double iP2ADX = adxBuffer[barIndex + 2];
|
double iP2ADX = _adxBuffer[barIndex + 2];
|
||||||
|
|
||||||
//
|
//
|
||||||
// ADX +DI ...
|
// ADX +DI ...
|
||||||
double iADXP = adxpBuffer[barIndex];
|
double iADXP = _adxpBuffer[barIndex];
|
||||||
double iPADXP = adxpBuffer[barIndex + 1];
|
double iPADXP = _adxpBuffer[barIndex + 1];
|
||||||
double iP2ADXP = adxpBuffer[barIndex + 2];
|
double iP2ADXP = _adxpBuffer[barIndex + 2];
|
||||||
|
|
||||||
//
|
//
|
||||||
// ADX -DI ...
|
// ADX -DI ...
|
||||||
double iADXN = adxnBuffer[barIndex];
|
double iADXN = _adxnBuffer[barIndex];
|
||||||
double iPADXN = adxnBuffer[barIndex + 1];
|
double iPADXN = _adxnBuffer[barIndex + 1];
|
||||||
double iP2ADXN = adxnBuffer[barIndex + 2];
|
double iP2ADXN = _adxnBuffer[barIndex + 2];
|
||||||
|
|
||||||
//
|
//
|
||||||
// Preparing Conditions ...
|
// Preparing Conditions ...
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isADXBullish = iADX > adxThreshold;
|
bool isADXBullish = iADX > _adxThreshold;
|
||||||
bool isADXBearish = iADX < adxThreshold;
|
bool isADXBearish = iADX < _adxThreshold;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isPADXBullish = iPADX > adxThreshold;
|
bool isPADXBullish = iPADX > _adxThreshold;
|
||||||
bool isPADXBearish = iPADX < adxThreshold;
|
bool isPADXBearish = iPADX < _adxThreshold;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isP2ADXBullish = iP2ADX > adxThreshold;
|
bool isP2ADXBullish = iP2ADX > _adxThreshold;
|
||||||
bool isP2ADXBearish = iP2ADX < adxThreshold;
|
bool isP2ADXBearish = iP2ADX < _adxThreshold;
|
||||||
|
|
||||||
//
|
//
|
||||||
bool isADXSwitchedToBullish =
|
bool isADXSwitchedToBullish =
|
||||||
@@ -854,12 +865,12 @@ bool DetectTriggerBlock(
|
|||||||
double trends[];
|
double trends[];
|
||||||
int toIDX = tb.ToIndex();
|
int toIDX = tb.ToIndex();
|
||||||
int fromIDX = tb.FromIndex();
|
int fromIDX = tb.FromIndex();
|
||||||
double iTrend = trendBuffer[toIDX];
|
double iTrend = _trendBuffer[toIDX];
|
||||||
for (int i = toIDX; i <= fromIDX; i++)
|
for (int i = toIDX; i <= fromIDX; i++)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
Add(
|
Add(
|
||||||
trendBuffer[i],
|
_trendBuffer[i],
|
||||||
trends //
|
trends //
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1077,7 +1088,7 @@ bool DetectTriggerBlock(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
double iATR = atrBuffer[barIndex];
|
double iATR = _atrBuffer[barIndex];
|
||||||
double slAdditional = _slAtrMultiplier * iATR;
|
double slAdditional = _slAtrMultiplier * iATR;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -1089,10 +1100,13 @@ bool DetectTriggerBlock(
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
Add(
|
// Add Trigger Block to Collection
|
||||||
|
// and Cleanup Unuseds ...
|
||||||
|
AddRef(
|
||||||
tb,
|
tb,
|
||||||
mX121TriggerBlocks //
|
mX121TriggerBlocks //
|
||||||
);
|
);
|
||||||
|
CleanX121TriggerBlocks(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||||
#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||||
#include "../Helpers/xcaea.helper.mq5"
|
#include "../Helpers/xcaea.helper.mq5"
|
||||||
#include "../Libraries/xcaea.trigger.block.lib.mq5"
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Definitions ...
|
// Definitions ...
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user