complete XCATBEA and all of it's requirements, such as:
- Expert Class; - Class Based EA; - Signaller(s); - Multi Symbol; - Multi Session; - ...
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,615 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121XCATB
|
||||
// Description: X121XCATB base Expert Advisor ...
|
||||
//
|
||||
// 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 X121XCATB based Expert Advisor"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "X121XCATBEA"
|
||||
|
||||
//
|
||||
// Importts ...
|
||||
#include "../XCATBEA/Classes/xcatbea.expert.class.mq5";
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long eaMagicNumber = 1694056; // 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 Block to Has Propper Swing
|
||||
input bool eaForceOBBarType = false; // Force Order Block to Has InDirectional Bars
|
||||
input int eaMinRequiredOBBar = 0; // Min Required OB Bar
|
||||
input bool eaForceFVGBarType = false; // Force Fair Value Gaps Bars Type
|
||||
input int eaLiquidityLoopback = 0; // Liquidity Detection Loopback
|
||||
input double eaMaxAllowedRange = 0.0; // Max Allowed Order Block Range
|
||||
input double eaMinAllowedRange = 0.0; // Min Allowed Order Block Range
|
||||
input bool eaForceHasFLiquidity = false; // Force Order Block To Has Reversal Liquidity
|
||||
input bool eaForceHasRLiquidity = false; // Force Order Block to Has Following Liquidity
|
||||
input bool eaValidateGapSequence = false; // Validate Fair Value Gaps Bar Sequences
|
||||
input int eaMinAllowedBlockLength = 0; // Min Allowed Block Length
|
||||
input bool eaValidateBlockEdgeBreakout = false; // Validate Order Block Edge Breakeout
|
||||
|
||||
//
|
||||
// Filtering ...
|
||||
input group "Filters";
|
||||
input bool eaFilterBasedOnKI = false; // Filter Based On KI Flats
|
||||
input bool eaFilterBasedOnPV = false; // Filter Based On PV
|
||||
input int eaBosLoopback = 0; // PV Based Filtering BOS Lookup
|
||||
input bool eaFilterBasedOnSar = false; // Filter Based On SAR
|
||||
input bool eaForceSarSwitched = false; // SAR Switched on Sides for Filtering
|
||||
input bool eaForceSarOnBothSide = false; // SAR Check on Both Sides for Filtering
|
||||
input bool eaForceSarHasBreakout = false; // SAR Must Breakout
|
||||
input bool eaForceSarHasReversalSide = false; // SAR Must Has Reversal Direction
|
||||
input bool eaFilterBasedOnRSI = false; // Filter Based On RSI
|
||||
input bool eaForceHasRSITrending = false; // RSI Must Has Trending
|
||||
input bool eaForceHasRSIVPattern = false; // RSI Must Has Pattern
|
||||
input bool eaForceHasRSICrossing = false; // RSI Must Has Crossing Levels
|
||||
input bool eaFilterBasedOnADX = false; // Filter Based On ADX
|
||||
input bool eaForceHasADXTrending = false; // ADX Must Has Trending
|
||||
input bool eaForceHasADXCrossing = false; // ADX Must Has Crossing +DI/-DI
|
||||
input bool eaFilterBasedOnATR = false; // Filter Based On ATR
|
||||
input bool eaForceHasATRTrending = false; // ATR Must Has Trending
|
||||
input bool eaForceHasATRBreakout = false; // ATR Must Has Breakout
|
||||
input bool eaFilterBasedOnTrend = false; // Filter Based On Trend
|
||||
input bool eaForceHasTrendDir = false; // TREND Must Has Following Direction
|
||||
input bool eaForceHasTrendPlace = false; // TREND Place Based Filtering
|
||||
input bool eaForceHasTrendChange = false; // TREND Change Filtering
|
||||
input bool eaForceHasTrendTrending = false; // TREND Must Has Trending
|
||||
input bool eaForceHasTrendRejection = false; // TREND Line Must Rejected
|
||||
input bool eaForceHasTrendLineInside = false; // TREND Line has Inside
|
||||
input bool eaForceHasTrendDirOnBothSide = false; // TREND Must Has Following Direction in Both Side
|
||||
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 eaFilterBasedOnRoundPrice = false; // Filter Based On Round Prices
|
||||
input bool eaFilterBasedOnHKSignalBar = false; // Filter Based On HK Signal Bar
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
input group "Signal";
|
||||
input int eaSignalR2R = 2; // Risk Reward Ratio
|
||||
input double eaSLATRMultiplier = 0; // 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 ...
|
||||
// eaSymbols => comma separated Symbols for Trading, use Default if not Provided ...
|
||||
// eaSessions => (SYDNEY_02:00_14:00),(NY_19:00_23:00)
|
||||
input group "Management";
|
||||
input string eaSymbols = ""; // Allowed Trading Symbols
|
||||
input bool eaAllowGuards = false; // Allow Guards
|
||||
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
input string eaSessions = ""; // Active Sessions
|
||||
input ENUM_XCATBEA_TRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XCATBEA_TRADE_RESTRICATION_NONE; // Restrictions Period
|
||||
input int eaMaxAllowedTPs = 0; // Max Allowed TP(s) in Restrictions Period
|
||||
input int eaMaxAllowedSLs = 0; // Max Allowed SL(s) in Restrictions Period
|
||||
input int eaMaxAllowedTrades = 0; // Max Allowed Trades in Restrictions Period
|
||||
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 = false; // 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
|
||||
|
||||
//
|
||||
// Collector ...
|
||||
input group "Collector";
|
||||
input bool eaSaveTrades = false; // Save Trades
|
||||
input bool eaSaveSignals = false; // Save Signals
|
||||
input bool eaSaveWins = false; // Save Winning Conditions
|
||||
input bool eaSaveLosts = false; // Save Lost Conditions
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
XCXCATBEAExpert *eaExpert;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Preparing Tags ...
|
||||
string eaTag =
|
||||
(IsValid(eaLogSuffix)
|
||||
? eaLogSuffix + "_"
|
||||
: "") +
|
||||
ShortName;
|
||||
|
||||
//
|
||||
// Validate Inputs and Required Parameters
|
||||
// for EA to Works fine ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Timer ...
|
||||
if (!InitTimer())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Configure EA Expert Class ...
|
||||
eaExpert = new XCXCATBEAExpert();
|
||||
|
||||
//
|
||||
// Setting All Inputs to Expert Adviser Class ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
eaExpert.eaMagicNumber = eaMagicNumber;
|
||||
eaExpert.eaSlippage = eaSlippage;
|
||||
eaExpert.eaLogSuffix = eaTag;
|
||||
|
||||
//
|
||||
// Detector ...
|
||||
|
||||
//
|
||||
// Validations ...
|
||||
eaExpert.eaForceHasSwing = eaForceHasSwing;
|
||||
eaExpert.eaForceOBBarType = eaForceOBBarType;
|
||||
eaExpert.eaMinRequiredOBBar = eaMinRequiredOBBar;
|
||||
eaExpert.eaForceFVGBarType = eaForceFVGBarType;
|
||||
eaExpert.eaLiquidityLoopback = eaLiquidityLoopback;
|
||||
eaExpert.eaMaxAllowedRange = eaMaxAllowedRange;
|
||||
eaExpert.eaMinAllowedRange = eaMinAllowedRange;
|
||||
eaExpert.eaForceHasFLiquidity = eaForceHasFLiquidity;
|
||||
eaExpert.eaForceHasRLiquidity = eaForceHasRLiquidity;
|
||||
eaExpert.eaValidateGapSequence = eaValidateGapSequence;
|
||||
eaExpert.eaMinAllowedBlockLength = eaMinAllowedBlockLength;
|
||||
eaExpert.eaValidateBlockEdgeBreakout = eaValidateBlockEdgeBreakout;
|
||||
|
||||
//
|
||||
// Filters ...
|
||||
eaExpert.eaFilterBasedOnKI = eaFilterBasedOnKI;
|
||||
eaExpert.eaFilterBasedOnPV = eaFilterBasedOnPV;
|
||||
eaExpert.eaBosLoopback = eaBosLoopback;
|
||||
eaExpert.eaFilterBasedOnSar = eaFilterBasedOnSar;
|
||||
eaExpert.eaForceSarSwitched = eaForceSarSwitched;
|
||||
eaExpert.eaForceSarOnBothSide = eaForceSarOnBothSide;
|
||||
eaExpert.eaForceSarHasBreakout = eaForceSarHasBreakout;
|
||||
eaExpert.eaForceSarHasReversalSide = eaForceSarHasReversalSide;
|
||||
eaExpert.eaFilterBasedOnRSI = eaFilterBasedOnRSI;
|
||||
eaExpert.eaForceHasRSITrending = eaForceHasRSITrending;
|
||||
eaExpert.eaForceHasRSIVPattern = eaForceHasRSIVPattern;
|
||||
eaExpert.eaForceHasRSICrossing = eaForceHasRSICrossing;
|
||||
eaExpert.eaFilterBasedOnADX = eaFilterBasedOnADX;
|
||||
eaExpert.eaForceHasADXTrending = eaForceHasADXTrending;
|
||||
eaExpert.eaForceHasADXCrossing = eaForceHasADXCrossing;
|
||||
eaExpert.eaFilterBasedOnATR = eaFilterBasedOnATR;
|
||||
eaExpert.eaForceHasATRTrending = eaForceHasATRTrending;
|
||||
eaExpert.eaForceHasATRBreakout = eaForceHasATRBreakout;
|
||||
eaExpert.eaFilterBasedOnTrend = eaFilterBasedOnTrend;
|
||||
eaExpert.eaForceHasTrendDir = eaForceHasTrendDir;
|
||||
eaExpert.eaForceHasTrendPlace = eaForceHasTrendPlace;
|
||||
eaExpert.eaForceHasTrendChange = eaForceHasTrendChange;
|
||||
eaExpert.eaForceHasTrendTrending = eaForceHasTrendTrending;
|
||||
eaExpert.eaForceHasTrendRejection = eaForceHasTrendRejection;
|
||||
eaExpert.eaForceHasTrendLineInside = eaForceHasTrendLineInside;
|
||||
eaExpert.eaForceHasTrendDirOnBothSide = eaForceHasTrendDirOnBothSide;
|
||||
eaExpert.eaFilterBasedOnDelta = eaFilterBasedOnDelta;
|
||||
eaExpert.eaFilterBasedOnVolume = eaFilterBasedOnVolume;
|
||||
eaExpert.eaFilterBasedOnSignalBar = eaFilterBasedOnSignalBar;
|
||||
eaExpert.eaFilterBasedOnRoundPrice = eaFilterBasedOnRoundPrice;
|
||||
eaExpert.eaFilterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar;
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
eaExpert.eaSignalR2R = eaSignalR2R;
|
||||
eaExpert.eaSLATRMultiplier = eaSLATRMultiplier;
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
eaExpert.eaVolumeSelect = eaVolumeSelect;
|
||||
eaExpert.eaStaticVoluem = eaStaticVoluem;
|
||||
eaExpert.eaDynamicVolumeStepBalance = eaDynamicVolumeStepBalance;
|
||||
eaExpert.eaDynamicVolumeStepVolume = eaDynamicVolumeStepVolume;
|
||||
eaExpert.eaConstantRiskBalance = eaConstantRiskBalance;
|
||||
eaExpert.eaConstantPercent = eaConstantPercent;
|
||||
eaExpert.eaConstantBalance = eaConstantBalance;
|
||||
|
||||
//
|
||||
// Management ...
|
||||
eaExpert.eaSymbols = eaSymbols;
|
||||
eaExpert.eaAllowGuards = eaAllowGuards;
|
||||
eaExpert.eaAllowTrade = eaAllowTrade;
|
||||
eaExpert.eaAllowLongs = eaAllowLongs;
|
||||
eaExpert.eaAllowShorts = eaAllowShorts;
|
||||
eaExpert.eaRestrictionsPeriod = eaRestrictionsPeriod;
|
||||
eaExpert.eaMaxAllowedTPs = eaMaxAllowedTPs;
|
||||
eaExpert.eaMaxAllowedSLs = eaMaxAllowedSLs;
|
||||
eaExpert.eaMaxAllowedTrades = eaMaxAllowedTrades;
|
||||
eaExpert.eaMaxAllowedPositions = eaMaxAllowedPositions;
|
||||
eaExpert.eaMaxAllowedSpread = eaMaxAllowedSpread;
|
||||
eaExpert.eaMaxAllowedDrawdownFactor = eaMaxAllowedDrawdownFactor;
|
||||
eaExpert.eaCloseAllOpenTradesAt = eaCloseAllOpenTradesAt;
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
eaExpert.eaEnableAlerts = eaEnableAlerts;
|
||||
eaExpert.eaLogAlerts = eaLogAlerts;
|
||||
eaExpert.eaMailAlerts = eaMailAlerts;
|
||||
eaExpert.eaPushAlerts = eaPushAlerts;
|
||||
eaExpert.eaTerminalAlerts = eaTerminalAlerts;
|
||||
|
||||
//
|
||||
// Reports ...
|
||||
eaExpert.eaReportNewMonths = eaReportNewMonths;
|
||||
eaExpert.eaReportNewWeeks = eaReportNewWeeks;
|
||||
eaExpert.eaReportNewDays = eaReportNewDays;
|
||||
eaExpert.eaReportNewHours = eaReportNewHours;
|
||||
eaExpert.eaReportTrades = eaReportTrades;
|
||||
eaExpert.eaReportSignals = eaReportSignals;
|
||||
eaExpert.eaReportProtector = eaReportProtector;
|
||||
eaExpert.eaReportAfterTradesBalance = eaReportAfterTradesBalance;
|
||||
|
||||
//
|
||||
// Collector ...
|
||||
eaExpert.eaSaveTrades = eaSaveTrades;
|
||||
eaExpert.eaSaveSignals = eaSaveSignals;
|
||||
eaExpert.eaSaveWins = eaSaveWins;
|
||||
eaExpert.eaSaveLosts = eaSaveLosts;
|
||||
|
||||
//
|
||||
// Attach Event Handlers ...
|
||||
eaExpert.OnModifyEventHandler = OnPositionModified;
|
||||
eaExpert.OnDealsChangedEventHandler = OnDealsChanged;
|
||||
eaExpert.OnStopLossEventHandler = OnStopLossTriggered;
|
||||
eaExpert.OnOrdersChangedEventHandler = OnOrdersChanged;
|
||||
eaExpert.OnForceCloseEventHandler = OnPositionForceClosed;
|
||||
eaExpert.OnTakeProfitEventHandler = OnTakeProfitTriggered;
|
||||
eaExpert.OnPositionsChangedEventHandler = OnPositionsChanged;
|
||||
eaExpert.OnPartialCloseEventHandler = OnPositionPartialClosed;
|
||||
eaExpert.OnTradeStateChangedEventHandler = OnTradeStateChanged;
|
||||
|
||||
//
|
||||
bool isInited = eaExpert.HandleOnInit();
|
||||
if (!isInited)
|
||||
{
|
||||
//
|
||||
Print(ShortName + " Initialization Failed ...");
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
Print(ShortName + " Initialization 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
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
eaExpert.HandleOnDeInit();
|
||||
|
||||
//
|
||||
delete eaExpert;
|
||||
ZeroMemory(eaExpert);
|
||||
|
||||
//
|
||||
Print(ShortName + " Deinitialized Successfully ...");
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
eaExpert.HandleOnTick();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade Event ...
|
||||
void OnTrade()
|
||||
{
|
||||
eaExpert.HandleOnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// On Timer ...
|
||||
void OnTimer()
|
||||
{
|
||||
eaExpert.HandleOnTimer();
|
||||
}
|
||||
|
||||
//
|
||||
// Chart Event Handler ...
|
||||
void OnChartEvent(
|
||||
const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam //
|
||||
)
|
||||
{
|
||||
eaExpert.HandleOnChartEvent(id, lparam, dparam, sparam);
|
||||
}
|
||||
|
||||
//
|
||||
// Event Listeners ...
|
||||
|
||||
/**
|
||||
* Handle StopLoss Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaExpert.HandleOnStopLossTriggered(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Take Profit Triggered Positions ...
|
||||
*
|
||||
* @param deal: XDeal instance ...
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaExpert.HandleOnTakeProfitTriggered(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 //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionForceClosed(
|
||||
ticket,
|
||||
position,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Deals Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnDealsChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnDealsChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Orders Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnOrdersChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnOrdersChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Positions Changes ...
|
||||
*
|
||||
* @param count: Integer, Number of Changes ...
|
||||
*/
|
||||
void OnPositionsChanged(int count)
|
||||
{
|
||||
eaExpert.HandleOnPositionsChanged(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Modified ...
|
||||
*
|
||||
* @param ticket: ulong, Position Ticket ...
|
||||
* @param profit: double, Position Profit ...
|
||||
* @param comment: string, Comment ...
|
||||
*/
|
||||
void OnPositionModified(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionModified(
|
||||
ticket,
|
||||
profit,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Position Partial Closed ...
|
||||
*
|
||||
* @param ticket: ulong, Position Ticket ...
|
||||
* @param profit: double, Position Profit ...
|
||||
* @param comment: string, Comment ...
|
||||
*/
|
||||
void OnPositionPartialClosed(
|
||||
const ulong ticket,
|
||||
const double profit,
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
//
|
||||
eaExpert.HandleOnPositionPartialClosed(
|
||||
ticket,
|
||||
profit,
|
||||
comment //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Trade State Changed ...
|
||||
*
|
||||
* @param state: XOnTradeHandlerState instance ...
|
||||
*/
|
||||
void OnTradeStateChanged(const XOnTradeHandlerState &state)
|
||||
{
|
||||
eaExpert.HandleOnTradeStateChanged(state);
|
||||
}
|
||||
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
|
||||
//
|
||||
+152
-234
@@ -20,15 +20,10 @@
|
||||
|
||||
//
|
||||
// Include Common Library ...
|
||||
#include "../Classes/x-saherelm.x-alert.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-trade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-guard.class.mq5"
|
||||
#include "../Classes/x-saherelm.x-volume.class.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../XCATBEA/Classes/xcatbea.signaller.class.mq5"
|
||||
#include "../XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5"
|
||||
#include "../XCATBEA/Libraries/xcatbea.signaller.lib.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCATBEA"
|
||||
@@ -66,6 +61,7 @@ input bool eaValidateBlockEdgeBreakout = false; // Validate Order Block Edge Bre
|
||||
//
|
||||
// Filtering ...
|
||||
input group "Filters";
|
||||
input bool eaFilterBasedOnKI = false; // Filter Based On KI Flats
|
||||
input bool eaFilterBasedOnPV = false; // Filter Based On PV
|
||||
input int eaBosLoopback = 0; // PV Based Filtering BOS Lookup
|
||||
input bool eaFilterBasedOnSar = false; // Filter Based On SAR
|
||||
@@ -94,13 +90,14 @@ input bool eaForceHasTrendDirOnBothSide = false; // TREND Must Has Following Dir
|
||||
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 eaFilterBasedOnRoundPrice = false; // Filter Based On Round Prices
|
||||
input bool eaFilterBasedOnHKSignalBar = false; // Filter Based On HK Signal Bar
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
input group "Signal";
|
||||
input int eaSignalR2R = 2; // Risk Reward Ratio
|
||||
input double eaSLAtrMultiplier = 0; // ATR Multiplier for SL
|
||||
input double eaSLATRMultiplier = 0; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
@@ -117,6 +114,7 @@ input double eaConstantBalance = 0.0; // Constant Ba
|
||||
// Management ...
|
||||
// eaSessions => (SYDNEY_02:00_14:00),(NY_19:00_23:00)
|
||||
input group "Management";
|
||||
input bool eaAllowGuards = false; // Allow Guards
|
||||
input bool eaAllowTrade = true; // Allow Trade on Signals
|
||||
input bool eaAllowLongs = true; // Allow Long Trades
|
||||
input bool eaAllowShorts = true; // Allow Short Trades
|
||||
@@ -165,13 +163,14 @@ input bool eaSaveLosts = false; // Save Lost Conditions
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
string eaTag = "";
|
||||
XCVolume *eaVolume;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCXCATBEASignaller *eaSignallers[];
|
||||
XCXCATBEATradeManager *eaTradeManager;
|
||||
XCAlert *eaAlert; // EA Scope Alert Handler ...
|
||||
XCTrade *eaTrade; // EA Scope Trade Handler ...
|
||||
XCGuard *eaGuard; // EA Scope Guard Handler ...
|
||||
string eaTag = ""; // Specified Alert Tag for EA ...
|
||||
XCVolume *eaVolume; // EA Scope Voluem Handler ...
|
||||
XTimeTracker eaTimeTracker; // EA Scope Time Tracker ...
|
||||
XCXCATBEASignaller *eaSignallers[]; // EA Signallers Collection ...
|
||||
XCXCATBEATradeManager *eaTradeManager; // EA Scope Trade Manager ...
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
@@ -227,6 +226,10 @@ void OnDeinit(const int reason)
|
||||
delete eaTrade;
|
||||
ZeroMemory(eaTrade);
|
||||
|
||||
//
|
||||
delete eaGuard;
|
||||
ZeroMemory(eaGuard);
|
||||
|
||||
//
|
||||
delete eaVolume;
|
||||
ZeroMemory(eaVolume);
|
||||
@@ -234,6 +237,13 @@ void OnDeinit(const int reason)
|
||||
//
|
||||
eaTimeTracker.Clean();
|
||||
|
||||
//
|
||||
Clean(eaSignallers);
|
||||
|
||||
//
|
||||
delete eaTradeManager;
|
||||
ZeroMemory(eaTradeManager);
|
||||
|
||||
//
|
||||
DestroyTimer();
|
||||
}
|
||||
@@ -345,6 +355,7 @@ void OnTick()
|
||||
{
|
||||
//
|
||||
// Handle Guards Firing ...
|
||||
eaGuard.DoGuards(guards);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -354,6 +365,7 @@ void OnTick()
|
||||
{
|
||||
//
|
||||
// Handle Conditions Triggering ...
|
||||
TriggerConditions(conditions);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -362,226 +374,6 @@ void OnTick()
|
||||
//
|
||||
Clean(guards);
|
||||
Clean(conditions);
|
||||
|
||||
// //
|
||||
// eaTB.Clean();
|
||||
// eaSignal.Clean();
|
||||
// eaConditions.Clean();
|
||||
// eaCatbConditions.Clean();
|
||||
|
||||
// //
|
||||
// bool has = false;
|
||||
// int barIndex = 0;
|
||||
// int cBarIndex = 0;
|
||||
|
||||
// //
|
||||
// // Check Bar Processing ...
|
||||
// if (!eaBarTraker.CanProcessBar())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// eaHelper.Check(barIndex);
|
||||
|
||||
// //
|
||||
// // Reading Required Bars ...
|
||||
// XOHCL zBar;
|
||||
// XOHCL cBar;
|
||||
// has = zBar.Init(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// barIndex //
|
||||
// );
|
||||
// has =
|
||||
// has &&
|
||||
// zBar.GetPreviousBar(cBar);
|
||||
// if (!has)
|
||||
// {
|
||||
// //
|
||||
// zBar.Clean();
|
||||
// cBar.Clean();
|
||||
|
||||
// //
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// cBarIndex = barIndex + 1;
|
||||
|
||||
// //
|
||||
// // Update All Required Buffers ...
|
||||
// eaHelper.Update(cBarIndex);
|
||||
|
||||
// //
|
||||
// // Check Trigger Block Detected or Not ...
|
||||
// if (tradeUsingTriggerBlock)
|
||||
// {
|
||||
// //
|
||||
// // Trigger Block Detection ...
|
||||
// has = DetectTriggerBlock1(
|
||||
// eaHelper,
|
||||
// eaBarAnalyser,
|
||||
// eaTB,
|
||||
// eaCatbConditions,
|
||||
// eaValidations,
|
||||
// eaFilters,
|
||||
// barIndex,
|
||||
// 10 // Loopback ...
|
||||
// );
|
||||
|
||||
// //
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// // Wait for Next Bar for anything ...
|
||||
// eaBarTraker.Waits();
|
||||
|
||||
// //
|
||||
// // Prepare Target ...
|
||||
// double targets[];
|
||||
// for (int i = 1; i <= eaSignalR2R; i++)
|
||||
// {
|
||||
// //
|
||||
// Add(
|
||||
// (double)i,
|
||||
// targets //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Calculate SL Additions ...
|
||||
// double iATR = 0;
|
||||
// if (barIndex > 0 &&
|
||||
// barIndex < ArraySize(eaHelper.atrBuffer))
|
||||
// {
|
||||
// iATR = eaHelper.atrBuffer[barIndex];
|
||||
// }
|
||||
// double slAdditional = eaSLAtrMultiplier * iATR;
|
||||
|
||||
// //
|
||||
// // Preparing Signal ...
|
||||
// has = ToSignal(
|
||||
// eaTB.trigger,
|
||||
// eaTB.signal,
|
||||
// targets,
|
||||
// slAdditional //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Draw Trigger Block ...
|
||||
// DrawTriggerBlock(
|
||||
// eaTB,
|
||||
// eaDrawer,
|
||||
// eaObjects,
|
||||
// NULL //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Attach Signal ...
|
||||
// eaSignal = eaTB.signal;
|
||||
|
||||
// //
|
||||
// // Check Signal Type ...
|
||||
// bool isLong = IsLong(eaSignal.type);
|
||||
|
||||
// //
|
||||
// // Update Entry ...
|
||||
// eaSignal.entry = GetEntry(
|
||||
// eaSignal.symbol,
|
||||
// eaSignal.type //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Update Signal Targets ...
|
||||
// UpdateSignalTargets(eaSignal);
|
||||
|
||||
// //
|
||||
// // Handle Volume Management ...
|
||||
// double iVolume = eaVolume.CalculateVolume(eaSignal);
|
||||
// if (iVolume > X_MIN_VOLUME &&
|
||||
// iVolume != eaSignal.volume)
|
||||
// {
|
||||
// eaSignal.volume = iVolume;
|
||||
// }
|
||||
|
||||
// //
|
||||
// eaConditions.sl = eaSignal.sl;
|
||||
// eaConditions.tp = eaSignal.tp;
|
||||
// eaConditions.pivot = eaSignal.sl;
|
||||
// eaConditions.time = eaSignal.time;
|
||||
// eaConditions.reward = eaSignalR2R;
|
||||
// eaConditions.point = eaSignal.entry;
|
||||
// eaConditions.entry = eaSignal.entry;
|
||||
// eaConditions.symbol = eaSignal.symbol;
|
||||
// eaConditions.period = eaSignal.period;
|
||||
// eaConditions.setupTime = eaSignal.time;
|
||||
// eaConditions.triggerTime = eaSignal.time;
|
||||
// eaConditions.decisionZone = eaTB.trigger;
|
||||
// eaConditions.provider = eaSignal.provider;
|
||||
// eaConditions.conditions = eaCatbConditions;
|
||||
// eaConditions.type = ToPositionType(eaSignal.type);
|
||||
// eaConditions.dir =
|
||||
// isLong
|
||||
// ? X_DIRECTION_BULLISH
|
||||
// : X_DIRECTION_BEARISH;
|
||||
// Copy(
|
||||
// eaSignal.targets,
|
||||
// eaConditions.targets //
|
||||
// );
|
||||
// eaSignal.conditions =
|
||||
// eaCatbConditions
|
||||
// .GenerateSummary(
|
||||
// false, // Commons ...
|
||||
// true, // Conditions ...
|
||||
// true, // Scores ...
|
||||
// false // Ignore Falses ...
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Execute Signal ...
|
||||
// has = eaTradeManager.Execute(
|
||||
// eaSignal,
|
||||
// eaConditions //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// eaTB.Clean();
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Trade Using Market Conditions ...
|
||||
// if (tradeUsingMarketConditions1)
|
||||
// {
|
||||
// //
|
||||
// XBoxZone signalZone;
|
||||
// X121XCatbConditions conditions;
|
||||
// has = DetectSignalZone(
|
||||
// eaDrawer,
|
||||
// eaHelper,
|
||||
// eaBarAnalyser,
|
||||
// signalZone,
|
||||
// conditions,
|
||||
// barIndex //
|
||||
// );
|
||||
// if (has)
|
||||
// {
|
||||
// //
|
||||
// // Convert Box to Signal ...
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Cleanup Resources ...
|
||||
|
||||
// //
|
||||
// zBar.Clean();
|
||||
// cBar.Clean();
|
||||
// eaTB.Clean();
|
||||
// eaSignal.Clean();
|
||||
// eaConditions.Clean();
|
||||
// eaCatbConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -835,6 +627,8 @@ void InitRequirements()
|
||||
eaMaxAllowedPositions,
|
||||
eaMaxAllowedDrawdownFactor //
|
||||
);
|
||||
|
||||
//
|
||||
eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
@@ -845,6 +639,7 @@ void InitRequirements()
|
||||
eaTradeManager = new XCXCATBEATradeManager(
|
||||
eaTrade //
|
||||
);
|
||||
|
||||
//
|
||||
eaTradeManager.SetAlertPrefix(eaTag);
|
||||
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
@@ -852,6 +647,7 @@ void InitRequirements()
|
||||
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
eaTradeManager.SaveWins(eaSaveWins);
|
||||
eaTradeManager.SaveLosts(eaSaveLosts);
|
||||
@@ -887,6 +683,20 @@ void InitRequirements()
|
||||
eaMaxAllowedTrades //
|
||||
);
|
||||
|
||||
//
|
||||
// EA Guard Initialization ...
|
||||
eaGuard = new XCGuard(
|
||||
eaTrade //
|
||||
);
|
||||
|
||||
//
|
||||
eaGuard.SetAlertPrefix(eaTag);
|
||||
eaGuard.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaGuard.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaGuard.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaGuard.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaGuard.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// Initializing Sessions ...
|
||||
string sessions[];
|
||||
@@ -974,12 +784,23 @@ void InitRequirements()
|
||||
// Provider Name ...
|
||||
iSignallerInputs.period = _Period;
|
||||
iSignallerInputs.provider = "XTRGB";
|
||||
iSignallerInputs.allowGuards = eaAllowGuards;
|
||||
iSignallerInputs.riskToRewardRatio = eaSignalR2R;
|
||||
iSignallerInputs.allowDraws = IsRunningOnTestMode();
|
||||
iSignallerInputs.slATRMultiplier = eaSLATRMultiplier;
|
||||
|
||||
//
|
||||
// CATB Indicator ...
|
||||
iSignallerInputs.catbInputs.Default();
|
||||
iSignallerInputs.catbInputs.Hide();
|
||||
|
||||
//
|
||||
// Make Available all Requirement Buffers of XCATB indicator ...
|
||||
iSignallerInputs.catbInputs.showPV = true;
|
||||
iSignallerInputs.catbInputs.showKI = true;
|
||||
iSignallerInputs.catbInputs.showATRBand = true;
|
||||
iSignallerInputs.catbInputs.showPVGolden = true;
|
||||
|
||||
//
|
||||
// Trigger Block Validations ...
|
||||
iSignallerInputs.validations.forceHasSwing = eaForceHasSwing;
|
||||
@@ -1036,11 +857,15 @@ void InitRequirements()
|
||||
iSignallerInputs.filters.forceHasTrendDirOnBothSide = eaForceHasTrendDirOnBothSide;
|
||||
|
||||
//
|
||||
iSignallerInputs.filters.filterBasedOnKI = eaFilterBasedOnKI;
|
||||
iSignallerInputs.filters.filterBasedOnDelta = eaFilterBasedOnDelta;
|
||||
iSignallerInputs.filters.filterBasedOnVolume = eaFilterBasedOnVolume;
|
||||
iSignallerInputs.filters.filterBasedOnSignalBar = eaFilterBasedOnSignalBar;
|
||||
iSignallerInputs.filters.filterBasedOnRoundPrice = eaFilterBasedOnRoundPrice;
|
||||
iSignallerInputs.filters.filterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar;
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
// Loop Through Symbols for Signalling Initializing ...
|
||||
int symbolsCount = ArraySize(symbols);
|
||||
@@ -1233,4 +1058,97 @@ void UpdateSignalTargets(XSignal &signal)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Triggered Conditions to Signal and
|
||||
* Execute it ...
|
||||
*/
|
||||
void TriggerConditions(XCATBEAStrategyConditions &conditions[])
|
||||
{
|
||||
//
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
has = HasChild(conditions);
|
||||
if (!has)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
count = ArraySize(conditions);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Retrieve Indexed Conditions ...
|
||||
XCATBEAStrategyConditions iConditions = conditions[i];
|
||||
|
||||
//
|
||||
// Prepare Signal Based on Conditions ...
|
||||
XSignal iSignal;
|
||||
|
||||
//
|
||||
// Check if a Trigger Block Attached and Has Signal ...
|
||||
// use it ...
|
||||
has =
|
||||
iConditions.IsValid() &&
|
||||
iConditions.IsSetuped() &&
|
||||
iConditions.CanTrigger() &&
|
||||
iConditions.triggerBlock.IsValid() &&
|
||||
iConditions.triggerBlock.signal.IsValid();
|
||||
if (has)
|
||||
{
|
||||
iSignal = iConditions.triggerBlock.signal;
|
||||
}
|
||||
|
||||
//
|
||||
// if we Have any other Signalling senarios we can Handle them here ...
|
||||
|
||||
//
|
||||
// Validate Signal ...
|
||||
has = iSignal.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Retrieve Signal Type ...
|
||||
bool isLong = IsLong(iSignal.type);
|
||||
|
||||
//
|
||||
// Update Signal Entry ...
|
||||
iSignal.entry = GetEntry(
|
||||
iSignal.symbol,
|
||||
iSignal.type //
|
||||
);
|
||||
|
||||
//
|
||||
// Update Signal Targets ...
|
||||
UpdateSignalTargets(iSignal);
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = eaVolume.CalculateVolume(iSignal);
|
||||
has = iVolume > X_MIN_VOLUME &&
|
||||
iVolume != iSignal.volume;
|
||||
if (has)
|
||||
{
|
||||
iSignal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
has = eaTradeManager.Execute(
|
||||
iSignal,
|
||||
iConditions //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iSignal.Clean();
|
||||
iConditions.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,11 @@ struct XCATBEASignallerInputs
|
||||
// Pros ...
|
||||
string symbol;
|
||||
string provider;
|
||||
ENUM_TIMEFRAMES period;
|
||||
bool allowDraws;
|
||||
bool allowGuards;
|
||||
ENUM_TIMEFRAMES period;
|
||||
double slATRMultiplier;
|
||||
double riskToRewardRatio;
|
||||
X121XCatbInputs catbInputs;
|
||||
XTriggerBlockFilters filters;
|
||||
XTriggerBlockValidationRules validations;
|
||||
@@ -66,7 +70,11 @@ struct XCATBEASignallerInputs
|
||||
provider = NULL;
|
||||
filters.Clean();
|
||||
catbInputs.Clean();
|
||||
allowDraws = false;
|
||||
validations.Clean();
|
||||
allowGuards = false;
|
||||
slATRMultiplier = 0;
|
||||
riskToRewardRatio = 0;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
@@ -84,7 +92,8 @@ struct XCATBEASignallerInputs
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
IsValid(provider) &&
|
||||
catbInputs.IsValid();
|
||||
catbInputs.IsValid() &&
|
||||
riskToRewardRatio > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -102,8 +111,10 @@ class XCXCATBEASignaller : XCBase
|
||||
// Props ...
|
||||
|
||||
//
|
||||
bool useGuards; // Use Guards or not ...
|
||||
bool allowDraws; // Allow Draws or not ...
|
||||
bool allowDraws; // Allow Draws or not ...
|
||||
bool allowGuards; // Allow Guards or not ...
|
||||
double slATRMultiplier; // SL ATR Multiplier ...
|
||||
double riskToRewardRatio; // Signals R2R ...
|
||||
|
||||
//
|
||||
XBarTracker barTraker; // Bar Tracker ...
|
||||
@@ -112,6 +123,9 @@ class XCXCATBEASignaller : XCBase
|
||||
XCXCATBEAPOIDrawer *drawer; // POI Drawer ...
|
||||
XCXCATBEAPOIDetector *detector; // POI Detector ...
|
||||
|
||||
//
|
||||
XBoxZone unavailableZones[]; // Un Available Zones ...
|
||||
|
||||
//
|
||||
XCATBEAStrategyConditions mConditions;
|
||||
XCATBEAStrategyConditions mConditionsCollection[];
|
||||
@@ -151,6 +165,12 @@ class XCXCATBEASignaller : XCBase
|
||||
return period;
|
||||
}
|
||||
|
||||
//
|
||||
double GetR2R()
|
||||
{
|
||||
return riskToRewardRatio;
|
||||
}
|
||||
|
||||
//
|
||||
// Tick Analyser ...
|
||||
|
||||
@@ -168,6 +188,7 @@ class XCXCATBEASignaller : XCBase
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
int barIndex = 0;
|
||||
@@ -212,6 +233,18 @@ class XCXCATBEASignaller : XCBase
|
||||
}
|
||||
|
||||
//
|
||||
// When Setup Invalidated
|
||||
// Signaller Clean Conditions ...
|
||||
if (!has &&
|
||||
!iConditions.IsValid())
|
||||
{
|
||||
//
|
||||
selectedIDX = i;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
iConditions.Clean();
|
||||
}
|
||||
|
||||
@@ -232,6 +265,21 @@ class XCXCATBEASignaller : XCBase
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Check Selected Index for Invalid Conditions ...
|
||||
if (IsValidIndex(selectedIDX))
|
||||
{
|
||||
//
|
||||
// Remove Invalidated Conditions ...
|
||||
ArrayRemove(
|
||||
mConditionsCollection,
|
||||
selectedIDX,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resource ...
|
||||
conditions.Clean();
|
||||
}
|
||||
}
|
||||
@@ -242,11 +290,38 @@ class XCXCATBEASignaller : XCBase
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Initialize Bar ...
|
||||
bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect POI(s) ...
|
||||
detector.Detect(barIndex);
|
||||
|
||||
//
|
||||
// Validate POI(s) ...
|
||||
detector.Validate(
|
||||
unavailableZones,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
// Draw POI(s) ...
|
||||
if (allowDraws)
|
||||
{
|
||||
drawer.Draw(bar.time);
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Setups ...
|
||||
has = DetectSignalSetup(barIndex);
|
||||
if (has) {
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
barTraker.Waits();
|
||||
|
||||
@@ -256,6 +331,10 @@ class XCXCATBEASignaller : XCBase
|
||||
//
|
||||
mConditions.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
bar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -312,6 +391,40 @@ class XCXCATBEASignaller : XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(conditions.dir);
|
||||
bool isBearish = IsBearish(conditions.dir);
|
||||
|
||||
//
|
||||
// Validate Direction of Setuped Conditions ...
|
||||
result =
|
||||
result &&
|
||||
(isBullish ||
|
||||
isBearish);
|
||||
|
||||
//
|
||||
// Do Triggering Senario based on Trigger Block ...
|
||||
if (result &&
|
||||
conditions.triggerBlock.IsValid())
|
||||
{
|
||||
//
|
||||
// Complete Conditions Here ...
|
||||
}
|
||||
|
||||
//
|
||||
// Do Other Validation Senarios ...
|
||||
|
||||
//
|
||||
result = conditions.IsValid() &&
|
||||
conditions.IsSetuped() &&
|
||||
conditions.CanTrigger();
|
||||
|
||||
//
|
||||
// Check Setup Age or Setup Validations here ...
|
||||
if (!result)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
@@ -339,14 +452,32 @@ class XCXCATBEASignaller : XCBase
|
||||
|
||||
//
|
||||
// Normalize Args ...
|
||||
Clean(guards);
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
|
||||
//
|
||||
result = allowGuards &&
|
||||
HasChild(positions);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
|
||||
//
|
||||
result = HasChild(guards);
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
Clean(guards);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -372,6 +503,9 @@ class XCXCATBEASignaller : XCBase
|
||||
symbol = inputs.symbol;
|
||||
period = inputs.period;
|
||||
provider = inputs.provider;
|
||||
allowGuards = inputs.allowGuards;
|
||||
slATRMultiplier = inputs.slATRMultiplier;
|
||||
riskToRewardRatio = inputs.riskToRewardRatio;
|
||||
|
||||
//
|
||||
// Initialize Bar Tracker ...
|
||||
@@ -540,6 +674,8 @@ class XCXCATBEASignaller : XCBase
|
||||
|
||||
//
|
||||
// Configure ...
|
||||
detector.detectPeakPivots = true;
|
||||
detector.detectValePivots = true;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -552,6 +688,35 @@ class XCXCATBEASignaller : XCBase
|
||||
|
||||
//
|
||||
// Configure ...
|
||||
drawer.drawPeakPivots = true;
|
||||
drawer.drawValePivots = true;
|
||||
|
||||
//
|
||||
XCATBPivotStyle iStyle;
|
||||
|
||||
//
|
||||
// Styling Peak Pivot ...
|
||||
iStyle.width = 1;
|
||||
iStyle.clr = clrMagenta;
|
||||
iStyle.style = STYLE_SOLID;
|
||||
|
||||
//
|
||||
drawer.peakPivotStyle = iStyle;
|
||||
|
||||
//
|
||||
// Styling Vale Pivot ...
|
||||
iStyle.width = 1;
|
||||
iStyle.clr = clrAqua;
|
||||
iStyle.style = STYLE_SOLID;
|
||||
|
||||
//
|
||||
drawer.valePivotStyle = iStyle;
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
iStyle.Clean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
struct XCAPivotStyle
|
||||
struct XCATBPivotStyle
|
||||
{
|
||||
//
|
||||
// Properties ...
|
||||
@@ -37,7 +37,7 @@ struct XCAPivotStyle
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XCAPivotStyle()
|
||||
XCATBPivotStyle()
|
||||
{
|
||||
Default();
|
||||
}
|
||||
@@ -89,12 +89,12 @@ class XCXCATBEAPOIDrawer : public XCBase
|
||||
// Styling ...
|
||||
|
||||
//
|
||||
XCAPivotStyle defaultBullishStyle;
|
||||
XCAPivotStyle defaultBearishStyle;
|
||||
XCATBPivotStyle defaultBullishStyle;
|
||||
XCATBPivotStyle defaultBearishStyle;
|
||||
|
||||
//
|
||||
XCAPivotStyle peakPivotStyle;
|
||||
XCAPivotStyle valePivotStyle;
|
||||
XCATBPivotStyle peakPivotStyle;
|
||||
XCATBPivotStyle valePivotStyle;
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
@@ -250,7 +250,7 @@ class XCXCATBEAPOIDrawer : public XCBase
|
||||
{
|
||||
//
|
||||
// Select Styling Config ...
|
||||
XCAPivotStyle style;
|
||||
XCATBPivotStyle style;
|
||||
|
||||
//
|
||||
if (box.IsBullish())
|
||||
@@ -569,7 +569,7 @@ class XCXCATBEAPOIDrawer : public XCBase
|
||||
//
|
||||
void ApplyPivotStyle(
|
||||
XCBoxObject *&object,
|
||||
XCAPivotStyle &style //
|
||||
XCATBPivotStyle &style //
|
||||
)
|
||||
{
|
||||
//
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
|
||||
#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../Libraries/xcatbea.lib.mq5"
|
||||
|
||||
//
|
||||
// Definiions ...
|
||||
@@ -194,6 +193,7 @@ struct XTriggerBlockFilters
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
bool filterBasedOnKI; // Filter Based On KI Flats ...
|
||||
bool filterBasedOnPV; // Filter Based On PV ...
|
||||
bool filterBasedOnSar; // Filter Based On SAR ...
|
||||
bool filterBasedOnRSI; // Filter Based On RSI ...
|
||||
@@ -203,6 +203,7 @@ struct XTriggerBlockFilters
|
||||
bool filterBasedOnDelta; // Filter Based On Delta ...
|
||||
bool filterBasedOnVolume; // Filter Based On Volume ...
|
||||
bool filterBasedOnSignalBar; // Filter Based on Signal Bar ...
|
||||
bool filterBasedOnRoundPrice; // Filter Based On Round Prices ...
|
||||
bool filterBasedOnHKSignalBar; // Filter Based On HK Signal Bar ...
|
||||
|
||||
//
|
||||
@@ -251,6 +252,7 @@ struct XTriggerBlockFilters
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
filterBasedOnKI = false;
|
||||
filterBasedOnPV = false;
|
||||
filterBasedOnSar = false;
|
||||
filterBasedOnRSI = false;
|
||||
@@ -260,6 +262,7 @@ struct XTriggerBlockFilters
|
||||
filterBasedOnDelta = false;
|
||||
filterBasedOnVolume = false;
|
||||
filterBasedOnSignalBar = false;
|
||||
filterBasedOnRoundPrice = false;
|
||||
filterBasedOnHKSignalBar = false;
|
||||
|
||||
//
|
||||
@@ -1158,6 +1161,34 @@ bool FilterTriggerBlock(
|
||||
//
|
||||
// Checking Conditions ...
|
||||
|
||||
//
|
||||
// Filter Based KI ...
|
||||
if (result &&
|
||||
filters.filterBasedOnKI)
|
||||
{
|
||||
//
|
||||
int count = 0;
|
||||
toIDX = triggerBlock.ob.ToIndex();
|
||||
fromIDX = triggerBlock.ob.FromIndex();
|
||||
double lKI = conditions.kiBuffer[zIDX];
|
||||
for (int i = toIDX; i < fromIDX; i++)
|
||||
{
|
||||
//
|
||||
double iKI = helper.GetKI(i);
|
||||
if (iKI == lKI)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = count >= 3;
|
||||
}
|
||||
|
||||
//
|
||||
// Filter Based On PV ...
|
||||
if (result &&
|
||||
@@ -2230,6 +2261,15 @@ bool FilterTriggerBlock(
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Filter Based Round Price ...
|
||||
if (result &&
|
||||
filters.filterBasedOnRoundPrice)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-poi.lib.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-trade.lib.mq5"
|
||||
#include "../../Helpers/x-saherelm.x121.xcatb.helper.mq5"
|
||||
#include "../Libraries/xcatbea.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
@@ -60,8 +61,9 @@ struct XCATBEAStrategyConditions
|
||||
datetime triggerTime;
|
||||
|
||||
//
|
||||
XBoxZone pivotZone;
|
||||
ENUM_X_DIRECTION dir;
|
||||
XBoxZone decisionZone;
|
||||
XTriggerBlock triggerBlock;
|
||||
ENUM_X_POSITION_TYPES type;
|
||||
X121XCatbConditions conditions;
|
||||
|
||||
@@ -102,8 +104,9 @@ struct XCATBEAStrategyConditions
|
||||
Clean(targets);
|
||||
|
||||
//
|
||||
pivotZone.Clean();
|
||||
conditions.Clean();
|
||||
decisionZone.Clean();
|
||||
triggerBlock.Clean();
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user