last preparation of XCATB indicator, helper and tester EA ...
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XCZone MQL5 Expert Advisor
|
||||
// SaherElm IT Center XCATB MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XCAEA
|
||||
// Description: an Exper Advisor which used XCZone
|
||||
// Description: an Exper Advisor which used XCATB
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
@@ -15,7 +15,7 @@
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "EA based on X121 XCZone indicators"
|
||||
#property description "EA based on X121 XCATB indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
@@ -23,13 +23,13 @@
|
||||
#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"
|
||||
#include "../XCAEA/Helpers/xcaea.helper.mq5"
|
||||
#include "../XCAEA/Libraries/xcaea.trigger.block.lib.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XCZONEEA"
|
||||
#define ShortName "XCATBEA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
@@ -46,34 +46,35 @@ input string eaLogSuffix = ""; // Log Suffix
|
||||
input group "Detector";
|
||||
|
||||
//
|
||||
// Ranges ...
|
||||
input double eaMaxAllowedRange = 0.0; // Maximum Allowed Range
|
||||
input int eaMinAllowedBlockEdgeLength = 7; // Minimum Required Block Edge Length
|
||||
|
||||
//
|
||||
// Validation ...
|
||||
input bool eaForceFVGBarType = true; // Force FVG to Has Same Type of Bars
|
||||
input bool eaForceHasSwingBar = true; // Force Has Propper Swing
|
||||
input bool eaForceOBOppositBar = true; // Force OB to Start by Opposit Bars
|
||||
input bool eaForceHasLiquidity = false; // Force Has Following Liquidity Zone
|
||||
input bool eaForceGapBarBreakout = true; // Force FVG's Gap Bar to Breakeout OB Edge Side
|
||||
input bool eaForceHasReversalLiquidity = true; // Force Has Reversal Liquidity Zone
|
||||
// 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 bool eaFilterBasedOnSar = true; // Filter Trigger Block Based on Sar
|
||||
input bool eaFilterBasedOnRSI = true; // Filter Trigger Block Based on RSI
|
||||
input bool eaFilterBasedOnADX = true; // Filter Trigger Block Based on ADX
|
||||
input bool eaFilterBasedOnTrend = true; // Filter Trigger Block Based on Trend
|
||||
input bool eaFilterBasedOnScores = true; // Filter Trigger Block Based on Scores
|
||||
input bool eaFilterBasedOnVolumes = true; // Filter Trigger Block Based on Volumes
|
||||
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
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input double maxAllowedR2R = 2; // Max Allowed R2R
|
||||
input double eaSLAdditionalPoint = 0.0; // Additional SL in Point
|
||||
input double eaSLATRMultiplier = 0.0; // Additional SL using ATR Multiplier
|
||||
// Signal ...
|
||||
input group "Signal";
|
||||
input int eaSignalR2R = 3; // Risk Reward Ratio
|
||||
input double eaSLAtrMultiplier = 0.5; // ATR Multiplier for SL
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
@@ -106,11 +107,11 @@ input string eaCloseAllOpenTradesAt = "";
|
||||
// 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 = false; // Push Alerts
|
||||
input bool eaTerminalAlerts = false; // Terminal Alerts
|
||||
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 ...
|
||||
@@ -132,8 +133,8 @@ XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
XSignal eaSignal;
|
||||
XCVolume *eaVolume;
|
||||
XCAEAInputs eaInputs;
|
||||
XCXCAEAHelper *eaHelper;
|
||||
X121XCatbInputs eaInputs;
|
||||
XCX121XCatbHelper *eaHelper;
|
||||
XBarTracker eaBarTraker;
|
||||
XTimeTracker eaTimeTracker;
|
||||
XCXCAEATradeManager *eaTradeManager;
|
||||
@@ -141,9 +142,6 @@ XCAEAStrategyConditions eaConditions;
|
||||
|
||||
//
|
||||
XTriggerBlock eaTB;
|
||||
XBoxZone eaUpperRange;
|
||||
XBoxZone eaLowerRange;
|
||||
XCAEATriggerBlockConfiguration eaTBConfig;
|
||||
|
||||
//
|
||||
CArrayObj *eaObjects;
|
||||
@@ -170,10 +168,6 @@ int OnInit()
|
||||
// Initial Requirements ...
|
||||
InitRequirements();
|
||||
|
||||
//
|
||||
// Configure Detector ...
|
||||
ConfigureDetector();
|
||||
|
||||
//
|
||||
// Initialize Volume Manger ...
|
||||
if (!InitVolume())
|
||||
@@ -222,7 +216,6 @@ void OnDeinit(const int reason)
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaTBConfig.Clean();
|
||||
eaBarTraker.Clean();
|
||||
eaConditions.Clean();
|
||||
eaTimeTracker.Clean();
|
||||
@@ -282,264 +275,43 @@ void OnTick()
|
||||
double bid = GetBid(zBar.symbol);
|
||||
|
||||
//
|
||||
// Detect Range Blocks ...
|
||||
double mid = 0;
|
||||
double range = 0;
|
||||
XBoxZone upperRNGB;
|
||||
XBoxZone lowerRNGB;
|
||||
bool isIn = false;
|
||||
has = eaHelper
|
||||
.barAnalyser
|
||||
.DetectRangeBlocks(
|
||||
zBar,
|
||||
upperRNGB,
|
||||
lowerRNGB,
|
||||
(288 * 5) //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Setting Range Boxes ...
|
||||
upperRNGB.to = zBar.time;
|
||||
lowerRNGB.to = zBar.time;
|
||||
eaUpperRange.to = zBar.time;
|
||||
eaLowerRange.to = zBar.time;
|
||||
|
||||
//
|
||||
bool canSet = false;
|
||||
|
||||
//
|
||||
// Set Upper Range ...
|
||||
canSet = !eaUpperRange.IsValid()
|
||||
? true
|
||||
: upperRNGB.upper > eaUpperRange.upper;
|
||||
if (canSet)
|
||||
{
|
||||
eaUpperRange = upperRNGB;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Lower Range ...
|
||||
canSet = !eaLowerRange.IsValid()
|
||||
? true
|
||||
: lowerRNGB.lower < eaLowerRange.lower;
|
||||
if (canSet)
|
||||
{
|
||||
eaLowerRange = lowerRNGB;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Requirements ...
|
||||
range = eaUpperRange.lower - eaLowerRange.upper;
|
||||
mid = eaUpperRange.lower - (range / 2);
|
||||
|
||||
//
|
||||
double price = zBar.close; // bid;
|
||||
|
||||
//
|
||||
// Check Price in Upper Tange ...
|
||||
bool isInUpperRange =
|
||||
price >= eaUpperRange.lower &&
|
||||
price <= eaUpperRange.upper;
|
||||
|
||||
//
|
||||
// Check Price in Lower Range ...
|
||||
bool isInLowerRange =
|
||||
price >= eaLowerRange.lower &&
|
||||
price <= eaLowerRange.upper;
|
||||
|
||||
//
|
||||
isIn = isInUpperRange ||
|
||||
isInLowerRange;
|
||||
if (isIn)
|
||||
{
|
||||
//
|
||||
if (isInUpperRange) {
|
||||
eaLowerRange = lowerRNGB;
|
||||
}
|
||||
|
||||
//
|
||||
if (isInLowerRange) {
|
||||
eaUpperRange = upperRNGB;
|
||||
}
|
||||
|
||||
//
|
||||
Print("IsIn ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Do Detection ...
|
||||
has = DetectTriggerBlock(
|
||||
eaTB,
|
||||
eaHelper,
|
||||
eaTBConfig,
|
||||
zBar.Index(),
|
||||
10,
|
||||
eaSLAdditionalPoint,
|
||||
eaSLATRMultiplier //
|
||||
XTriggerBlock iTB;
|
||||
has = GetNewestX121TriggerBlock(
|
||||
_Symbol,
|
||||
_Period,
|
||||
iTB //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
bool isBullish = eaTB.trigger.IsBullish();
|
||||
|
||||
//
|
||||
has =
|
||||
isBullish
|
||||
? zBar.close < mid
|
||||
: zBar.close > mid;
|
||||
if (!has)
|
||||
// Check Newest TB is Newer Than Exists TB ...
|
||||
bool canPass =
|
||||
!eaTB.IsValid()
|
||||
? true
|
||||
: iTB.ToIndex() < eaTB.ToIndex();
|
||||
if (canPass)
|
||||
{
|
||||
eaTB.Clean();
|
||||
//
|
||||
eaTB = iTB;
|
||||
eaSignal = iTB.signal;
|
||||
|
||||
//
|
||||
// Prepare eaConditions if Reuqired ...
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Draws ...
|
||||
|
||||
//
|
||||
// Darw Ranges ...
|
||||
has = eaUpperRange.IsValid() &&
|
||||
eaLowerRange.IsValid();
|
||||
has = eaSignal.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Draw Ranges ...
|
||||
|
||||
//
|
||||
// Draw Upper Range ...
|
||||
XCBoxObject *iUpperObj;
|
||||
has = eaHelper.poiDrawer.DrawBox(
|
||||
eaUpperRange,
|
||||
iUpperObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Style Object ...
|
||||
|
||||
//
|
||||
// Store Object ...
|
||||
eaObjects.Add(iUpperObj);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Lower Range ...
|
||||
XCBoxObject *iLowerObj;
|
||||
has = eaHelper.poiDrawer.DrawBox(
|
||||
eaLowerRange,
|
||||
iLowerObj //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Style Object ...
|
||||
|
||||
//
|
||||
// Store Object ...
|
||||
eaObjects.Add(iLowerObj);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Fibonacchi ...
|
||||
// Here we ensure which has a New Signal and must
|
||||
// prepare and Execute it ...
|
||||
Print("new Signal Detected ...");
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Trigger Block ...
|
||||
has = eaTB.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
if (eaTB.signal.IsValid())
|
||||
{
|
||||
//
|
||||
eaSignal = eaTB.signal;
|
||||
|
||||
//
|
||||
eaConditions.symbol = eaTB.signal.symbol;
|
||||
eaConditions.period = eaTB.signal.period;
|
||||
eaConditions.conditions = eaTB.conditions;
|
||||
}
|
||||
|
||||
//
|
||||
CArrayObj *tObjects;
|
||||
tObjects = new CArrayObj();
|
||||
|
||||
//
|
||||
has = DrawTriggerBlock(
|
||||
eaTB,
|
||||
tObjects,
|
||||
eaHelper,
|
||||
NULL, // zBar.time,
|
||||
0 // Prevent Drawing RR Zones ...
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
AddObjects(tObjects, eaObjects);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Signals ...
|
||||
|
||||
//
|
||||
// Check Signal Validation ...
|
||||
if (eaSignal.IsValid())
|
||||
{
|
||||
//
|
||||
// Do What we Want ...
|
||||
// When we Need Waits Until Next Bar ...
|
||||
eaBarTraker.Waits();
|
||||
|
||||
//
|
||||
bool isLong = IsLong(eaSignal.type);
|
||||
|
||||
//
|
||||
// Update Entry ...
|
||||
eaSignal.entry = GetEntry(
|
||||
eaSignal.symbol,
|
||||
eaSignal.type //
|
||||
);
|
||||
|
||||
//
|
||||
// Try to Check Liquidity ...
|
||||
if (eaTB.rLiquidity.IsValid())
|
||||
{
|
||||
//
|
||||
double irLQRange = eaTB.rLiquidity.GetRange();
|
||||
eaSignal.sl =
|
||||
isLong
|
||||
? eaSignal.sl - irLQRange
|
||||
: eaSignal.sl + irLQRange;
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Signal Targets ...
|
||||
ApplySignalTargets(eaSignal);
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = eaVolume.CalculateVolume(eaSignal);
|
||||
if (iVolume > X_MIN_VOLUME &&
|
||||
iVolume != eaSignal.volume)
|
||||
{
|
||||
eaSignal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Execute Signal ...
|
||||
has = eaTradeManager.Execute(
|
||||
eaSignal,
|
||||
eaConditions //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
|
||||
//
|
||||
eaTB.Clean();
|
||||
// eaTB.Clean();
|
||||
zBar.Clean();
|
||||
cBar.Clean();
|
||||
eaSignal.Clean();
|
||||
@@ -800,10 +572,45 @@ void InitRequirements()
|
||||
|
||||
//
|
||||
// we Can make Show all requirements here ...
|
||||
eaInputs.caInputs.showSar = false;
|
||||
|
||||
//
|
||||
eaHelper = new XCXCAEAHelper();
|
||||
// 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,
|
||||
@@ -878,60 +685,6 @@ void InitRequirements()
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void ConfigureDetector()
|
||||
{
|
||||
//
|
||||
// Configure Detector ...
|
||||
|
||||
//
|
||||
// Validation ...
|
||||
eaTBConfig.maxAllowedRange = eaMaxAllowedRange;
|
||||
eaTBConfig.minAllowedBlockEdgeLength = eaMinAllowedBlockEdgeLength;
|
||||
|
||||
//
|
||||
// Validation ...
|
||||
eaTBConfig.forceFVGBarType = eaForceFVGBarType;
|
||||
eaTBConfig.forceHasSwingBar = eaForceHasSwingBar;
|
||||
eaTBConfig.forceOBOppositBar = eaForceOBOppositBar;
|
||||
eaTBConfig.forceHasLiquidity = eaForceHasLiquidity;
|
||||
eaTBConfig.forceGapBarBreakout = eaForceGapBarBreakout;
|
||||
eaTBConfig.forceHasReversalLiquidity = eaForceHasReversalLiquidity;
|
||||
|
||||
//
|
||||
// Filters ...
|
||||
eaTBConfig.filterBasedOnSar = eaFilterBasedOnSar;
|
||||
eaTBConfig.filterBasedOnADX = eaFilterBasedOnADX;
|
||||
eaTBConfig.filterBasedOnRSI = eaFilterBasedOnRSI;
|
||||
eaTBConfig.filterBasedOnTrend = eaFilterBasedOnTrend;
|
||||
eaTBConfig.filterBasedOnScores = eaFilterBasedOnScores;
|
||||
eaTBConfig.filterBasedOnVolumes = eaFilterBasedOnVolumes;
|
||||
|
||||
//
|
||||
// Targets ...
|
||||
double targets[] = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
};
|
||||
Copy(
|
||||
targets,
|
||||
eaTBConfig.targets //
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling Time Reporting ...
|
||||
*/
|
||||
@@ -1003,9 +756,10 @@ void ApplySignalTargets(XSignal &signal)
|
||||
|
||||
//
|
||||
// Calculate Requirements ...
|
||||
double r2r = maxAllowedR2R > 0
|
||||
? maxAllowedR2R
|
||||
: 1;
|
||||
double r2r = 1;
|
||||
// maxAllowedR2R > 0
|
||||
// ? maxAllowedR2R
|
||||
// : 1;
|
||||
double risk = signal.GetRisk();
|
||||
double reward = risk * r2r;
|
||||
|
||||
Reference in New Issue
Block a user