This commit is contained in:
2024-05-27 09:06:04 +03:30
parent c1aa4fe888
commit 30dd2f1aaf
13 changed files with 2337 additions and 368 deletions
+135
View File
@@ -1287,6 +1287,7 @@ public:
double maxAllowedSpread, // Max Allowed Spred for Opening Trades
int maxAllowedPositions, // Max Allowed Positions
double maxAllowedDrawdownFactor, // Max Allowed Drawdown Factor
double staticVolume, // Static Volume for Positions
//
// Position Management ...
bool allowLong = true, // Allow Long Trades
@@ -1331,6 +1332,7 @@ public:
mAllowShort = allowShort;
mMinProfitPerTrade = minProfitPerTrade;
mMinProfitPerVolumeFactor = minProfitPerVolumeFactor;
mStaticVolume = staticVolume;
//
// Set Event Handlers ...
@@ -1451,6 +1453,25 @@ public:
return mTrader.GetMaxAllowedDrawdownFactor();
}
//
double GetStaticVolume()
{
return mStaticVolume;
}
//
void SetStaticVolume(double value)
{
//
if (value <= 0)
{
value = 0.01;
}
//
mStaticVolume = value;
}
//
bool GetAllowLong()
{
@@ -1953,6 +1974,10 @@ public:
virtual void OnLongsGoingToDrawdown(XProfitTrack &track) {}
virtual void OnShortsGoingToDrawdown(XProfitTrack &track) {}
//
virtual void OnPositionGoingInProfit(XPositionTrack &track) {}
virtual void OnPositionGoingToDrawdown(XPositionTrack &track) {}
//
// Protected ...
protected:
@@ -2267,6 +2292,36 @@ protected:
//
void HandleProfitManageMent()
{
//
// Check Tracking Interval ...
//
static datetime lastProfitTracked = NULL;
datetime cTime = TimeCurrent();
//
int profitManagementInterval = PeriodSeconds(PERIOD_M5);
int timeDiff = (int)cTime - (int)lastProfitTracked;
//
bool canManage =
//
lastProfitTracked == NULL
? true
: timeDiff >= profitManagementInterval
//
;
if (!canManage)
{
return;
}
//
lastProfitTracked = cTime;
//
// Do Track ...
//
AddProfitTrack();
@@ -2376,6 +2431,85 @@ protected:
}
}
//
// Synchronize Positions and Position Tracker ...
void SyncPositionTracker()
{
//
// Check Syncing Interval ...
//
static datetime lastSyncPositionTracker = NULL;
datetime cTime = TimeCurrent();
//
int syncInterval = PeriodSeconds(PERIOD_M5);
int lastDiff = (int)cTime - (int)lastSyncPositionTracker;
//
bool canSync =
//
lastSyncPositionTracker == NULL
? true
: lastDiff >= syncInterval
//
;
if (!canSync)
{
return;
}
//
lastSyncPositionTracker = cTime;
//
// Do Sync ...
//
XPositionTrackerState state;
int synced = mPositionTracker.Sync(
state,
mTrader //
);
if (synced > 0)
{
//
// Check State and Do What we Want ...
int onProfitsCount = ArraySize(state.onProfits);
int onDrawdownCount = ArraySize(state.onDrawdowns);
//
// Do What we want whe a Position Dropped to Prefit ...
if (onProfitsCount > 0)
{
//
for (int i = 0; i < onProfitsCount; i++)
{
//
XPositionTrack iTrack = state.onProfits[i];
//
OnPositionGoingInProfit(iTrack);
}
}
//
// Do what we want when a Position Dropped to Drawdown ...
if (onDrawdownCount > 0)
{
//
for (int i = 0; i < onDrawdownCount; i++)
{
//
XPositionTrack iTrack = state.onDrawdowns[i];
//
OnPositionGoingToDrawdown(iTrack);
}
}
}
}
//
// Guards ...
@@ -2855,6 +2989,7 @@ private:
bool mAllowShort; // Allow Short Trades
double mMinProfitPerTrade; // Min Profit Per Trade based On Volume Factor (Hedge)
double mMinProfitPerVolumeFactor; // Min Volume Factor for Calculating Profit (Hedge)
double mStaticVolume; // Static Volume for Positions
//
// Event Handlers ...