This commit is contained in:
2024-07-27 15:59:01 +03:30
parent c0c4714545
commit 37b9578ba1
6 changed files with 3525 additions and 1092 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+38 -5
View File
@@ -43,23 +43,29 @@ double eaAllowLong = true; // Allow Long Positions
double eaAllowShort = true; // Allow Short Positions double eaAllowShort = true; // Allow Short Positions
// //
int eaMaxAllowedLongs = 0; // Max Allowed Long Positions int eaMaxAllowedLongs = 1; // Max Allowed Long Positions
int eaMaxAllowedShorts = 0; // Max Allowed Short Positions int eaMaxAllowedShorts = 1; // Max Allowed Short Positions
// //
input double eaTPPoint = 200; // Static TP Point input double eaTPPoint = 100; // Static TP Point
input double eaSLPoint = 100; // Static SL Point input double eaSLPoint = 100; // Static SL Point
// //
bool eaIgnoreTP = false; // Ignore TP bool eaIgnoreTP = false; // Ignore TP
bool eaIgnoreSL = false; // Ignore SL bool eaIgnoreSL = false; // Ignore SL
//
int eaMaxAllowedSLsInDay = 2;
// //
double eaR2R = 1.5; // Risk to Reward Ratio double eaR2R = 1.5; // Risk to Reward Ratio
// //
// Variables ... // Variables ...
//
int mNumberOfSLs = 0;
// //
// Bar Style nad Time Instances ... // Bar Style nad Time Instances ...
XSCXCTHelper *mCTHelper; XSCXCTHelper *mCTHelper;
@@ -73,6 +79,9 @@ XSCBaseStrategy *strategies[];
// Trader Instance Class ... // Trader Instance Class ...
XSCTrade *eaTrader; XSCTrade *eaTrader;
//
XTimeTracker eaTimeTracker;
// //
// Alert Class ... // Alert Class ...
XSCAlert *eaAlert; XSCAlert *eaAlert;
@@ -167,7 +176,14 @@ void OnTrade()
// On Timer ... // On Timer ...
void OnTimer() void OnTimer()
{ {
//
HandleTradeState(); HandleTradeState();
//
if (eaTimeTracker.IsNewDay())
{
mNumberOfSLs = 0;
}
} }
// //
@@ -359,6 +375,7 @@ bool InitialEA()
eurusdXCHKMStrategy = new XSCXCHKMStrategy( eurusdXCHKMStrategy = new XSCXCHKMStrategy(
eurusdSymbol, eurusdSymbol,
PERIOD_M5, PERIOD_M5,
PERIOD_H1, // Analyzing Period
eaVolume, eaVolume,
eaR2R, // R2R ... eaR2R, // R2R ...
eaSlippage, eaSlippage,
@@ -387,17 +404,18 @@ bool InitialEA()
xchmStrategy = new XSCXCHKMStrategy( xchmStrategy = new XSCXCHKMStrategy(
_Symbol, _Symbol,
_Period, _Period,
PERIOD_H1, // Analyzing Period
eaVolume, eaVolume,
eaR2R, // R2R ... eaR2R, // R2R ...
eaSlippage, eaSlippage,
eaMagicNumber, eaMagicNumber,
true, // Ignore Signal Execution true, // Ignore Signal Execution
false, // Use TP SL Point true, // Use TP SL Point
false, // Use Max false, // Use Max
eaTPPoint, // TP eaTPPoint, // TP
eaSLPoint, // SL eaSLPoint, // SL
eaIgnoreTP, eaIgnoreTP,
false, // eaIgnoreSL, true, // eaIgnoreSL,
eaAllowLong, eaAllowLong,
eaAllowShort, eaAllowShort,
eaMaxAllowedLongs, // Max Longs eaMaxAllowedLongs, // Max Longs
@@ -503,6 +521,13 @@ void OnSignalRecieved(XSignal &signal)
return; return;
} }
//
if (eaMaxAllowedSLsInDay > 0 &&
mNumberOfSLs >= eaMaxAllowedSLsInDay)
{
return;
}
// //
ENUM_X_SIGNAL_EXECUTION_RESULT state; ENUM_X_SIGNAL_EXECUTION_RESULT state;
bool isExecuted = eaTrader.ExecuteSignal( bool isExecuted = eaTrader.ExecuteSignal(
@@ -564,13 +589,21 @@ void OnSignalRecieved(XSignal &signal)
// //
void OnStopLossTriggered(const XDeal &deal) void OnStopLossTriggered(const XDeal &deal)
{ {
//
// Finish ... // Finish ...
eaTradeHandler.Finish(deal); eaTradeHandler.Finish(deal);
//
if (deal.profit < 0)
{
mNumberOfSLs++;
}
} }
// //
void OnTakeProfitTriggered(const XDeal &deal) void OnTakeProfitTriggered(const XDeal &deal)
{ {
//
// Finish ... // Finish ...
eaTradeHandler.Finish(deal); eaTradeHandler.Finish(deal);
} }
+4 -4
View File
@@ -4055,7 +4055,7 @@ public:
// //
for (int i = 0; i < barsCount; i++) for (int i = 0; i < barsCount; i++)
{ {
result = bars[i].GetBody(); result += bars[i].GetBody();
} }
// //
@@ -4084,7 +4084,7 @@ public:
// //
for (int i = 0; i < barsCount; i++) for (int i = 0; i < barsCount; i++)
{ {
result = bars[i].GetBody(); result += bars[i].GetBody();
} }
// //
@@ -4115,7 +4115,7 @@ public:
// //
for (int i = 0; i < barsCount; i++) for (int i = 0; i < barsCount; i++)
{ {
result = bars[i].GetBody(); result += bars[i].GetBody();
} }
// //
@@ -4146,7 +4146,7 @@ public:
// //
for (int i = 0; i < barsCount; i++) for (int i = 0; i < barsCount; i++)
{ {
result = bars[i].GetBody(); result += bars[i].GetBody();
} }
// //
+66 -66
View File
@@ -1165,7 +1165,7 @@ struct XOHCL
// //
bool IsSharpBullish( bool IsSharpBullish(
int _loopback = 2, int __loopback = 2,
double _sharpRatio = 2.5 // double _sharpRatio = 2.5 //
) )
{ {
@@ -1180,9 +1180,9 @@ struct XOHCL
} }
// //
if (_loopback < 0) if (__loopback < 0)
{ {
_loopback = 2; __loopback = 2;
} }
// //
@@ -1193,11 +1193,11 @@ struct XOHCL
// //
int hIDX = FindHighestIndex( int hIDX = FindHighestIndex(
_loopback, __loopback,
MODE_HIGH // MODE_HIGH //
); );
int lIDX = FindLowestIndex( int lIDX = FindLowestIndex(
_loopback, __loopback,
MODE_LOW // MODE_LOW //
); );
@@ -1245,13 +1245,13 @@ struct XOHCL
// //
int hhIDX = hBar.FindHighestIndex( int hhIDX = hBar.FindHighestIndex(
_loopback, __loopback,
MODE_HIGH // MODE_HIGH //
); );
// //
int llIDX = lBar.FindLowestIndex( int llIDX = lBar.FindLowestIndex(
_loopback, __loopback,
MODE_LOW // MODE_LOW //
); );
@@ -1297,7 +1297,7 @@ struct XOHCL
// //
bool IsSharpBearish( bool IsSharpBearish(
int _loopback = 2, int __loopback = 2,
double _sharpRatio = 2.5 // double _sharpRatio = 2.5 //
) )
{ {
@@ -1312,9 +1312,9 @@ struct XOHCL
} }
// //
if (_loopback < 0) if (__loopback < 0)
{ {
_loopback = 2; __loopback = 2;
} }
// //
@@ -1325,11 +1325,11 @@ struct XOHCL
// //
int hIDX = FindHighestIndex( int hIDX = FindHighestIndex(
_loopback, __loopback,
MODE_HIGH // MODE_HIGH //
); );
int lIDX = FindLowestIndex( int lIDX = FindLowestIndex(
_loopback, __loopback,
MODE_LOW // MODE_LOW //
); );
@@ -1377,13 +1377,13 @@ struct XOHCL
// //
int hhIDX = hBar.FindHighestIndex( int hhIDX = hBar.FindHighestIndex(
_loopback, __loopback,
MODE_HIGH // MODE_HIGH //
); );
// //
int llIDX = lBar.FindLowestIndex( int llIDX = lBar.FindLowestIndex(
_loopback, __loopback,
MODE_LOW // MODE_LOW //
); );
@@ -1588,7 +1588,7 @@ struct XOHCL
// //
// Retrieve Bullish Pressure ... // Retrieve Bullish Pressure ...
double GetBullishPressure( double GetBullishPressure(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
@@ -1607,7 +1607,7 @@ struct XOHCL
symbol, symbol,
period, period,
Index(), Index(),
_loopback // __loopback //
); );
if (!IsValidSize(barsCount)) if (!IsValidSize(barsCount))
{ {
@@ -1627,7 +1627,7 @@ struct XOHCL
// //
// Retrieve Bearish Pressure ... // Retrieve Bearish Pressure ...
double GetBearishPressure( double GetBearishPressure(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
@@ -1646,7 +1646,7 @@ struct XOHCL
symbol, symbol,
period, period,
Index(), Index(),
_loopback // __loopback //
); );
if (!IsValidSize(barsCount)) if (!IsValidSize(barsCount))
{ {
@@ -1665,21 +1665,21 @@ struct XOHCL
// //
bool HasBullishPressure( bool HasBullishPressure(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
bool result = false; bool result = false;
// //
if (_loopback < 0) if (__loopback < 0)
{ {
_loopback = 7; __loopback = 7;
} }
// //
double bullishPressure = GetBullishPressure(_loopback); double bullishPressure = GetBullishPressure(__loopback);
double bearishPressure = GetBearishPressure(_loopback); double bearishPressure = GetBearishPressure(__loopback);
// //
result = result =
@@ -1696,21 +1696,21 @@ struct XOHCL
// //
bool HasBearishPressure( bool HasBearishPressure(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
bool result = false; bool result = false;
// //
if (_loopback < 0) if (__loopback < 0)
{ {
_loopback = 7; __loopback = 7;
} }
// //
double bullishPressure = GetBullishPressure(_loopback); double bullishPressure = GetBullishPressure(__loopback);
double bearishPressure = GetBearishPressure(_loopback); double bearishPressure = GetBearishPressure(__loopback);
// //
result = result =
@@ -1728,7 +1728,7 @@ struct XOHCL
// //
// Retrieve Bullish Power ... // Retrieve Bullish Power ...
double GetBullishPower( double GetBullishPower(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
@@ -1747,7 +1747,7 @@ struct XOHCL
symbol, symbol,
period, period,
Index(), Index(),
_loopback // __loopback //
); );
if (!IsValidSize(barsCount)) if (!IsValidSize(barsCount))
{ {
@@ -1771,7 +1771,7 @@ struct XOHCL
// //
// Retrieve Bearish Pressure ... // Retrieve Bearish Pressure ...
double GetBearishPower( double GetBearishPower(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
@@ -1790,7 +1790,7 @@ struct XOHCL
symbol, symbol,
period, period,
Index(), Index(),
_loopback // __loopback //
); );
if (!IsValidSize(barsCount)) if (!IsValidSize(barsCount))
{ {
@@ -1813,21 +1813,21 @@ struct XOHCL
// //
bool HasBullishPower( bool HasBullishPower(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
bool result = false; bool result = false;
// //
if (_loopback < 0) if (__loopback < 0)
{ {
_loopback = 7; __loopback = 7;
} }
// //
double bullishPressure = GetBullishPower(_loopback); double bullishPressure = GetBullishPower(__loopback);
double bearishPressure = GetBearishPower(_loopback); double bearishPressure = GetBearishPower(__loopback);
// //
result = result =
@@ -1844,21 +1844,21 @@ struct XOHCL
// //
bool HasBearishPower( bool HasBearishPower(
int _loopback = 7 // int __loopback = 7 //
) )
{ {
// //
bool result = false; bool result = false;
// //
if (_loopback < 0) if (__loopback < 0)
{ {
_loopback = 7; __loopback = 7;
} }
// //
double bullishPressure = GetBullishPower(_loopback); double bullishPressure = GetBullishPower(__loopback);
double bearishPressure = GetBearishPower(_loopback); double bearishPressure = GetBearishPower(__loopback);
// //
result = result =
@@ -3114,7 +3114,7 @@ struct XOHCL
bool HasSupport( bool HasSupport(
XOHCL &bar, XOHCL &bar,
ENUM_X_PRICE type = X_PRICE_CLOSE, ENUM_X_PRICE type = X_PRICE_CLOSE,
int loopback = 21, int _loopback = 21,
int tries = 100 // int tries = 100 //
) )
{ {
@@ -3125,9 +3125,9 @@ struct XOHCL
bar.Clean(); bar.Clean();
// //
if (loopback < 0) if (_loopback < 0)
{ {
loopback = 21; _loopback = 21;
} }
// //
@@ -3150,11 +3150,11 @@ struct XOHCL
for (int i = 1; i < tries; i++) for (int i = 1; i < tries; i++)
{ {
// //
int length = loopback * i; int _length = _loopback * i;
// //
int lowestIDX = FindLowestIndex( int lowestIDX = FindLowestIndex(
length, _length,
MODE_LOW // MODE_LOW //
); );
result = IsValidSize(lowestIDX); result = IsValidSize(lowestIDX);
@@ -3198,7 +3198,7 @@ struct XOHCL
bool HasResistance( bool HasResistance(
XOHCL &bar, XOHCL &bar,
ENUM_X_PRICE type = X_PRICE_CLOSE, ENUM_X_PRICE type = X_PRICE_CLOSE,
int loopback = 21, int _loopback = 21,
int tries = 100 // int tries = 100 //
) )
{ {
@@ -3209,9 +3209,9 @@ struct XOHCL
bar.Clean(); bar.Clean();
// //
if (loopback < 0) if (_loopback < 0)
{ {
loopback = 21; _loopback = 21;
} }
// //
@@ -3234,11 +3234,11 @@ struct XOHCL
for (int i = 1; i < tries; i++) for (int i = 1; i < tries; i++)
{ {
// //
int length = loopback * i; int _length = _loopback * i;
// //
int highestIDX = FindHighestIndex( int highestIDX = FindHighestIndex(
length, _length,
MODE_LOW // MODE_LOW //
); );
result = IsValidSize(highestIDX); result = IsValidSize(highestIDX);
@@ -3286,7 +3286,7 @@ struct XOHCL
XOHCL &highSwingBars[], XOHCL &highSwingBars[],
XOHCL &lowSwingBars[], XOHCL &lowSwingBars[],
bool forceMethod2 = false, bool forceMethod2 = false,
int loopback = 3, int _loopback = 3,
int tries = 3, int tries = 3,
ENUM_X_PRICE type = X_PRICE_CLOSE // ENUM_X_PRICE type = X_PRICE_CLOSE //
) )
@@ -3323,7 +3323,7 @@ struct XOHCL
symbol, symbol,
period, period,
X_SWING_HIGH, X_SWING_HIGH,
loopback, _loopback,
lastIDX // lastIDX //
); );
result = IsValidIndex(iHIDX); result = IsValidIndex(iHIDX);
@@ -3376,7 +3376,7 @@ struct XOHCL
symbol, symbol,
period, period,
X_SWING_LOW, X_SWING_LOW,
loopback, _loopback,
lastIDX // lastIDX //
); );
result = IsValidIndex(iLIDX); result = IsValidIndex(iLIDX);
@@ -3429,12 +3429,12 @@ struct XOHCL
else else
{ {
// //
int length = i * loopback; int _length = i * _loopback;
int start = int start =
// //
i == 1 i == 1
? 1 ? 1
: length - loopback : _length - _loopback
// //
; ;
@@ -3443,7 +3443,7 @@ struct XOHCL
symbol, symbol,
period, period,
MODE_HIGH, MODE_HIGH,
loopback, _loopback,
start // start //
); );
result = IsValidIndex(iHIDX); result = IsValidIndex(iHIDX);
@@ -3496,7 +3496,7 @@ struct XOHCL
symbol, symbol,
period, period,
MODE_LOW, MODE_LOW,
loopback, _loopback,
start // start //
); );
result = IsValidIndex(iLIDX); result = IsValidIndex(iLIDX);
@@ -3576,7 +3576,7 @@ struct XOHCL
XOHCL &highSwingBars[], XOHCL &highSwingBars[],
XOHCL &lowSwingBars[], XOHCL &lowSwingBars[],
bool forceMethod2 = false, bool forceMethod2 = false,
int loopback = 3, int _loopback = 3,
int tries = 3, int tries = 3,
ENUM_X_PRICE type = X_PRICE_CLOSE // ENUM_X_PRICE type = X_PRICE_CLOSE //
) )
@@ -3613,7 +3613,7 @@ struct XOHCL
symbol, symbol,
period, period,
X_SWING_HIGH, X_SWING_HIGH,
loopback, _loopback,
lastIDX // lastIDX //
); );
result = IsValidIndex(iHIDX); result = IsValidIndex(iHIDX);
@@ -3666,7 +3666,7 @@ struct XOHCL
symbol, symbol,
period, period,
X_SWING_LOW, X_SWING_LOW,
loopback, _loopback,
lastIDX // lastIDX //
); );
result = IsValidIndex(iLIDX); result = IsValidIndex(iLIDX);
@@ -3719,12 +3719,12 @@ struct XOHCL
else else
{ {
// //
int length = i * loopback; int _length = i * _loopback;
int start = int start =
// //
i == 1 i == 1
? 1 ? 1
: length - loopback : _length - _loopback
// //
; ;
@@ -3733,7 +3733,7 @@ struct XOHCL
symbol, symbol,
period, period,
MODE_HIGH, MODE_HIGH,
loopback, _loopback,
start // start //
); );
result = IsValidIndex(iHIDX); result = IsValidIndex(iHIDX);
@@ -3786,7 +3786,7 @@ struct XOHCL
symbol, symbol,
period, period,
MODE_LOW, MODE_LOW,
loopback, _loopback,
start // start //
); );
result = IsValidIndex(iLIDX); result = IsValidIndex(iLIDX);
File diff suppressed because it is too large Load Diff