Last Apply Props and Fix on Protection Handlers ...

This commit is contained in:
2024-10-01 18:41:03 +03:30
parent fe988089ef
commit 59eb5e86a2
2 changed files with 164 additions and 40 deletions
Binary file not shown.
+164 -40
View File
@@ -126,6 +126,8 @@ input group "In Drawdown Positions Protecting";
input group "Protect"; input group "Protect";
input bool eaAllowProtect = true; // Allow Proptecting input bool eaAllowProtect = true; // Allow Proptecting
input int eaProtectionDelay = 300; // Delay Between two Protection in Secconds input int eaProtectionDelay = 300; // Delay Between two Protection in Secconds
input int eaMaxAllowedProtection = 1; // Max Allowed Protection
input bool eaUseEntryAsProtectionSL = true; // Use Position Entry For SL of Protect
input bool eaProtectOnConditions = true; // Do Protection only when Conditions happens input bool eaProtectOnConditions = true; // Do Protection only when Conditions happens
input bool eaAllowDirectionProtct = false; // Allow also Directional Protect input bool eaAllowDirectionProtct = false; // Allow also Directional Protect
input double eaProtectionStartDistance = 100; // Protection Start Drawdown in Point input double eaProtectionStartDistance = 100; // Protection Start Drawdown in Point
@@ -219,8 +221,10 @@ XCEdit eaStaticVolumeTb;
XCLabel eaStaticVolumeLbl; XCLabel eaStaticVolumeLbl;
XCButton eaSetStaticVolumeBtn; XCButton eaSetStaticVolumeBtn;
XCButton eaResetStaticVolumeBtn; XCButton eaResetStaticVolumeBtn;
bool eaAppliedStaticVolume = false; double eaAppliedStaticVolume = eaVolume;
bool eEnableDynamicVolumeVolume = false; bool eEnableDynamicVolumeVolume = eaUseDynamicVolume &&
eaDynamicVolumeStep > 0 &&
eaDynamicVolumeBalanceFactor > 0;
// //
// Event Handlers ... // Event Handlers ...
@@ -593,6 +597,8 @@ bool InitEA()
// Protect ... // Protect ...
eaTradeHandler.AllowProtect(eaAllowProtect); eaTradeHandler.AllowProtect(eaAllowProtect);
eaTradeHandler.ProtectionDelay(eaProtectionDelay); eaTradeHandler.ProtectionDelay(eaProtectionDelay);
eaTradeHandler.MaxAllowedProtection(eaMaxAllowedProtection);
eaTradeHandler.UseEntryAsProtectionSL(eaUseEntryAsProtectionSL);
eaTradeHandler.ProtectOnConditions(eaProtectOnConditions); eaTradeHandler.ProtectOnConditions(eaProtectOnConditions);
eaTradeHandler.AllowDirectionProtct(eaAllowDirectionProtct); eaTradeHandler.AllowDirectionProtct(eaAllowDirectionProtct);
eaTradeHandler.ProtectionStartDistance(eaProtectionStartDistance); eaTradeHandler.ProtectionStartDistance(eaProtectionStartDistance);
@@ -1129,36 +1135,8 @@ void OnSignalRecieved(
} }
// //
// Prepare Signal Dynamic Volume // Apply Volume On Signal ...
// if Provided ... ApplyVolumeOnSignal(signal);
if (eaUseDynamicVolume &&
eaDynamicVolumeStep > 0 &&
eaDynamicVolumeBalanceFactor > 0)
{
//
double dVolume = eaTrader.GetDynamicVolume(
signal.symbol,
eaDynamicVolumeBalanceFactor,
eaDynamicVolumeStep //
);
//
if (dVolume > 0)
{
signal.volume = dVolume;
}
else
{
signal.volume = eaVolume;
}
//
eaTradeHandler.UpdateSignal(signal);
}
else
{
signal.volume = eaVolume;
}
// //
// Chekc Signalling Enable or not ... // Chekc Signalling Enable or not ...
@@ -1320,6 +1298,46 @@ void RegisterStrategy(XSCBaseStrategy *strategy)
strategies[ArraySize(strategies) - 1] = strategy; strategies[ArraySize(strategies) - 1] = strategy;
} }
/**
* Apply Volume Based On Configurations on Signal ...
*
* @param signal: XSignal instance
*/
void ApplyVolumeOnSignal(XSignal &signal)
{
//
// Prepare Signal Dynamic Volume
// if Provided ...
if (eEnableDynamicVolumeVolume &&
eaDynamicVolumeStep > 0 &&
eaDynamicVolumeBalanceFactor > 0)
{
//
double dVolume = eaTrader.GetDynamicVolume(
signal.symbol,
eaDynamicVolumeBalanceFactor,
eaDynamicVolumeStep //
);
//
if (dVolume > 0)
{
signal.volume = dVolume;
}
else
{
signal.volume = eaAppliedStaticVolume;
}
}
else
{
signal.volume = eaAppliedStaticVolume;
}
//
eaTradeHandler.UpdateSignal(signal);
}
// //
// GUI Parts ... // GUI Parts ...
@@ -1914,9 +1932,9 @@ bool InitVolumeGUI()
string eaStaticVolumeTbName = eaVolumePrefix + "STATIC_VOLUME_tb"; string eaStaticVolumeTbName = eaVolumePrefix + "STATIC_VOLUME_tb";
result = eaStaticVolumeTb.Create( result = eaStaticVolumeTb.Create(
eaStaticVolumeTbName, eaStaticVolumeTbName,
150,
250,
160, 160,
250,
150,
25 // 25 //
); );
if (!result) if (!result)
@@ -1972,6 +1990,59 @@ bool InitVolumeGUI()
*/ */
void UpdateVolumeGUI() void UpdateVolumeGUI()
{ {
//
string tbVolume = eaStaticVolumeTb.Text();
//
// Set Current Volume if it's Empty ...
if (!IsValid(tbVolume))
{
eaStaticVolumeTb.Text(ToString(eaVolume));
}
//
bool isDefault = ToString(tbVolume) == ToString(eaVolume);
bool isCurrent = ToString(tbVolume) == ToString(eaAppliedStaticVolume);
//
// Set Static Volume Color ...
color eaSetStaticVolumeBtnColor = (isDefault ||
isCurrent)
? clrGray
: clrGreen;
eaSetStaticVolumeBtn.Color(eaSetStaticVolumeBtnColor);
//
// Reset Static Volume Color ...
color eaResetStaticVolumeBtnColor = isDefault
? clrGray
: clrRed;
eaResetStaticVolumeBtn.Color(eaResetStaticVolumeBtnColor);
//
// Dynamic Volume State ...
//
// Check Required Props ...
bool isDynamicVolumeActivedProps =
eaDynamicVolumeStep > 0 &&
eaDynamicVolumeBalanceFactor > 0;
//
color eaDynamicVolumeBtnColor =
!isDynamicVolumeActivedProps
? clrGray
: eEnableDynamicVolumeVolume
? clrRed
: clrGreen;
string eaDynamicVolumeBtnText =
!isDynamicVolumeActivedProps
? "Disabled"
: eEnableDynamicVolumeVolume
? "Deactive Dynamic Volume"
: "Active Dynamic Volume";
eaDynamicVolumeBtn.Text(eaDynamicVolumeBtnText);
eaDynamicVolumeBtn.Color(eaDynamicVolumeBtnColor);
} }
/** /**
@@ -1990,29 +2061,82 @@ void DestroyVolumeGUI()
eaVolumePanel.Destroy(); eaVolumePanel.Destroy();
} }
/**
* Toggle Dynamic Volume Usage ...
*/
void HandleChangeDynamicVolumeState() void HandleChangeDynamicVolumeState()
{ {
// //
UpdateVolumeOnTradeHandler(); // Check Required Props ...
bool isDynamicVolumeActivedProps =
eaDynamicVolumeStep > 0 &&
eaDynamicVolumeBalanceFactor > 0;
//
if (!isDynamicVolumeActivedProps)
{
return;
}
//
eEnableDynamicVolumeVolume = !eEnableDynamicVolumeVolume;
} }
/**
* Change Static Volume ...
*/
void HandleChangeStaticVolume() void HandleChangeStaticVolume()
{ {
//
string tbVolume = eaStaticVolumeTb.Text();
// //
UpdateVolumeOnTradeHandler(); // Set Current Volume if it's Empty ...
if (!IsValid(tbVolume))
{
return;
}
//
bool isCurrent = ToString(tbVolume) == ToString(eaAppliedStaticVolume);
if (isCurrent)
{
return;
}
//
eaAppliedStaticVolume = (double)tbVolume;
if (eaAppliedStaticVolume <= 0)
{
eaAppliedStaticVolume = eaVolume;
}
} }
/**
* Set Default Static Volume Value ...
*/
void HandleResetStaticVolume() void HandleResetStaticVolume()
{ {
//
string tbVolume = eaStaticVolumeTb.Text();
// //
UpdateVolumeOnTradeHandler(); // Set Current Volume if it's Empty ...
} if (!IsValid(tbVolume))
{
return;
}
void UpdateVolumeOnTradeHandler() //
{ bool isDefault = ToString(tbVolume) == ToString(eaVolume);
if (isDefault)
{
return;
}
//
eaStaticVolumeTb.Text(ToString(eaVolume));
} }
// //