Refactor XCObjects and Extends them from Base XCObject Class and also Implement GUI Features on EA Class and Refactor Inputs ...
This commit is contained in:
+688
-84
@@ -93,7 +93,7 @@ input int eaDelayBarBetweenTwoSameSignal = 5; // Delay Bars Between Two Same Typ
|
||||
//
|
||||
// Protector > Hedging Properties ...
|
||||
input group "Hedging";
|
||||
input bool eaAllowHedge = true; // Allow Protector to Hedge Positions
|
||||
input bool eaAllowHedge = true; // Allow Hedge Positions
|
||||
input double eaHedgeMinVolumeStep = 0.01; // Minimum Volume Step For Hedge
|
||||
input int eaMinimumOpenPositionsForHEHedge = 2; // Minimum Open Positions For HE Hedge
|
||||
input double eaHedgeHEMinProfitPerVolumeStep = 1; // Minimum Required Profit For HE Hedge Per Volume Step
|
||||
@@ -144,11 +144,11 @@ input group "In Drawdown Positions Protecting";
|
||||
// Protect ...
|
||||
input group "Protect";
|
||||
input bool eaAllowProtect = true; // Allow Proptecting
|
||||
input int eaProtectionDelay = 60; // Delay Between two Protection in Secconds
|
||||
input int eaProtectionDelay = 300; // Delay Between two Protection in Secconds
|
||||
input bool eaProtectOnConditions = true; // Do Protection only when Conditions happens
|
||||
input bool eaAllowDirectionProtct = false; // Allow also Directional Protect
|
||||
input double eaProtectionStartDistance = 50; // Protection Start Drawdown in Profit
|
||||
input double eaProtectionVolumeMultiplier = 2; // Protection Volume Multiplier
|
||||
input double eaProtectionStartDistance = 100; // Protection Start Drawdown in Profit
|
||||
input double eaProtectionVolumeMultiplier = 1; // Protection Volume Multiplier
|
||||
|
||||
//
|
||||
// Partial Close (In Drawdown) ...
|
||||
@@ -203,14 +203,6 @@ XTimeTracker eaTimeTracker;
|
||||
// Trade Handler Instance Class ...
|
||||
X121SCTradeHandler *eaTradeHandler;
|
||||
|
||||
//
|
||||
// Panel of EA ...
|
||||
XCPanel eaPanel;
|
||||
XCButton eaStateButton;
|
||||
string eaStateButtonTitle;
|
||||
bool eaEnableLongs = true;
|
||||
bool eaEnableShorts = true;
|
||||
|
||||
//
|
||||
string mTag = "";
|
||||
|
||||
@@ -219,6 +211,25 @@ double eaR2R = 1.5;
|
||||
datetime lastSignalOn = NULL;
|
||||
bool eaUseFixedTPSLPoints = true;
|
||||
|
||||
//
|
||||
// SIGNALLING GUI ...
|
||||
XCPanel eaSignallingPanel;
|
||||
XCButton eaSignallingBtn;
|
||||
XCButton eaSignallingLongBtn;
|
||||
XCButton eaSignallingShortBtn;
|
||||
bool eaEnableLongs = eaAllowLong && eaMaxAllowedLongs >= 0;
|
||||
bool eaEnableShorts = eaAllowShort && eaMaxAllowedShorts >= 0;
|
||||
|
||||
//
|
||||
// PROTECTOR GUI ...
|
||||
XCPanel eaProtectorPanel;
|
||||
XCButton eaHedgingBtn;
|
||||
XCButton eaTraillingBtn;
|
||||
XCButton eaProtectingBtn;
|
||||
bool eaEnableHedging = false;
|
||||
bool eaEnableTrailling = false;
|
||||
bool eaEnableProtecting = false;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
@@ -233,7 +244,7 @@ int OnInit()
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitialEA())
|
||||
if (!InitEA())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
@@ -252,8 +263,7 @@ int OnInit()
|
||||
// EventSetMillisecondTimer(100);
|
||||
|
||||
//
|
||||
// Create Panel for EA Data ...
|
||||
if (!InitialPanel())
|
||||
if (!InitGUI())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
@@ -300,7 +310,7 @@ void OnDeinit(const int reason)
|
||||
delete eaTradeHandler;
|
||||
|
||||
//
|
||||
eaPanel.Destroy();
|
||||
DestroyGUI();
|
||||
|
||||
//
|
||||
Clean(strategies);
|
||||
@@ -311,9 +321,9 @@ void OnDeinit(const int reason)
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
UpdateGUI();
|
||||
HandleTradeState();
|
||||
HandleTimeReport();
|
||||
HandlePanelUpdate();
|
||||
HandleStrategiesOnTick();
|
||||
}
|
||||
|
||||
@@ -344,12 +354,16 @@ void OnChartEvent(
|
||||
)
|
||||
{
|
||||
//
|
||||
eaPanel.OnEvent(
|
||||
id,
|
||||
lparam,
|
||||
dparam,
|
||||
sparam //
|
||||
);
|
||||
// Handle Panel Removing ...
|
||||
eaProtectorPanel.OnEvent(id, lparam, dparam, sparam);
|
||||
eaSignallingPanel.OnEvent(id, lparam, dparam, sparam);
|
||||
|
||||
//
|
||||
// Handle OnClick Event ...
|
||||
if (id == CHARTEVENT_OBJECT_CLICK)
|
||||
{
|
||||
HandleOnClickEvent(sparam);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -468,45 +482,9 @@ bool ValidateInputs()
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool InitialPanel()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Create a Panel ...
|
||||
result = eaPanel.Create(
|
||||
mTag,
|
||||
100,
|
||||
100,
|
||||
300,
|
||||
200 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Activation Button ...
|
||||
string eaStatePrefix = mTag + "_State_";
|
||||
eaStateButtonTitle = eaStatePrefix + "lbl";
|
||||
result = eaStateButton.Create(
|
||||
eaStateButtonTitle,
|
||||
100,
|
||||
120,
|
||||
100,
|
||||
25 //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize all Requirements ...
|
||||
bool InitialEA()
|
||||
bool InitEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
@@ -875,25 +853,53 @@ bool InitialEA()
|
||||
}
|
||||
|
||||
//
|
||||
// Register Strategy ...
|
||||
void RegisterStrategy(XSCBaseStrategy *strategy)
|
||||
// Initial GUI ...
|
||||
bool InitGUI()
|
||||
{
|
||||
//
|
||||
if (strategy == NULL)
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Initial Signalling GUI ...
|
||||
result = InitSignallingGUI();
|
||||
if (!result)
|
||||
{
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
strategies,
|
||||
ArraySize(strategies) + 1 //
|
||||
);
|
||||
// Initial Protector GUI ...
|
||||
result = InitProtectorGUI();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
strategies[ArraySize(strategies) - 1] = strategy;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Update GUi ...
|
||||
void UpdateGUI()
|
||||
{
|
||||
//
|
||||
UpdateProtectorGUI();
|
||||
UpdateSignallingGUI();
|
||||
}
|
||||
|
||||
//
|
||||
// Destroy GUI ...
|
||||
void DestroyGUI()
|
||||
{
|
||||
//
|
||||
DestroyProtectorGUI();
|
||||
DestroySignallingGUI();
|
||||
}
|
||||
|
||||
//
|
||||
// HANDLERS ...
|
||||
|
||||
//
|
||||
// Call All Registered Strategis Tick Handler Functions ...
|
||||
void HandleStrategiesOnTick()
|
||||
@@ -981,21 +987,97 @@ void HandleTimeReport()
|
||||
}
|
||||
|
||||
//
|
||||
// Update Panel ...
|
||||
void HandlePanelUpdate()
|
||||
// Report Account Balance ...
|
||||
void HandleReportBalance()
|
||||
{
|
||||
//
|
||||
// Prepare State ...
|
||||
bool isEnable = eaEnableLongs ||
|
||||
eaEnableShorts;
|
||||
if (!IsRunningOnTestMode())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string stateStr = isEnable ? "Active" : "Inactive";
|
||||
string msg = "Balance: " + ToString(eaTrader.mAccount.GetBalance());
|
||||
eaAlert.Log(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Click Event for GUI Components ...
|
||||
void HandleOnClickEvent(string name)
|
||||
{
|
||||
//
|
||||
if (!IsValid(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClicked = false;
|
||||
|
||||
//
|
||||
// Signalling State Button ...
|
||||
if (name == eaSignallingBtn.Name())
|
||||
{
|
||||
//
|
||||
isClicked = true;
|
||||
HandleChangeState();
|
||||
eaSignallingBtn.State(false);
|
||||
}
|
||||
//
|
||||
// Long Signalling State ...
|
||||
else if (name == eaSignallingLongBtn.Name())
|
||||
{
|
||||
//
|
||||
isClicked = true;
|
||||
HandleChangeLongsState();
|
||||
eaSignallingLongBtn.State(false);
|
||||
}
|
||||
//
|
||||
// Short Signalling State ...
|
||||
else if (name == eaSignallingShortBtn.Name())
|
||||
{
|
||||
//
|
||||
isClicked = true;
|
||||
HandleChangeShortsState();
|
||||
eaSignallingShortBtn.State(false);
|
||||
}
|
||||
//
|
||||
// Hedging State Button ...
|
||||
else if (name == eaHedgingBtn.Name())
|
||||
{
|
||||
//
|
||||
isClicked = true;
|
||||
HandleChangeHedgingState();
|
||||
eaHedgingBtn.State(false);
|
||||
}
|
||||
//
|
||||
// Trailling State Button ...
|
||||
else if (name == eaTraillingBtn.Name())
|
||||
{
|
||||
//
|
||||
isClicked = true;
|
||||
HandleChangeTraillingState();
|
||||
eaTraillingBtn.State(false);
|
||||
}
|
||||
//
|
||||
// Protecting State Button ...
|
||||
else if (name == eaProtectingBtn.Name())
|
||||
{
|
||||
//
|
||||
isClicked = true;
|
||||
HandleChangeProtectingState();
|
||||
eaProtectingBtn.State(false);
|
||||
}
|
||||
|
||||
//
|
||||
if (isClicked)
|
||||
{
|
||||
UpdateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNAL EVENT Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// All Signals from Strategies Comming Here for Execution or
|
||||
@@ -1167,7 +1249,7 @@ void OnStopLossTriggered(const XDeal &deal)
|
||||
eaTradeHandler.Finish(deal);
|
||||
|
||||
//
|
||||
ReportBalance();
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1179,7 +1261,7 @@ void OnTakeProfitTriggered(const XDeal &deal)
|
||||
eaTradeHandler.Finish(deal);
|
||||
|
||||
//
|
||||
ReportBalance();
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1199,22 +1281,544 @@ void OnPositionForceClosed(
|
||||
);
|
||||
|
||||
//
|
||||
ReportBalance();
|
||||
HandleReportBalance();
|
||||
}
|
||||
|
||||
//
|
||||
// Report Account Balance ...
|
||||
void ReportBalance()
|
||||
// HELPERS ...
|
||||
|
||||
//
|
||||
// Register Strategy ...
|
||||
void RegisterStrategy(XSCBaseStrategy *strategy)
|
||||
{
|
||||
//
|
||||
if (!IsRunningOnTestMode())
|
||||
if (strategy == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string msg = "Balance: " + ToString(eaTrader.mAccount.GetBalance());
|
||||
eaAlert.Log(msg);
|
||||
ArrayResize(
|
||||
strategies,
|
||||
ArraySize(strategies) + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
strategies[ArraySize(strategies) - 1] = strategy;
|
||||
}
|
||||
|
||||
//
|
||||
// GUI Parts ...
|
||||
|
||||
//
|
||||
// SIGNALLING GUI ...
|
||||
|
||||
/**
|
||||
* Initialize State and Signalling GUI ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitSignallingGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string eaSignallingPanelName = mTag + "SIGNALLING";
|
||||
|
||||
//
|
||||
// Create a Panel ...
|
||||
result = eaSignallingPanel.Create(
|
||||
eaSignallingPanelName,
|
||||
10,
|
||||
40,
|
||||
300,
|
||||
50 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaSignallingPanel.Caption("Signalling");
|
||||
|
||||
//
|
||||
// Create Activation Button ...
|
||||
string eaSignallingPrefix = eaSignallingPanelName + "_";
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
string eaSignallingBtnName = eaSignallingPrefix + "btn";
|
||||
result = eaSignallingBtn.Create(
|
||||
eaSignallingBtnName,
|
||||
10,
|
||||
60,
|
||||
300,
|
||||
25 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaSignallingBtn.Text("");
|
||||
eaSignallingPanel.Add(eaSignallingBtnName);
|
||||
|
||||
//
|
||||
// Long Signalling ...
|
||||
string eaSignallingLongBtnName = eaSignallingPrefix + "_Long_btn";
|
||||
result = eaSignallingLongBtn.Create(
|
||||
eaSignallingLongBtnName,
|
||||
10,
|
||||
85,
|
||||
150,
|
||||
25 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaSignallingLongBtn.Text("");
|
||||
eaSignallingPanel.Add(eaSignallingLongBtnName);
|
||||
|
||||
//
|
||||
// Short Signalling ...
|
||||
string eaSignallingShortBtnName = eaSignallingPrefix + "_Short_btn";
|
||||
result = eaSignallingShortBtn.Create(
|
||||
eaSignallingShortBtnName,
|
||||
160,
|
||||
85,
|
||||
150,
|
||||
25 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaSignallingShortBtn.Text("");
|
||||
eaSignallingPanel.Add(eaSignallingShortBtnName);
|
||||
|
||||
//
|
||||
UpdateSignallingGUI();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Signalling GUI Content ...
|
||||
*/
|
||||
void UpdateSignallingGUI()
|
||||
{
|
||||
//
|
||||
// Preparing State ...
|
||||
bool isSignallingActive = eaEnableLongs ||
|
||||
eaEnableShorts;
|
||||
|
||||
//
|
||||
// All Signalls ...
|
||||
color mSignallingBtnTextColor = isSignallingActive
|
||||
? clrRed
|
||||
: clrGreen;
|
||||
string mSignallingBtnText = isSignallingActive
|
||||
? "Deactive"
|
||||
: "Active";
|
||||
eaSignallingBtn.Text(mSignallingBtnText);
|
||||
eaSignallingBtn.Color(mSignallingBtnTextColor);
|
||||
|
||||
//
|
||||
// Long Signals ...
|
||||
color mSignallingLongBtnTextColor = eaEnableLongs
|
||||
? clrRed
|
||||
: clrGreen;
|
||||
string mSignallingLongBtnText = eaEnableLongs
|
||||
? "Deactive Longs"
|
||||
: "Active Longs";
|
||||
eaSignallingLongBtn.Text(mSignallingLongBtnText);
|
||||
eaSignallingLongBtn.Color(mSignallingLongBtnTextColor);
|
||||
|
||||
//
|
||||
// Short Signals ...
|
||||
color mSignallingShortBtnTextColor = eaEnableShorts
|
||||
? clrRed
|
||||
: clrGreen;
|
||||
string mSignallingShortBtnText = eaEnableShorts
|
||||
? "Deactive Shorts"
|
||||
: "Active Shorts";
|
||||
eaSignallingShortBtn.Text(mSignallingShortBtnText);
|
||||
eaSignallingShortBtn.Color(mSignallingShortBtnTextColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Signalling GUI ...
|
||||
*/
|
||||
void DestroySignallingGUI()
|
||||
{
|
||||
//
|
||||
eaSignallingPanel.Destroy();
|
||||
eaSignallingBtn.Destroy();
|
||||
eaSignallingLongBtn.Destroy();
|
||||
eaSignallingShortBtn.Destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Signalling State ...
|
||||
*/
|
||||
void HandleChangeState()
|
||||
{
|
||||
//
|
||||
// Preparing State ...
|
||||
bool isSignallingActive = eaEnableLongs ||
|
||||
eaEnableShorts;
|
||||
|
||||
//
|
||||
if (isSignallingActive)
|
||||
{
|
||||
//
|
||||
eaEnableLongs = false;
|
||||
eaEnableShorts = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
eaEnableLongs = true;
|
||||
eaEnableShorts = true;
|
||||
}
|
||||
|
||||
//
|
||||
UpdateSignallingOnTradeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Longs Signalling ...
|
||||
*/
|
||||
void HandleChangeLongsState()
|
||||
{
|
||||
//
|
||||
eaEnableLongs = !eaEnableLongs;
|
||||
|
||||
//
|
||||
UpdateSignallingOnTradeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Shorts Signalling ...
|
||||
*/
|
||||
void HandleChangeShortsState()
|
||||
{
|
||||
//
|
||||
eaEnableShorts = !eaEnableShorts;
|
||||
|
||||
//
|
||||
UpdateSignallingOnTradeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Signalling Features on Trade Handler ...
|
||||
*/
|
||||
void UpdateSignallingOnTradeHandler()
|
||||
{
|
||||
//
|
||||
eaTradeHandler.AllowLong(eaEnableLongs);
|
||||
eaTradeHandler.AllowShort(eaEnableShorts);
|
||||
|
||||
//
|
||||
UpdateSignallingGUI();
|
||||
}
|
||||
|
||||
//
|
||||
// PROTECTOR GUI ...
|
||||
|
||||
/**
|
||||
* Initial Protector GUI ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool InitProtectorGUI()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string eaProtectorPanelName = mTag + "PROTECTOR";
|
||||
|
||||
//
|
||||
// Create a Panel ...
|
||||
result = eaProtectorPanel.Create(
|
||||
eaProtectorPanelName,
|
||||
10,
|
||||
110,
|
||||
300,
|
||||
100 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaProtectorPanel.Caption("Protector");
|
||||
|
||||
//
|
||||
string eaProtectorPrefix = eaProtectorPanelName + "_";
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
string eaHedgingBtnName = eaProtectorPrefix + "HEDGING_btn";
|
||||
result = eaHedgingBtn.Create(
|
||||
eaHedgingBtnName,
|
||||
10,
|
||||
130,
|
||||
300,
|
||||
25 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaHedgingBtn.Text("");
|
||||
eaProtectorPanel.Add(eaHedgingBtnName);
|
||||
|
||||
//
|
||||
// Trailling ...
|
||||
string eaTraillingBtnName = eaProtectorPrefix + "TRAILLING_btn";
|
||||
result = eaTraillingBtn.Create(
|
||||
eaTraillingBtnName,
|
||||
10,
|
||||
155,
|
||||
300,
|
||||
25 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaTraillingBtn.Text("");
|
||||
eaProtectorPanel.Add(eaTraillingBtnName);
|
||||
|
||||
//
|
||||
// Protecting ...
|
||||
string eaProtectingBtnName = eaProtectorPrefix + "FREEZING_btn";
|
||||
result = eaProtectingBtn.Create(
|
||||
eaProtectingBtnName,
|
||||
10,
|
||||
180,
|
||||
300,
|
||||
25 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
eaProtectingBtn.Text("");
|
||||
eaProtectorPanel.Add(eaProtectingBtnName);
|
||||
|
||||
//
|
||||
UpdateProtectorGUI();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Protector GUI ...
|
||||
*/
|
||||
void UpdateProtectorGUI()
|
||||
{
|
||||
//
|
||||
// Hedging ...
|
||||
|
||||
//
|
||||
// Checking Hedging Props ...
|
||||
bool isHedgingActiveProps =
|
||||
eaHedgeMinVolumeStep > 0 &&
|
||||
((eaMinimumOpenPositionsForHEHedge > 0 &&
|
||||
eaHedgeHEMinProfitPerVolumeStep > 0) ||
|
||||
eaHedgeBEMinProfitPerVolumeStep);
|
||||
|
||||
//
|
||||
// Check Hedging State ...
|
||||
bool isHedgingActived = eaAllowHedge &&
|
||||
isHedgingActiveProps;
|
||||
eaEnableHedging = isHedgingActived;
|
||||
|
||||
//
|
||||
color eaHedgingBtnTextColor =
|
||||
!isHedgingActiveProps
|
||||
? clrGray
|
||||
: isHedgingActived
|
||||
? clrRed
|
||||
: clrGreen;
|
||||
string eaHedgingBtnText =
|
||||
!isHedgingActiveProps
|
||||
? "Hedging Disabled"
|
||||
: isHedgingActived
|
||||
? "Deactive Hedging"
|
||||
: "Active Hedging";
|
||||
eaHedgingBtn.Text(eaHedgingBtnText);
|
||||
eaHedgingBtn.Color(eaHedgingBtnTextColor);
|
||||
|
||||
//
|
||||
// Trailling ...
|
||||
|
||||
//
|
||||
// Checking Trailling Props ...
|
||||
bool isTraillingActiveProps =
|
||||
eaTrailStep > 0 &&
|
||||
eaTrailStartDistance > 0 &&
|
||||
eaTrailStep < eaTrailStartDistance;
|
||||
|
||||
//
|
||||
// Check Trailling State ...
|
||||
bool isTraillingActived =
|
||||
eaAllowTrail &&
|
||||
isTraillingActiveProps;
|
||||
eaEnableTrailling = isTraillingActived;
|
||||
|
||||
//
|
||||
color eaTraillingBtnTextColor =
|
||||
!isTraillingActiveProps
|
||||
? clrGray
|
||||
: isTraillingActived
|
||||
? clrRed
|
||||
: clrGreen;
|
||||
string eaTraillingBtnText =
|
||||
!isTraillingActiveProps
|
||||
? "Trailling Disabled"
|
||||
: isTraillingActived
|
||||
? "Deactive Trailling"
|
||||
: "Active Trailling";
|
||||
eaTraillingBtn.Text(eaTraillingBtnText);
|
||||
eaTraillingBtn.Color(eaTraillingBtnTextColor);
|
||||
|
||||
//
|
||||
// Protecting ...
|
||||
|
||||
//
|
||||
// Checking Protection Props ...
|
||||
bool isProtectingActiveProps =
|
||||
eaProtectionDelay >= 0 &&
|
||||
eaProtectionStartDistance > 0 &&
|
||||
eaProtectionVolumeMultiplier > 0;
|
||||
|
||||
//
|
||||
// Check Protection State ...
|
||||
bool isProtectingActived =
|
||||
eaAllowProtect &&
|
||||
isProtectingActiveProps;
|
||||
eaEnableProtecting = isProtectingActived;
|
||||
|
||||
//
|
||||
color eaProtectingBtnTextColor =
|
||||
!isProtectingActiveProps
|
||||
? clrGray
|
||||
: isProtectingActived
|
||||
? clrRed
|
||||
: clrGreen;
|
||||
string eaProtectingBtnText =
|
||||
!isProtectingActiveProps
|
||||
? "Protecting Disabled"
|
||||
: isProtectingActived
|
||||
? "Deactive Protecting"
|
||||
: "Active Protecting";
|
||||
eaProtectingBtn.Text(eaProtectingBtnText);
|
||||
eaProtectingBtn.Color(eaProtectingBtnTextColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Protector GUI ...
|
||||
*/
|
||||
void DestroyProtectorGUI()
|
||||
{
|
||||
//
|
||||
eaHedgingBtn.Destroy();
|
||||
eaTraillingBtn.Destroy();
|
||||
eaProtectingBtn.Destroy();
|
||||
eaProtectorPanel.Destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Hedging State ...
|
||||
*/
|
||||
void HandleChangeHedgingState()
|
||||
{
|
||||
//
|
||||
// Checking Hedging Props ...
|
||||
bool isHedgingActiveProps =
|
||||
eaHedgeMinVolumeStep > 0 &&
|
||||
((eaMinimumOpenPositionsForHEHedge > 0 &&
|
||||
eaHedgeHEMinProfitPerVolumeStep > 0) ||
|
||||
eaHedgeBEMinProfitPerVolumeStep);
|
||||
|
||||
//
|
||||
if (!isHedgingActiveProps)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
eaEnableHedging = !eaEnableHedging;
|
||||
|
||||
//
|
||||
UpdateProtectingOnTradeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Trailling State ...
|
||||
*/
|
||||
void HandleChangeTraillingState()
|
||||
{
|
||||
//
|
||||
// Checking Trailling Props ...
|
||||
bool isTraillingActiveProps =
|
||||
eaTrailStep > 0 &&
|
||||
eaTrailStartDistance > 0 &&
|
||||
eaTrailStep < eaTrailStartDistance;
|
||||
|
||||
//
|
||||
if (!isTraillingActiveProps)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
eaEnableTrailling = !eaEnableTrailling;
|
||||
|
||||
//
|
||||
UpdateProtectingOnTradeHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Protecting State ...
|
||||
*/
|
||||
void HandleChangeProtectingState()
|
||||
{
|
||||
|
||||
//
|
||||
// Checking Protection Props ...
|
||||
bool isProtectingActiveProps =
|
||||
eaProtectionDelay >= 0 &&
|
||||
eaProtectionStartDistance > 0 &&
|
||||
eaProtectionVolumeMultiplier > 0;
|
||||
|
||||
//
|
||||
if (!isProtectingActiveProps)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
eaEnableProtecting = !eaEnableProtecting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Protecting Features on Trade Handler ...
|
||||
*/
|
||||
void UpdateProtectingOnTradeHandler()
|
||||
{
|
||||
//
|
||||
eaTradeHandler.AllowHedge(eaEnableHedging);
|
||||
eaTradeHandler.AllowTrail(eaEnableTrailling);
|
||||
eaTradeHandler.AllowProtect(eaEnableProtecting);
|
||||
|
||||
//
|
||||
UpdateProtectorGUI();
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user