last ...
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
// Imports ...
|
||||
#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 "../XSTRCCI/Classes/xstrcci.x-trade.manager.class.mq5"
|
||||
#include "../XSTRCCI/Signals/xstrcci.signaller.class.mq5"
|
||||
|
||||
//
|
||||
@@ -37,6 +39,17 @@ input long eaMagicNumber = 78692110; // Magic Number
|
||||
input int eaSlippage = 10; // Slippgae
|
||||
input string eaLogSuffix = ""; // Log Suffix
|
||||
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
// Here we Provider All Requirements for
|
||||
@@ -60,6 +73,8 @@ input bool eaReportNewHours = false; // Report New Hours
|
||||
// Variables, Instances ...
|
||||
XCAlert *eaAlert;
|
||||
XCTrade *eaTrade;
|
||||
XCVolume *eaVolume;
|
||||
XCXSTRCCITradeManager *eaTradeManager;
|
||||
|
||||
//
|
||||
XSignal eaSignal;
|
||||
@@ -100,6 +115,13 @@ int OnInit()
|
||||
// Initial Requirements ...
|
||||
InitRequirements();
|
||||
|
||||
//
|
||||
// Initialize Volume Manger ...
|
||||
if (!InitVolume())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
@@ -122,7 +144,17 @@ void OnDeinit(const int reason)
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Destroy Timer ...
|
||||
ZeroMemory(eaAlert);
|
||||
ZeroMemory(eaTrade);
|
||||
ZeroMemory(eaVolume);
|
||||
ZeroMemory(eaSignaller);
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
DestroyTimer();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -134,18 +166,16 @@ void OnTick()
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Handle Position Management / Protections ...
|
||||
eaTradeManager.Manage();
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
double sl = 0;
|
||||
double tp = 0;
|
||||
double r2r = 5;
|
||||
double risk = 0;
|
||||
double entry = 0;
|
||||
double reward = 0;
|
||||
double volume = 0.01;
|
||||
string provider = "XSTRCCI";
|
||||
ENUM_POSITION_TYPE type = POSITION_TYPE_BUY;
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
@@ -154,9 +184,6 @@ void OnTick()
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
double selectedSL = 0;
|
||||
|
||||
//
|
||||
// Start Calculations ...
|
||||
|
||||
@@ -239,6 +266,23 @@ void OnTick()
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Time to Conditions ...
|
||||
eaConditions.time = cTime;
|
||||
has = ToPositionType(
|
||||
type,
|
||||
eaConditions.type //
|
||||
);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Checking Trigger Direction ...
|
||||
hasLong = eaConditions.HasBullishSignal();
|
||||
@@ -248,23 +292,29 @@ void OnTick()
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
eaSignal.Clean();
|
||||
eaConditions.Clean();
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Preparing Signal ...
|
||||
//
|
||||
eaSignal.sl = sl;
|
||||
eaSignal.tp = tp;
|
||||
eaSignal.type = type;
|
||||
eaSignal.mode = mode;
|
||||
eaSignal.entry = entry;
|
||||
eaSignal.volume = volume;
|
||||
eaSignal.symbol = symbol;
|
||||
eaSignal.period = period;
|
||||
eaSignal.type = type;
|
||||
eaSignal.entry = GetEntry(
|
||||
eaConditions.symbol,
|
||||
eaConditions.dir //
|
||||
);
|
||||
eaSignal.provider = provider;
|
||||
eaSignal.time = TimeCurrent();
|
||||
eaSignal.sl = eaConditions.sl;
|
||||
eaSignal.tp = eaConditions.tp;
|
||||
eaSignal.volume = X_MIN_VOLUME;
|
||||
eaSignal.time = eaConditions.time;
|
||||
eaSignal.symbol = eaConditions.symbol;
|
||||
eaSignal.period = eaConditions.period;
|
||||
|
||||
//
|
||||
Copy(
|
||||
@@ -282,6 +332,15 @@ void OnTick()
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Volume Management ...
|
||||
double iVolume = eaVolume.CalculateVolume(eaSignal);
|
||||
if (iVolume > X_MIN_VOLUME &&
|
||||
iVolume != eaSignal.volume)
|
||||
{
|
||||
eaSignal.volume = iVolume;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Signal ...
|
||||
|
||||
@@ -289,7 +348,16 @@ void OnTick()
|
||||
// Execute Signal ...
|
||||
|
||||
//
|
||||
Print("Execute Signal ...");
|
||||
has =eaTradeManager.Execute(
|
||||
eaSignal,
|
||||
eaConditions //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Do What we Want on Successfully Execution Signal ...
|
||||
Print("Signal Executed ...");
|
||||
}
|
||||
|
||||
//
|
||||
eaSignal.Clean();
|
||||
@@ -329,6 +397,7 @@ void OnChartEvent(
|
||||
*/
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleSL(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,6 +407,7 @@ void OnStopLossTriggered(const XDeal &deal)
|
||||
*/
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
eaTradeManager.HandleTP(deal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,6 +423,7 @@ void OnPositionForceClosed(
|
||||
const string comment //
|
||||
)
|
||||
{
|
||||
eaTradeManager.HandleForceClose(position);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,6 +535,34 @@ void DestroyTimer()
|
||||
// EventKillTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Volume Manager Class Based on Given Configuration ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitVolume()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
eaVolume = new XCVolume();
|
||||
|
||||
//
|
||||
result = eaVolume.Init(
|
||||
eaVolumeSelect,
|
||||
eaStaticVoluem,
|
||||
eaDynamicVolumeStepBalance,
|
||||
eaDynamicVolumeStepVolume,
|
||||
eaConstantRiskBalance,
|
||||
eaConstantPercent,
|
||||
eaConstantBalance //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Requirements of EA ...
|
||||
*
|
||||
@@ -498,6 +597,21 @@ void InitRequirements()
|
||||
eaMaxAllowedPositions,
|
||||
eaMaxAllowedDrawdownFactor //
|
||||
);
|
||||
eaTrade.AddOnStopLossEventHandler(OnStopLossTriggered);
|
||||
eaTrade.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
|
||||
eaTrade.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
|
||||
|
||||
//
|
||||
// EA Trae Manager ...
|
||||
eaTradeManager = new XCXSTRCCITradeManager(
|
||||
eaTrade //
|
||||
);
|
||||
eaTradeManager.SetAlertEnableAlerts(eaEnableAlerts);
|
||||
eaTradeManager.SetAlertPrefix(eaTag);
|
||||
eaTradeManager.SetAlertLogAlerts(eaLogAlerts);
|
||||
eaTradeManager.SetAlertMailAlerts(eaMailAlerts);
|
||||
eaTradeManager.SetAlertPushAlerts(eaPushAlerts);
|
||||
eaTradeManager.SetAlertTerminalAlerts(eaTerminalAlerts);
|
||||
|
||||
//
|
||||
// EA Signaller ...
|
||||
|
||||
Reference in New Issue
Block a user