last works on xom1 ea ...

This commit is contained in:
2025-09-07 18:48:24 +03:30
parent 19497ba6ef
commit 5987194e51
7 changed files with 4771 additions and 749 deletions
File diff suppressed because it is too large Load Diff
+121
View File
@@ -35,6 +35,67 @@ input long eaMagicNumber = 1694056; // Magic Number
input int eaSlippage = 10; // Slippgae input int eaSlippage = 10; // Slippgae
input string eaLogSuffix = ""; // Log Suffix input string eaLogSuffix = ""; // Log Suffix
//
// Management ...
// eaSessions => (ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20: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
input string eaSessions = ""; // Active Sessions
input ENUM_XTRADE_RESTRICTION_PERIOD eaRestrictionsPeriod = XTRADE_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
//
// Volume ...
input group "Volume";
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_CONSTANT; // 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 = 1; // Constant Percent of Balance Per Trade
input double eaConstantBalance = 1000.0; // Constant Balance for Calculations
//
// Alert ...
input group "Alert";
input bool eaEnableAlerts = true; // Enable Alerts
input bool eaSaveAlerts = true; // Save 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
//
// Reports ...
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 eaReportRestrictions = true; // Report Restrictions
input bool eaReportProtector = true; // Report Protector Actions
input bool eaReportAfterTradesBalance = true; // Report Balance after a Trade Finished
//
// Collector ...
input group "Collector";
input bool eaSaveTrades = true; // Save Trades
input bool eaSaveSignals = true; // Save Signals
input bool eaSaveWins = true; // Save Winning Conditions
input bool eaSaveLosts = true; // Save Lost Conditions
input bool eaSaveRestrictions = true; // Save Restriction Reports
// //
// Variables ... // Variables ...
@@ -78,14 +139,74 @@ int OnInit()
// //
// Setting All Inputs to Expert Adviser Class ... // Setting All Inputs to Expert Adviser Class ...
// //
// Management ...
eaExpert.eaAllowGuards = eaAllowGuards;
eaExpert.eaAllowTrade = eaAllowTrade;
eaExpert.eaAllowLongs = eaAllowLongs;
eaExpert.eaAllowShorts = eaAllowShorts;
eaExpert.eaSessions = eaSessions;
eaExpert.eaRestrictionsPeriod = eaRestrictionsPeriod;
eaExpert.eaMaxAllowedTPs = eaMaxAllowedTPs;
eaExpert.eaMaxAllowedSLs = eaMaxAllowedSLs;
eaExpert.eaMaxAllowedTrades = eaMaxAllowedTrades;
eaExpert.eaMaxAllowedPositions = eaMaxAllowedPositions;
eaExpert.eaMaxAllowedSpread = eaMaxAllowedSpread;
eaExpert.eaMaxAllowedDrawdownFactor = eaMaxAllowedDrawdownFactor;
eaExpert.eaCloseAllOpenTradesAt = eaCloseAllOpenTradesAt;
//
// Volume ...
eaExpert.eaVolumeSelect = eaVolumeSelect;
eaExpert.eaStaticVoluem = eaStaticVoluem;
eaExpert.eaDynamicVolumeStepBalance = eaDynamicVolumeStepBalance;
eaExpert.eaDynamicVolumeStepVolume = eaDynamicVolumeStepVolume;
eaExpert.eaConstantRiskBalance = eaConstantRiskBalance;
eaExpert.eaConstantPercent = eaConstantPercent;
eaExpert.eaConstantBalance = eaConstantBalance;
//
// Alert ...
eaExpert.eaEnableAlerts = eaEnableAlerts;
eaExpert.eaSaveAlerts = eaSaveAlerts;
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.eaReportRestrictions = eaReportRestrictions;
eaExpert.eaReportProtector = eaReportProtector;
eaExpert.eaReportAfterTradesBalance = eaReportAfterTradesBalance;
//
// Collector ...
eaExpert.eaSaveTrades = eaSaveTrades;
eaExpert.eaSaveSignals = eaSaveSignals;
eaExpert.eaSaveWins = eaSaveWins;
eaExpert.eaSaveLosts = eaSaveLosts;
eaExpert.eaSaveRestrictions = eaSaveRestrictions;
//
// Try to Initialize eaExpert ...
bool isInited = eaExpert.HandleOnInit(); bool isInited = eaExpert.HandleOnInit();
if (!isInited) if (!isInited)
{ {
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED; return INIT_FAILED;
} }
// //
Print(ShortName, ": Initialized Successfully ...");
return INIT_SUCCEEDED; return INIT_SUCCEEDED;
} }
+259 -68
View File
@@ -31,26 +31,30 @@
// Buffers ... // Buffers ...
enum ENUM_XOM1_BUFFERS enum ENUM_XOM1_BUFFERS
{ {
XOM1_MA_LINE = 0, XOM1_MA_FAST_LINE = 0,
XOM1_MA_COLOR_LINE = 1, XOM1_MA_FAST_COLOR_LINE = 1,
XOM1_MA_STATE_LINE = 8, XOM1_MA_FAST_STATE_LINE = 10,
XOM1_SAR_LINE = 2, XOM1_MA_SLOW_LINE = 2,
XOM1_SAR_COLOR_LINE = 3, XOM1_MA_SLOW_COLOR_LINE = 3,
XOM1_SAR_STATE_LINE = 9, XOM1_MA_SLOW_STATE_LINE = 11,
XOM1_PEAK_LINE = 4, XOM1_SAR_LINE = 4,
XOM1_VALE_LINE = 5, XOM1_SAR_COLOR_LINE = 5,
XOM1_FINO_UPPER_LINE = 6, XOM1_SAR_STATE_LINE = 12,
XOM1_FINO_LOWER_LINE = 7, XOM1_PEAK_LINE = 6,
// 8 Ma State XOM1_VALE_LINE = 7,
// 9 Sar State XOM1_FINO_UPPER_LINE = 8,
XOM1_SC_HH_LINE = 10, XOM1_FINO_LOWER_LINE = 9,
XOM1_SC_LL_LINE = 11, // 10 Ma Fast State
XOM1_MC_HH_LINE = 12, // 11 Ma Slow State
XOM1_MC_LL_LINE = 13, // 12 Sar State
XOM1_LC_HH_LINE = 14, XOM1_SC_HH_LINE = 13,
XOM1_LC_LL_LINE = 15, XOM1_SC_LL_LINE = 14,
XOM1_HC_HH_LINE = 16, XOM1_MC_HH_LINE = 15,
XOM1_HC_LL_LINE = 17, XOM1_MC_LL_LINE = 16,
XOM1_LC_HH_LINE = 17,
XOM1_LC_LL_LINE = 18,
XOM1_HC_HH_LINE = 19,
XOM1_HC_LL_LINE = 20,
}; };
// //
@@ -78,13 +82,15 @@ struct XOM1Inputs
double sarMax; // SAR Maximum double sarMax; // SAR Maximum
ENUM_MA_METHOD maMethod; // MA Method ENUM_MA_METHOD maMethod; // MA Method
ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To
int maLength; // MA Length int maFastLength; // Fast MA Length
int maSlowLength; // Slow MA Length
// //
// Presentation ... // Presentation ...
bool showPV; // Show PV bool showPV; // Show PV
bool showMA; // Show MA
bool showSAR; // Show Sar bool showSAR; // Show Sar
bool showMAFast; // Show MA Fast
bool showMASlow; // Show MA Slow
bool showFiboZone; // Show Fibo Zone bool showFiboZone; // Show Fibo Zone
int startCalculationForLastBars; // Calculate Last n Bars int startCalculationForLastBars; // Calculate Last n Bars
int sarArrowCode; // Parabolic Sar Arrow Code int sarArrowCode; // Parabolic Sar Arrow Code
@@ -130,13 +136,15 @@ struct XOM1Inputs
sarMax = 0.2; // SAR Maximum sarMax = 0.2; // SAR Maximum
maMethod = MODE_EMA; // MA Method maMethod = MODE_EMA; // MA Method
maAppliedTo = PRICE_CLOSE; // MA Applied To maAppliedTo = PRICE_CLOSE; // MA Applied To
maLength = 10; // MA Length maFastLength = 7; // Fast MA Length
maSlowLength = 20; // Slow MA Length
// //
// Presentation ... // Presentation ...
showPV = true; // Show PV showPV = true; // Show PV
showMA = true; // Show MA
showSAR = true; // Show Sar showSAR = true; // Show Sar
showMAFast = true; // Show MA Fast
showMASlow = true; // Show MA Slow
showFiboZone = true; // Show Fibo Zone showFiboZone = true; // Show Fibo Zone
startCalculationForLastBars = 1500; // Calculate Last n Bars startCalculationForLastBars = 1500; // Calculate Last n Bars
sarArrowCode = 159; // Parabolic Sar Arrow Code sarArrowCode = 159; // Parabolic Sar Arrow Code
@@ -150,8 +158,9 @@ struct XOM1Inputs
{ {
// //
showPV = false; showPV = false;
showMA = false;
showSAR = false; showSAR = false;
showMAFast = false;
showMASlow = false;
showFiboZone = false; showFiboZone = false;
} }
@@ -166,7 +175,9 @@ struct XOM1Inputs
result = result =
// //
// MA ... // MA ...
maLength >= 2 && maFastLength >= 2 &&
maSlowLength >= 2 &&
maSlowLength > maFastLength &&
// //
// SAR ... // SAR ...
sarMax > 0 && sarMax > 0 &&
@@ -203,9 +214,12 @@ struct XOM1Conditions
// //
// Buffers ... // Buffers ...
double maBuffer[]; double maFastBuffer[];
double maColorBuffer[]; double maFastColorBuffer[];
double maStateBuffer[]; double maFastStateBuffer[];
double maSlowBuffer[];
double maSlowColorBuffer[];
double maSlowStateBuffer[];
double sarBuffer[]; double sarBuffer[];
double sarColorBuffer[]; double sarColorBuffer[];
double sarStateBuffer[]; double sarStateBuffer[];
@@ -255,9 +269,12 @@ struct XOM1Conditions
SpecifiedClean(bars); SpecifiedClean(bars);
// //
SpecifiedClean(maBuffer); SpecifiedClean(maFastBuffer);
SpecifiedClean(maColorBuffer); SpecifiedClean(maFastColorBuffer);
SpecifiedClean(maStateBuffer); SpecifiedClean(maFastStateBuffer);
SpecifiedClean(maSlowBuffer);
SpecifiedClean(maSlowColorBuffer);
SpecifiedClean(maSlowStateBuffer);
SpecifiedClean(sarBuffer); SpecifiedClean(sarBuffer);
SpecifiedClean(sarColorBuffer); SpecifiedClean(sarColorBuffer);
SpecifiedClean(sarStateBuffer); SpecifiedClean(sarStateBuffer);
@@ -281,9 +298,12 @@ struct XOM1Conditions
ArraySetAsSeries(bars, true); ArraySetAsSeries(bars, true);
// //
ArraySetAsSeries(maBuffer, true); ArraySetAsSeries(maFastBuffer, true);
ArraySetAsSeries(maColorBuffer, true); ArraySetAsSeries(maFastColorBuffer, true);
ArraySetAsSeries(maStateBuffer, true); ArraySetAsSeries(maFastStateBuffer, true);
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
ArraySetAsSeries(maSlowStateBuffer, true);
ArraySetAsSeries(sarBuffer, true); ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(sarColorBuffer, true); ArraySetAsSeries(sarColorBuffer, true);
ArraySetAsSeries(sarStateBuffer, true); ArraySetAsSeries(sarStateBuffer, true);
@@ -362,9 +382,12 @@ class XCXOM1Helper : public XCBaseHelper
// //
// Buffers ... // Buffers ...
double maBuffer[]; double maFastBuffer[];
double maColorBuffer[]; double maFastColorBuffer[];
double maStateBuffer[]; double maFastStateBuffer[];
double maSlowBuffer[];
double maSlowColorBuffer[];
double maSlowStateBuffer[];
double sarBuffer[]; double sarBuffer[];
double sarColorBuffer[]; double sarColorBuffer[];
double sarStateBuffer[]; double sarStateBuffer[];
@@ -420,9 +443,12 @@ class XCXOM1Helper : public XCBaseHelper
} }
// //
ArraySetAsSeries(maBuffer, true); ArraySetAsSeries(maFastBuffer, true);
ArraySetAsSeries(maColorBuffer, true); ArraySetAsSeries(maFastColorBuffer, true);
ArraySetAsSeries(maStateBuffer, true); ArraySetAsSeries(maFastStateBuffer, true);
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
ArraySetAsSeries(maSlowStateBuffer, true);
ArraySetAsSeries(sarBuffer, true); ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(sarColorBuffer, true); ArraySetAsSeries(sarColorBuffer, true);
ArraySetAsSeries(sarStateBuffer, true); ArraySetAsSeries(sarStateBuffer, true);
@@ -464,11 +490,13 @@ class XCXOM1Helper : public XCBaseHelper
mInputs.sarMax, mInputs.sarMax,
mInputs.maMethod, mInputs.maMethod,
mInputs.maAppliedTo, mInputs.maAppliedTo,
mInputs.maLength, mInputs.maFastLength,
mInputs.maSlowLength,
"", // Presentation ... "", // Presentation ...
mInputs.showPV, mInputs.showPV,
mInputs.showMA,
mInputs.showSAR, mInputs.showSAR,
mInputs.showMAFast,
mInputs.showMASlow,
mInputs.showFiboZone, mInputs.showFiboZone,
mInputs.startCalculationForLastBars, mInputs.startCalculationForLastBars,
mInputs.sarArrowCode, mInputs.sarArrowCode,
@@ -588,17 +616,31 @@ class XCXOM1Helper : public XCBaseHelper
// Buffers ... // Buffers ...
// //
CopyMA( CopyMAFast(
zIndex, zIndex,
loopback, loopback,
conditions.maBuffer // conditions.maFastBuffer //
); );
// //
CopyMAState( CopyMAFastState(
zIndex, zIndex,
loopback, loopback,
conditions.maStateBuffer // conditions.maFastStateBuffer //
);
//
CopyMASlow(
zIndex,
loopback,
conditions.maSlowBuffer //
);
//
CopyMASlowState(
zIndex,
loopback,
conditions.maSlowStateBuffer //
); );
// //
@@ -710,10 +752,10 @@ class XCXOM1Helper : public XCBaseHelper
// Values Retrievers ... // Values Retrievers ...
// //
// MA ... // Fast MA ...
// //
double GetMA( double GetMAFast(
int barIndex // Bar Index int barIndex // Bar Index
) )
{ {
@@ -727,18 +769,18 @@ class XCXOM1Helper : public XCBaseHelper
Calculate(barIndex); Calculate(barIndex);
// //
int count = ArraySize(maBuffer); int count = ArraySize(maFastBuffer);
if (barIndex >= count) if (barIndex >= count)
{ {
barIndex = count - 1; barIndex = count - 1;
} }
// //
return maBuffer[barIndex]; return maFastBuffer[barIndex];
} }
// //
int CopyMA( int CopyMAFast(
int start, // Start int start, // Start
int count, // Number of Items for read int count, // Number of Items for read
double &buffer[], // Dest Buffer double &buffer[], // Dest Buffer
@@ -754,7 +796,7 @@ class XCXOM1Helper : public XCBaseHelper
return Copy( return Copy(
0, 0,
count, count,
maBuffer, maFastBuffer,
buffer, buffer,
forceClean forceClean
// //
@@ -762,10 +804,10 @@ class XCXOM1Helper : public XCBaseHelper
} }
// //
// MA State ... // Fast MA State ...
// //
double GetMAState( double GetMAFastState(
int barIndex // Bar Index int barIndex // Bar Index
) )
{ {
@@ -779,18 +821,18 @@ class XCXOM1Helper : public XCBaseHelper
Calculate(barIndex); Calculate(barIndex);
// //
int count = ArraySize(maStateBuffer); int count = ArraySize(maFastStateBuffer);
if (barIndex >= count) if (barIndex >= count)
{ {
barIndex = count - 1; barIndex = count - 1;
} }
// //
return maStateBuffer[barIndex]; return maFastStateBuffer[barIndex];
} }
// //
int CopyMAState( int CopyMAFastState(
int start, // Start int start, // Start
int count, // Number of Items for read int count, // Number of Items for read
double &buffer[], // Dest Buffer double &buffer[], // Dest Buffer
@@ -806,7 +848,111 @@ class XCXOM1Helper : public XCBaseHelper
return Copy( return Copy(
0, 0,
count, count,
maStateBuffer, maFastStateBuffer,
buffer,
forceClean
//
);
}
//
// Slow MA ...
//
double GetMASlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(maSlowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return maSlowBuffer[barIndex];
}
//
int CopyMASlow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
maSlowBuffer,
buffer,
forceClean
//
);
}
//
// Slow MA State ...
//
double GetMASlowState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(maSlowStateBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return maSlowStateBuffer[barIndex];
}
//
int CopyMASlowState(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
maSlowStateBuffer,
buffer, buffer,
forceClean forceClean
// //
@@ -1589,28 +1735,55 @@ class XCXOM1Helper : public XCBaseHelper
// //
CopyBuffer( CopyBuffer(
mHandler, mHandler,
XOM1_MA_LINE, XOM1_MA_FAST_LINE,
barIndex, barIndex,
maxRequiredBars, maxRequiredBars,
maBuffer // maFastBuffer //
); );
// //
CopyBuffer( CopyBuffer(
mHandler, mHandler,
XOM1_MA_COLOR_LINE, XOM1_MA_FAST_COLOR_LINE,
barIndex, barIndex,
maxRequiredBars, maxRequiredBars,
maColorBuffer // maFastColorBuffer //
); );
// //
CopyBuffer( CopyBuffer(
mHandler, mHandler,
XOM1_MA_STATE_LINE, XOM1_MA_FAST_STATE_LINE,
barIndex, barIndex,
maxRequiredBars, maxRequiredBars,
maStateBuffer // maFastStateBuffer //
);
//
CopyBuffer(
mHandler,
XOM1_MA_SLOW_LINE,
barIndex,
maxRequiredBars,
maSlowBuffer //
);
//
CopyBuffer(
mHandler,
XOM1_MA_SLOW_COLOR_LINE,
barIndex,
maxRequiredBars,
maSlowColorBuffer //
);
//
CopyBuffer(
mHandler,
XOM1_MA_SLOW_STATE_LINE,
barIndex,
maxRequiredBars,
maSlowStateBuffer //
); );
// //
@@ -1756,19 +1929,37 @@ class XCXOM1Helper : public XCBaseHelper
{ {
// //
CleanupArray( CleanupArray(
maBuffer, maFastBuffer,
maxAllowed // maxAllowed //
); );
// //
CleanupArray( CleanupArray(
maColorBuffer, maFastColorBuffer,
maxAllowed // maxAllowed //
); );
// //
CleanupArray( CleanupArray(
maStateBuffer, maFastStateBuffer,
maxAllowed //
);
//
CleanupArray(
maSlowBuffer,
maxAllowed //
);
//
CleanupArray(
maSlowColorBuffer,
maxAllowed //
);
//
CleanupArray(
maSlowStateBuffer,
maxAllowed // maxAllowed //
); );
+179 -93
View File
@@ -65,19 +65,21 @@ input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method
// //
// Others ... // Others ...
input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level
input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_764; // Lower Zone Level input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_382; // Lower Zone Level
input double sarStep = 0.02; // SAR Step input double sarStep = 0.02; // SAR Step
input double sarMax = 0.2; // SAR Maximum input double sarMax = 0.2; // SAR Maximum
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input int maLength = 10; // MA Length input int maFastLength = 7; // Fast MA Length
input int maSlowLength = 20; // Slow MA Length
// //
// Presentation ... // Presentation ...
input group "Presentation"; input group "Presentation";
input bool showPV = true; // Show PV input bool showPV = true; // Show PV
input bool showMA = true; // Show MA
input bool showSAR = true; // Show Sar input bool showSAR = true; // Show Sar
input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow
input bool showFiboZone = true; // Show Fibo Zone input bool showFiboZone = true; // Show Fibo Zone
// //
@@ -112,122 +114,144 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window #property indicator_chart_window
// //
#property indicator_buffers 18 #property indicator_buffers 21
#property indicator_plots 6 #property indicator_plots 7
// //
// Plot Buffers ... // Plot Buffers ...
// //
// MA ... // Fast MA ...
// //
#define maBufferIndex 0 #define maFastBufferIndex 0
#define maBufferPlotIndex 0 #define maFastBufferPlotIndex 0
double maBuffer[]; double maFastBuffer[];
// //
#define maColorBufferIndex 1 #define maFastColorBufferIndex 1
double maColorBuffer[]; double maFastColorBuffer[];
// //
#property indicator_label1 "MA" #property indicator_label1 "FastMA"
#property indicator_type1 DRAW_COLOR_LINE #property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray #property indicator_color1 CLR_NONE, clrYellow, clrOrangeRed, clrGray
#property indicator_width1 2 #property indicator_width1 2
//
// Slow MA ...
//
#define maSlowBufferIndex 2
#define maSlowBufferPlotIndex 1
double maSlowBuffer[];
//
#define maSlowColorBufferIndex 3
double maSlowColorBuffer[];
//
#property indicator_label2 "SlowMA"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_width2 2
// //
// SAR ... // SAR ...
// //
#define sarBufferIndex 2 #define sarBufferIndex 4
#define sarBufferPlotIndex 1 #define sarBufferPlotIndex 2
double sarBuffer[]; double sarBuffer[];
// //
#define sarColorBufferIndex 3 #define sarColorBufferIndex 5
double sarColorBuffer[]; double sarColorBuffer[];
// //
#property indicator_label2 "SAR" #property indicator_label3 "SAR"
#property indicator_type2 DRAW_COLOR_ARROW #property indicator_type3 DRAW_COLOR_ARROW
#property indicator_color2 CLR_NONE, clrLime, clrRed, clrGray #property indicator_color3 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_width2 2 #property indicator_width3 2
// //
// PEAKS ... // PEAKS ...
// //
#define peakBufferIndex 4 #define peakBufferIndex 6
#define peakBufferPlotIndex 2 #define peakBufferPlotIndex 3
double peakBuffer[]; double peakBuffer[];
// //
#property indicator_label3 "PEAK" #property indicator_label4 "PEAK"
#property indicator_type3 DRAW_ARROW #property indicator_type4 DRAW_ARROW
#property indicator_color3 clrMagenta #property indicator_color4 clrMagenta
#property indicator_width3 3 #property indicator_width4 3
// //
// VALES ... // VALES ...
// //
#define valeBufferIndex 5 #define valeBufferIndex 7
#define valeBufferPlotIndex 3 #define valeBufferPlotIndex 4
double valeBuffer[]; double valeBuffer[];
// //
#property indicator_label4 "VALE" #property indicator_label5 "VALE"
#property indicator_type4 DRAW_ARROW #property indicator_type5 DRAW_ARROW
#property indicator_color4 clrAqua #property indicator_color5 clrAqua
#property indicator_width4 3 #property indicator_width5 3
// //
// FIBO Upper ... // FIBO Upper ...
// //
#define fiboUpperBufferIndex 6 #define fiboUpperBufferIndex 8
#define fiboUpperBufferPlotIndex 4 #define fiboUpperBufferPlotIndex 5
double fiboUpperBuffer[]; double fiboUpperBuffer[];
// //
#property indicator_label5 "FIBUP" #property indicator_label6 "FIBUP"
#property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_LINE
#property indicator_color5 clrAqua #property indicator_color6 clrAqua
#property indicator_width5 2 #property indicator_width6 2
// //
// FIBO Lower ... // FIBO Lower ...
// //
#define fiboLowerBufferIndex 7 #define fiboLowerBufferIndex 9
#define fiboLowerBufferPlotIndex 5 #define fiboLowerBufferPlotIndex 6
double fiboLowerBuffer[]; double fiboLowerBuffer[];
// //
#property indicator_label6 "FIBLO" #property indicator_label7 "FIBLO"
#property indicator_type6 DRAW_LINE #property indicator_type7 DRAW_LINE
#property indicator_color6 clrMagenta #property indicator_color7 clrMagenta
#property indicator_width6 2 #property indicator_width7 2
// //
// Data Buffers ... // Data Buffers ...
// //
#define mLastBufferIndex 7 #define mLastBufferIndex 9
// //
// MA ... // MA ...
// //
#define maStateBufferIndex mLastBufferIndex + 1 #define maFastStateBufferIndex mLastBufferIndex + 1
double maStateBuffer[]; double maFastStateBuffer[];
//
#define maSlowStateBufferIndex mLastBufferIndex + 2
double maSlowStateBuffer[];
// //
// SAR ... // SAR ...
// //
#define sarStateBufferIndex mLastBufferIndex + 2 #define sarStateBufferIndex mLastBufferIndex + 3
double sarStateBuffer[]; double sarStateBuffer[];
// //
@@ -237,44 +261,44 @@ double sarStateBuffer[];
// SC ... // SC ...
// //
#define sHHBufferIndex mLastBufferIndex + 3 #define sHHBufferIndex mLastBufferIndex + 4
double sHHBuffer[]; double sHHBuffer[];
// //
#define sLLBufferIndex mLastBufferIndex + 4 #define sLLBufferIndex mLastBufferIndex + 5
double sLLBuffer[]; double sLLBuffer[];
// //
// MC ... // MC ...
// //
#define mHHBufferIndex mLastBufferIndex + 5 #define mHHBufferIndex mLastBufferIndex + 6
double mHHBuffer[]; double mHHBuffer[];
// //
#define mLLBufferIndex mLastBufferIndex + 6 #define mLLBufferIndex mLastBufferIndex + 7
double mLLBuffer[]; double mLLBuffer[];
// //
// LC ... // LC ...
// //
#define lHHBufferIndex mLastBufferIndex + 7 #define lHHBufferIndex mLastBufferIndex + 8
double lHHBuffer[]; double lHHBuffer[];
// //
#define lLLBufferIndex mLastBufferIndex + 8 #define lLLBufferIndex mLastBufferIndex + 9
double lLLBuffer[]; double lLLBuffer[];
// //
// HC ... // HC ...
// //
#define hHHBufferIndex mLastBufferIndex + 9 #define hHHBufferIndex mLastBufferIndex + 10
double hHHBuffer[]; double hHHBuffer[];
// //
#define hLLBufferIndex mLastBufferIndex + 10 #define hLLBufferIndex mLastBufferIndex + 11
double hLLBuffer[]; double hLLBuffer[];
// //
@@ -301,8 +325,9 @@ int mHCLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL; ENUM_TIMEFRAMES mHCPeriod = NULL;
// //
int maHandler = INVALID_HANDLE;
int sarHandler = INVALID_HANDLE; int sarHandler = INVALID_HANDLE;
int maFastHandler = INVALID_HANDLE;
int maSlowHandler = INVALID_HANDLE;
// //
int limit; int limit;
@@ -404,8 +429,9 @@ void OnDeinit(const int reason)
// //
// De Initialize all Handlers and etc ... // De Initialize all Handlers and etc ...
IndicatorRelease(maHandler);
IndicatorRelease(sarHandler); IndicatorRelease(sarHandler);
IndicatorRelease(maFastHandler);
IndicatorRelease(maSlowHandler);
} }
/** /**
@@ -453,7 +479,8 @@ int OnCalculate(
// //
// MA ... // MA ...
int maCalculatedBars = BarsCalculated(maHandler); int maFastCalculatedBars = BarsCalculated(maFastHandler);
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
// //
// SAR ... // SAR ...
@@ -463,7 +490,8 @@ int OnCalculate(
bool isPassedRequiredCalculatedBars = bool isPassedRequiredCalculatedBars =
// //
// MA ... // MA ...
maCalculatedBars >= maxLength && maFastCalculatedBars >= maxLength &&
maSlowCalculatedBars >= maxLength &&
// //
// SAR ... // SAR ...
sarCalculatedBars >= maxLength sarCalculatedBars >= maxLength
@@ -484,7 +512,8 @@ int OnCalculate(
// //
// MA ... // MA ...
int copiedMAs = CopyBuffer(maHandler, MAIN_LINE, 0, limit, maBuffer); int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer);
int copiedMASlows = CopyBuffer(maSlowHandler, MAIN_LINE, 0, limit, maSlowBuffer);
// //
// SAR ... // SAR ...
@@ -495,7 +524,8 @@ int OnCalculate(
bool isPassedRequiredCopiedItems = bool isPassedRequiredCopiedItems =
// //
// MA ... // MA ...
copiedMAs >= limit && copiedMAFasts >= limit &&
copiedMASlows >= limit &&
// //
// SAR ... // SAR ...
copiedSARs >= limit copiedSARs >= limit
@@ -555,7 +585,9 @@ bool ValidateInputs()
result = result =
// //
// MA ... // MA ...
maLength >= 2 && maFastLength >= 2 &&
maSlowLength >= 2 &&
maSlowLength > maFastLength &&
// //
// SAR ... // SAR ...
sarMax > 0 && sarMax > 0 &&
@@ -588,7 +620,8 @@ int ExtractMaxLengthOfInputs()
result = MathMax(mSCLength, mMCLength); result = MathMax(mSCLength, mMCLength);
result = MathMax(result, mLCLength); result = MathMax(result, mLCLength);
result = MathMax(result, mHCLength); result = MathMax(result, mHCLength);
result = MathMax(result, maLength); result = MathMax(result, maFastLength);
result = MathMax(result, maSlowLength);
// //
return result; return result;
@@ -600,23 +633,42 @@ int ExtractMaxLengthOfInputs()
void DefineBuffers() void DefineBuffers()
{ {
// //
// MA ... // Fast MA ...
// //
ArraySetAsSeries(maBuffer, true); ArraySetAsSeries(maFastBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA); SetIndexBuffer(maFastBufferIndex, maFastBuffer, INDICATOR_DATA);
// //
PlotIndexSetInteger(maBufferPlotIndex, PLOT_SHOW_DATA, showMA); PlotIndexSetInteger(maFastBufferPlotIndex, PLOT_SHOW_DATA, showMAFast);
PlotIndexSetDouble(maBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); PlotIndexSetDouble(maFastBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
// //
ArraySetAsSeries(maColorBuffer, true); ArraySetAsSeries(maFastColorBuffer, true);
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX); SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX);
// //
ArraySetAsSeries(maStateBuffer, true); ArraySetAsSeries(maFastStateBuffer, true);
SetIndexBuffer(maStateBufferIndex, maStateBuffer, INDICATOR_CALCULATIONS); SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow MA ...
//
ArraySetAsSeries(maSlowBuffer, true);
SetIndexBuffer(maSlowBufferIndex, maSlowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(maSlowBufferPlotIndex, PLOT_SHOW_DATA, showMASlow);
PlotIndexSetDouble(maSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
ArraySetAsSeries(maSlowColorBuffer, true);
SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(maSlowStateBuffer, true);
SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS);
// //
// SAR ... // SAR ...
@@ -879,16 +931,32 @@ bool InitRequirements()
// Handlers ... // Handlers ...
// //
// MA ... // Fast MA ...
maHandler = iMA( maFastHandler = iMA(
_Symbol, _Symbol,
_Period, _Period,
maLength, maFastLength,
0, 0,
maMethod, maMethod,
maAppliedTo // maAppliedTo //
); );
result = maHandler != INVALID_HANDLE; result = maFastHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// Slow MA ...
maSlowHandler = iMA(
_Symbol,
_Period,
maSlowLength,
0,
maMethod,
maAppliedTo //
);
result = maSlowHandler != INVALID_HANDLE;
if (!result) if (!result)
{ {
return result; return result;
@@ -1053,22 +1121,40 @@ void CalculateValues(
); );
// //
// MA ... // Fast MA ...
double iMa = maBuffer[barIndex]; double iFastMa = maFastBuffer[barIndex];
double maState = close[barIndex] > iMa double maFastState = close[barIndex] > iFastMa
? bullishState ? bullishState
: close[barIndex] < iMa : close[barIndex] < iFastMa
? bearishState ? bearishState
: neuturalState; : neuturalState;
double maColor = close[barIndex] > iMa double maFastColor = close[barIndex] > iFastMa
? bullishColorIDX ? bullishColorIDX
: close[barIndex] < iMa : close[barIndex] < iFastMa
? bearishColorIDX ? bearishColorIDX
: neuturalColorIDX; : neuturalColorIDX;
maStateBuffer[barIndex] = maState; maFastStateBuffer[barIndex] = maFastState;
maColorBuffer[barIndex] = showMA maFastColorBuffer[barIndex] = showMAFast
? maColor ? maFastColor
: hideColorIDX; : hideColorIDX;
//
// Slow MA ...
double iSlowMa = maSlowBuffer[barIndex];
double maSlowState = close[barIndex] > iSlowMa
? bullishState
: close[barIndex] < iSlowMa
? bearishState
: neuturalState;
double maSlowColor = close[barIndex] > iSlowMa
? bullishColorIDX
: close[barIndex] < iSlowMa
? bearishColorIDX
: neuturalColorIDX;
maSlowStateBuffer[barIndex] = maSlowState;
maSlowColorBuffer[barIndex] = showMASlow
? maSlowColor
: hideColorIDX;
// //
// SAR ... // SAR ...
File diff suppressed because it is too large Load Diff
+619 -20
View File
@@ -24,6 +24,8 @@
// Imports ... // Imports ...
#include "../../Classes/x-saherelm.base.class.mq5" #include "../../Classes/x-saherelm.base.class.mq5"
#include "../../Classes/x-saherelm.x-alert.class.mq5" #include "../../Classes/x-saherelm.x-alert.class.mq5"
#include "../../Classes/x-saherelm.x-guard.class.mq5"
#include "../../Classes/x-saherelm.x-trade-manager.class.mq5"
#include "../../Classes/x-saherelm.x-volume.class.mq5" #include "../../Classes/x-saherelm.x-volume.class.mq5"
#include "../Classes/xom1ea.signaller.class.mq5" #include "../Classes/xom1ea.signaller.class.mq5"
@@ -46,6 +48,22 @@ class XCXOM1EAExpert : public XCBase
int eaSlippage; // Slippgae int eaSlippage; // Slippgae
string eaLogSuffix; // Log Suffix string eaLogSuffix; // Log Suffix
//
// Management ...
bool eaAllowGuards; // Allow Guards
bool eaAllowTrade; // Allow Trade on Signals
bool eaAllowLongs; // Allow Long Trades
bool eaAllowShorts; // Allow Short Trades
string eaSessions; // Active Sessions
ENUM_XTRADE_RESTRICTION_PERIOD eaRestrictionsPeriod; // Restrictions Period
int eaMaxAllowedTPs; // Max Allowed TP(s) in Restrictions Period
int eaMaxAllowedSLs; // Max Allowed SL(s) in Restrictions Period
int eaMaxAllowedTrades; // Max Allowed Trades in Restrictions Period
int eaMaxAllowedPositions; // Max Allowed Same Time Trades
double eaMaxAllowedSpread; // Max Allowed Spread For Trade
double eaMaxAllowedDrawdownFactor; // Max Allowed DrawDown for Trade
string eaCloseAllOpenTradesAt; // Close All Open Trades per Day At Specified Time
// //
// Volume ... // Volume ...
ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect; // Volume Applying Type ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect; // Volume Applying Type
@@ -65,12 +83,195 @@ class XCXOM1EAExpert : public XCBase
bool eaPushAlerts; // Push Alerts bool eaPushAlerts; // Push Alerts
bool eaTerminalAlerts; // Terminal Alerts bool eaTerminalAlerts; // Terminal Alerts
//
// Reports ...
bool eaReportNewMonths; // Report New Month
bool eaReportNewWeeks; // Report New Weeks
bool eaReportNewDays; // Report New Days
bool eaReportNewHours; // Report New Hours
bool eaReportTrades; // Report Trades
bool eaReportSignals; // Report Signals
bool eaReportProtector; // Report Protector Actions
bool eaReportRestrictions; // Report Restrictions
bool eaReportAfterTradesBalance; // Report Balance after a Trade Finished
//
// Collector ...
bool eaSaveTrades; // Save Trades
bool eaSaveSignals; // Save Signals
bool eaSaveWins; // Save Winning Conditions
bool eaSaveLosts; // Save Lost Conditions
bool eaSaveRestrictions; // Save Restriction Reports
// //
// Requirements ... // Requirements ...
// //
XCAlert *eaAlert; // EA Scope Alert Handler ... XCAlert *eaAlert; // EA Scope Alert Handler ...
XCVolume *eaVolume; // EA Scope Voluem Handler ... XCVolume *eaVolume; // EA Scope Voluem Handler ...
XCGuard *eaGuard; // EA Scope Guard Handler ...
XCTrade *eaTrade; // EA Scope Trade Handler ...
XCTradeManager *eaTradeManager; // EA Scope Trade Handler ...
XTimeTracker eaTimeTracker; // EA Scope Time Tracker ...
//
// Tools / Actions / Handlers ...
//
// Trade Event Handlers ...
//
void AddOnStopLossEventHandler(TOnStopLoss handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mStopLossEventHandlers
//
);
}
//
void AddOnTakeProfitEventHandler(TOnTakeProfit handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mTakeProfitEventHandlers
//
);
}
//
void AddOnDealsChangedEventHandler(TOnDealsChanged handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mDealsChangedEventHandlers
//
);
}
//
void AddOnOrdersChangedEventHandler(TOnOrdersChanged handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mOrdersChangedEventHandlers
//
);
}
//
void AddOnModifyPositionEventHandler(TOnModify handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mOnModifyEventHandlers
//
);
}
//
void AddOnPositionsChangedEventHandler(TOnPositionsChanged handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mPositionsChangedEventHandlers
//
);
}
//
void AddOnTradeStateChangedEventHandler(TOnTradeStateChanged handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mTradeStateChangedEventHandlers
//
);
}
//
void AddOnForceClosePositionEventHandler(TOnForceClose handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mOnForceCloseEventHandlers
//
);
}
//
void AddOnPartialClosePositionEventHandler(TOnPartialClose handler)
{
//
if (handler == NULL)
{
return;
}
//
Add(
handler,
mOnPartialCloseEventHandlers
//
);
}
// //
// Validators ... // Validators ...
@@ -114,6 +315,10 @@ class XCXOM1EAExpert : public XCBase
return result; return result;
} }
//
int count = 0;
bool has = false;
// //
// Initialize Alert Handler ... // Initialize Alert Handler ...
eaAlert = new XCAlert(); eaAlert = new XCAlert();
@@ -127,20 +332,209 @@ class XCXOM1EAExpert : public XCBase
// //
// Initialize Volume Manager ... // Initialize Volume Manager ...
// eaVolume = new XCVolume(); eaVolume = new XCVolume();
// result = eaVolume.Init( result = eaVolume.Init(
// eaVolumeSelect, eaVolumeSelect,
// eaStaticVoluem, eaStaticVoluem,
// eaDynamicVolumeStepBalance, eaDynamicVolumeStepBalance,
// eaDynamicVolumeStepVolume, eaDynamicVolumeStepVolume,
// eaConstantRiskBalance, eaConstantRiskBalance,
// eaConstantPercent, eaConstantPercent,
// eaConstantBalance // eaConstantBalance //
// ); );
// if (!result) if (!result)
// { {
// return result; return result;
// } }
//
// Initialize Trader ...
eaTrade = new XCTrade(
eaSlippage,
eaMagicNumber,
eaMaxAllowedSpread,
eaMaxAllowedPositions,
eaMaxAllowedDrawdownFactor //
);
//
// Trade Handler Attachments ...
//
// Position Modifiy Event Handlers ...
count = ArraySize(mOnModifyEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnModifyPositionEventHandler(mOnModifyEventHandlers[i]);
}
}
//
// Position Stop Loss Event Handlers ...
count = ArraySize(mStopLossEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnStopLossEventHandler(mStopLossEventHandlers[i]);
}
}
//
// Position Take Profit Event Handlers ...
count = ArraySize(mTakeProfitEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnTakeProfitEventHandler(mTakeProfitEventHandlers[i]);
}
}
//
// Position Force Close Event Handlers ...
count = ArraySize(mOnForceCloseEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnForceClosePositionEventHandler(mOnForceCloseEventHandlers[i]);
}
}
//
// Deals Changed Event Handlers ...
count = ArraySize(mDealsChangedEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnDealsChangedEventHandler(mDealsChangedEventHandlers[i]);
}
}
//
// Orders Changed Event Handlers ...
count = ArraySize(mOrdersChangedEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnOrdersChangedEventHandler(mOrdersChangedEventHandlers[i]);
}
}
//
// Positions Changed Event Handlers ...
count = ArraySize(mPositionsChangedEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnPositionsChangedEventHandler(mPositionsChangedEventHandlers[i]);
}
}
//
// Trade Changed Event Handlers ...
count = ArraySize(mTradeStateChangedEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnTradeStateChangedEventHandler(mTradeStateChangedEventHandlers[i]);
}
}
//
// Postion Partially Close Event Handlers ...
count = ArraySize(mOnPartialCloseEventHandlers);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
eaTrade.AddOnPartialClosePositionEventHandler(mOnPartialCloseEventHandlers[i]);
}
}
//
// Initialize Guard Handler ...
eaGuard = new XCGuard(
eaAlert,
eaTrade //
);
//
// Initialize Trae Manager ...
eaTradeManager = new XCTradeManager(
eaAlert,
eaTrade,
eaGuard //
);
//
// Configuring Trade Manager ...
//
eaTradeManager.SaveWins(eaSaveWins);
eaTradeManager.SaveLosts(eaSaveLosts);
eaTradeManager.SaveTrades(eaSaveTrades);
eaTradeManager.SaveSignals(eaSaveSignals);
eaTradeManager.SaveRestrictions(eaSaveRestrictions);
//
// Enable Force Close At ...
eaTradeManager.SetForceCloseTradesAt(eaCloseAllOpenTradesAt);
//
// Setting Trade Reports ...
eaTradeManager
.SetTradeReports(
eaReportTrades,
eaReportSignals,
eaReportProtector,
eaReportRestrictions,
eaReportAfterTradesBalance //
);
//
// Setting Trade Permissions ...
eaTradeManager
.SetTradePermissions(
eaAllowTrade,
eaAllowLongs,
eaAllowShorts //
);
//
// Setting Trade Restrictions ...
eaTradeManager
.SetTradeRestrictions(
eaRestrictionsPeriod,
eaMaxAllowedTPs,
eaMaxAllowedSLs,
eaMaxAllowedTrades //
);
// //
// Here we Apply Symbols,Periods and Configs ... // Here we Apply Symbols,Periods and Configs ...
@@ -171,7 +565,7 @@ class XCXOM1EAExpert : public XCBase
// Register Signaller ... // Register Signaller ...
Add( Add(
iDZoneSignaller, iDZoneSignaller,
signallers // eaSignallers //
); );
} }
@@ -192,10 +586,28 @@ class XCXOM1EAExpert : public XCBase
{ {
// //
//
delete eaTrade;
ZeroMemory(eaTrade);
//
delete eaGuard;
ZeroMemory(eaGuard);
// //
delete eaVolume; delete eaVolume;
ZeroMemory(eaVolume); ZeroMemory(eaVolume);
//
delete eaTradeManager;
ZeroMemory(eaTradeManager);
//
eaTimeTracker.Clean();
//
Clean(eaSignallers);
// //
string message = "DeInitialized Successfully ..."; string message = "DeInitialized Successfully ...";
eaAlert.SendAlert(message); eaAlert.SendAlert(message);
@@ -211,7 +623,7 @@ class XCXOM1EAExpert : public XCBase
void HandleOnTick() void HandleOnTick()
{ {
// //
int count = ArraySize(signallers); int count = ArraySize(eaSignallers);
bool has = IsValidSize(count); bool has = IsValidSize(count);
if (!has) if (!has)
{ {
@@ -224,7 +636,7 @@ class XCXOM1EAExpert : public XCBase
{ {
// //
// Calling Process Ticks on Signaller ... // Calling Process Ticks on Signaller ...
signallers[i].ProcessTick(0); eaSignallers[i].ProcessTick(0);
} }
} }
@@ -262,9 +674,185 @@ class XCXOM1EAExpert : public XCBase
// //
// Trade Event Handlers ... // Trade Event Handlers ...
/**
* Handle Stop Loss Event Triggered ...
*
* @param deal: XDeal instance refrence, provides Triggered Deal info ...
*/
void HandleOnStopLossTriggered(const XDeal &deal)
{
eaTradeManager.HandleSL(deal);
}
/**
* Handle Take Profit Event Triggered ...
*
* @param deal: XDeal instance refrence, provides Triggered Deal info ...
*/
void HandleOnTakeProfitTriggered(const XDeal &deal)
{
eaTradeManager.HandleTP(deal);
}
/**
* Handle Position Force Closed Event ...
*
* @param ticket: ulong, triggered Positions ticket ...
* @param position: XPosition instance refrence, Triggered Position ...
* @param comment: string, Comment ...
*/
void HandleOnPositionForceClosed(
const ulong ticket,
const XPosition &position,
const string comment //
)
{
eaTradeManager.HandleForceClose(position);
}
/**
* Handle Position Partially Closed Event ...
*
* @param ticket: ulong, triggered Positions ticket ...
* @param profit: double, Position Profit ...
* @param comment: string, Comment ...
*/
void HandleOnPositionPartialClosed(
const ulong ticket,
const double profit,
const string comment //
)
{
//
eaTradeManager.HandlePartiallyClosed(
ticket,
profit,
comment //
);
}
/**
* Handle Deals Changed ...
*
* @param count: int, number of changes ...
* if the count is positive, means new added ...
* if the count is negative, means removed ...
*/
void HandleOnDealsChanged(int count)
{
}
/**
* Handle Orders Changed ...
*
* @param count: int, number of changes ...
* if the count is positive, means new added ...
* if the count is negative, means removed ...
*/
void HandleOnOrdersChanged(int count)
{
}
/**
* Handle Positions Changed ...
*
* @param count: int, number of changes ...
* if the count is positive, means new added ...
* if the count is negative, means removed ...
*/
void HandleOnPositionsChanged(int count)
{
}
/**
* Handle Position Modified Event ...
*
* @param ticket: ulong, triggered Positions ticket ...
* @param profit: double, Position Profit ...
* @param comment: string, Comment ...
*/
void HandleOnPositionModified(
const ulong ticket,
const double profit,
const string comment //
)
{
}
/**
* Handle all Trades States Changed Event ...
*
* @param state: XOnTradeHandlerState instance refrence, Changed Trade State data ...
*/
void HandleOnTradeStateChanged(const XOnTradeHandlerState &state)
{
}
// //
// Protected ... // Protected ...
protected: protected:
//
/**
* Report Time Changes based on Given Configurations ...
*/
void HandleTimeReport()
{
//
if (eaAlert == NULL)
{
return;
}
//
// Monthly Report ....
if (eaReportNewMonths &&
eaTimeTracker.IsNewMonth())
{
//
string msg = "New Month ...";
//
eaAlert.SendAlert(msg);
}
//
// Weekly Report ....
if (eaReportNewWeeks &&
eaTimeTracker.IsNewWeek())
{
//
string msg = "New Week ...";
//
eaAlert.SendAlert(msg);
}
//
// Daily Report ....
if (eaReportNewDays &&
eaTimeTracker.IsNewDay())
{
//
string msg = "New Day ...";
//
eaAlert.SendAlert(msg);
}
//
// Hourly Report ....
if (eaReportNewHours &&
eaTimeTracker.IsNewHour())
{
//
string msg = "New Hour ...";
//
eaAlert.SendAlert(msg);
}
}
// //
// Private ... // Private ...
private: private:
@@ -272,7 +860,18 @@ class XCXOM1EAExpert : public XCBase
// Props ... // Props ...
// //
XCXOM1SignallerBase *signallers[]; // All Registered Signallers ... TOnModify mOnModifyEventHandlers[];
TOnStopLoss mStopLossEventHandlers[];
TOnTakeProfit mTakeProfitEventHandlers[];
TOnForceClose mOnForceCloseEventHandlers[];
TOnDealsChanged mDealsChangedEventHandlers[];
TOnOrdersChanged mOrdersChangedEventHandlers[];
TOnPartialClose mOnPartialCloseEventHandlers[];
TOnPositionsChanged mPositionsChangedEventHandlers[];
TOnTradeStateChanged mTradeStateChangedEventHandlers[];
//
XCXOM1SignallerBase *eaSignallers[]; // All Registered Signallers ...
}; };
// //