last works ...

This commit is contained in:
2024-06-12 06:02:38 +03:30
parent aaf55da2de
commit 6da0c05cdf
15 changed files with 1042 additions and 1968 deletions
+9 -3
View File
@@ -1879,7 +1879,9 @@ struct X121SignalGenerator
bool _allowShort, // Allow Short Signals
double _volume = 0.01, // Volume
double _slPoint = 0, // SL Point
double _tpPoint = 30 // TP Point
bool _ignoreSL = false, // Ignore Calculated SL
double _tpPoint = 30, // TP Point
bool _ignoreTP = false // Ignore Calculated TP
)
{
//
@@ -1970,8 +1972,12 @@ struct X121SignalGenerator
X_ORDER_MODE_MARKET,
mEntry,
_volume,
0, // mSL,
mTP //
_ignoreSL
? 0
: mSL,
_ignoreTP
? 0
: mTP //
);
if (!result)
{
+458 -117
View File
@@ -636,6 +636,49 @@ public:
mSLPoint = value;
}
//
bool IgnoreTP()
{
return mIgnoreTP;
}
//
void IgnoreTP(bool value)
{
mIgnoreTP = value;
}
//
bool IgnoreSL()
{
return mIgnoreSL;
}
//
void IgnoreSL(bool value)
{
mIgnoreSL = value;
}
//
int ReuiredSignalVerifications()
{
return mReuiredSignalVerifications;
}
//
void ReuiredSignalVerifications(int value)
{
//
if (value < 1)
{
value = 1;
}
//
mReuiredSignalVerifications = value;
}
//
bool IsEnable()
{
@@ -744,13 +787,33 @@ public:
for (int i = 0; i < count; i++)
{
//
// Cleanup Signals ...
cPusher = 0;
sPusher = 0;
mPusher = 0;
lPusher = 0;
hPusher = 0;
//
cProvider = NULL;
sProvider = NULL;
mProvider = NULL;
lProvider = NULL;
hProvider = NULL;
//
cSignal.Clean();
sSignal.Clean();
mSignal.Clean();
lSignal.Clean();
hSignal.Clean();
//
cConditions.Clean();
sConditions.Clean();
mConditions.Clean();
lConditions.Clean();
hConditions.Clean();
//
// Current ...
bool canProcess = mSetups[i]
@@ -799,7 +862,9 @@ public:
mAllowShort,
mVolume,
mSLPoint,
mTPPoint //
mIgnoreSL,
mTPPoint,
mIgnoreTP //
);
//
@@ -856,7 +921,9 @@ public:
mAllowShort,
mVolume,
mSLPoint,
mTPPoint //
mIgnoreSL,
mTPPoint,
mIgnoreTP //
);
//
@@ -913,7 +980,9 @@ public:
mAllowShort,
mVolume,
mSLPoint,
mTPPoint //
mIgnoreSL,
mTPPoint,
mIgnoreTP //
);
//
@@ -970,7 +1039,9 @@ public:
mAllowShort,
mVolume,
mSLPoint,
mTPPoint //
mIgnoreSL,
mTPPoint,
mIgnoreTP //
);
//
@@ -1027,7 +1098,9 @@ public:
mAllowShort,
mVolume,
mSLPoint,
mTPPoint //
mIgnoreSL,
mTPPoint,
mIgnoreTP //
);
//
@@ -1039,111 +1112,109 @@ public:
);
}
}
}
//
// Parse Signals and Add them for Executing ...
// Here we can Save Signal and it's Conditions to
// Specified Collector then Update them on SL and TP ...
//
// Current Signals ...
if (cPusher > 0 && cSignal.IsValid())
{
//
AddRef(
cSignal,
signals //
);
//
AddNewSignal(
cPusher,
cSignal,
mBullishScore,
mBearishScore,
cConditions //
);
}
//
// Short Signals ...
if (sPusher > 0 && sSignal.IsValid())
{
//
AddRef(
sSignal,
signals //
);
// Parse Signals and Add them for Executing ...
//
AddNewSignal(
sPusher,
sSignal,
mBullishScore,
mBearishScore,
sConditions //
);
}
// Current Signals ...
if (cPusher > mReuiredSignalVerifications && cSignal.IsValid())
{
//
AddRef(
cSignal,
signals //
);
//
// Medium Signals ...
if (mPusher > 0 && mSignal.IsValid())
{
//
AddRef(
mSignal,
signals //
);
//
AddNewSignal(
cPusher,
cSignal,
mBullishScore,
mBearishScore,
cConditions //
);
}
//
AddNewSignal(
mPusher,
mSignal,
mBullishScore,
mBearishScore,
mConditions //
);
}
// Short Signals ...
if (sPusher > mReuiredSignalVerifications && sSignal.IsValid())
{
//
AddRef(
sSignal,
signals //
);
//
// Long Signals ...
if (lPusher > 0 && lSignal.IsValid())
{
//
AddRef(
lSignal,
signals //
);
//
AddNewSignal(
sPusher,
sSignal,
mBullishScore,
mBearishScore,
sConditions //
);
}
//
AddNewSignal(
lPusher,
lSignal,
mBullishScore,
mBearishScore,
lConditions //
);
}
// Medium Signals ...
if (mPusher > mReuiredSignalVerifications && mSignal.IsValid())
{
//
AddRef(
mSignal,
signals //
);
//
// Hind Signals ...
if (hPusher > 0 && hSignal.IsValid())
{
//
AddRef(
hSignal,
signals //
);
//
AddNewSignal(
mPusher,
mSignal,
mBullishScore,
mBearishScore,
mConditions //
);
}
//
AddNewSignal(
hPusher,
hSignal,
mBullishScore,
mBearishScore,
hConditions //
);
// Long Signals ...
if (lPusher > mReuiredSignalVerifications && lSignal.IsValid())
{
//
AddRef(
lSignal,
signals //
);
//
AddNewSignal(
lPusher,
lSignal,
mBullishScore,
mBearishScore,
lConditions //
);
}
//
// Hind Signals ...
if (hPusher > mReuiredSignalVerifications && hSignal.IsValid())
{
//
AddRef(
hSignal,
signals //
);
//
AddNewSignal(
hPusher,
hSignal,
mBullishScore,
mBearishScore,
hConditions //
);
}
}
//
@@ -1230,24 +1301,49 @@ public:
//
const bool result = false;
//
// Here we Implement Account Protector ...
HandleAccountProtect();
//
// Do all State Management here ...
// //
// // Check State Interval ...
// static datetime lastStateManaged = NULL;
// //
// datetime cTime = TimeCurrent();
// int interval = PeriodSeconds(PERIOD_M3);
// //
// bool canManageState =
// //
// !IsValid(lastStateManaged)
// ? true
// : (int)cTime >= (int)lastStateManaged + interval;
// //
// ;
// if (!canManageState)
// {
// return result;
// }
// //
// lastStateManaged = cTime;
// //
// // Retrieve Account Profit ...
// double profit = mTrader.Profit();
// //
// // Check EQM Orders and Handle Hedging ...
// DoEQMHedge();
//
// if Returns true, Signal Execution failed ...
return result;
}
//
// Tools For Signal Info Collect ...
//
// Used for Signal Info States ...
void OnDealsChangedHandler(int count)
void OnDealsChangedHandler(int count) override
{
//
XDeal deal;
@@ -1260,18 +1356,24 @@ public:
}
}
//
void OnGoingToProfit(XProfitTrack &track) override
{
// RemoveEQMOrders();
}
//
void OnGoingToDrawdown(XProfitTrack &track) override
{
// PlaceEQMOrders();
}
//
// Protected ...
protected:
//
// Tools ...
//
// Do All Protection Senarios here ...
void HandleAccountProtect()
{
}
//
// Private ...
private:
@@ -1279,11 +1381,14 @@ private:
// Props ...
//
bool mAllowLong; // Allow Long
bool mAllowShort; // Allow Short
double mVolume; // Volume
double mTPPoint; // TP Point
double mSLPoint; // SL Point
bool mAllowLong; // Allow Long
bool mAllowShort; // Allow Short
double mVolume; // Volume
double mTPPoint; // TP Point
double mSLPoint; // SL Point
bool mIgnoreTP; // Ignore Calculated TP
bool mIgnoreSL; // Ignore Calculated SL
int mReuiredSignalVerifications; // Required Verifications for Validate Signals
//
XSignalInfo mSignalInfos[];
@@ -1545,6 +1650,242 @@ private:
//
return result;
}
//
// EQM Functions ...
//
// Check and Hedge ...
void DoEQMHedge() {}
//
// Remove Untriggered EQM Orders ...
void RemoveEQMOrders()
{
//
RemoveDraws("XTRND");
//
XOrder supports[];
int supportsCount = mTrader.GetOrders(
supports,
NULL, // All Symbols ...
XEQMSupportToken, // Only EQM Supports ...
NULL, // All Periods ...
X_POSITION_TYPE_ALL, // All Order Types ...
ORDER_STATE_PLACED, // Untriggered Orders ...
true // Filter by Magic ...
);
if (!IsValidSize(supportsCount))
{
return;
}
//
int cancelled = mTrader.CancelOrders(
supports //
);
//
if (IsValidSize(cancelled))
{
//
string message = XEQMSupportToken + " Cancel " + ToString(cancelled) + " Supports ...";
//
Alert(message);
}
}
//
// Place EQM Orders ...
void PlaceEQMOrders()
{
//
int count = CountSetups();
if (!IsValidSize(count))
{
return;
}
//
XSignal supports[];
//
for (int i = 0; i < count; i++)
{
//
string iSymbol = mSetups[i].GetSymbol();
ENUM_TIMEFRAMES iPeriod = NULL; // All Periods ...
string iProvider = NULL; // All Providers ...
//
XPosition iPositions[];
int iPositionsCount = mTrader.GetPositions(
iPositions,
iSymbol,
iProvider,
iPeriod,
X_POSITION_TYPE_ALL //
);
if (!IsValidSize(iPositionsCount))
{
continue;
}
//
int maxInDIDX = FindMaxDrawdownIndex(
iPositions //
);
if (!IsValidIndex(maxInDIDX))
{
continue;
}
//
XPosition maxInDP = iPositions[maxInDIDX];
bool isLong = IsLong(maxInDP.type);
//
XOHCL iZBar;
bool isInited = iZBar.Init(
iSymbol,
iPeriod,
0 //
);
if (!isInited)
{
continue;
}
//
double iSupport = 0;
double iResistance = 0;
bool isDrawn = DrawTrendState(
ChartID(),
"XTRND",
iZBar,
iSupport,
iResistance //
);
if (isDrawn)
{
//
XSignal iSignal;
//
double iSL = 0;
double iTP = 0;
double iEntry = 0;
ENUM_POSITION_TYPE iType;
ENUM_X_ORDER_MODES iMode;
double iVolume = maxInDP.volume * 3;
//
if (iSupport > 0 && isLong && iSupport > maxInDP.sl && maxInDP.sl > 0)
{
//
// Add Short Support for Long ...
iEntry = iSupport;
iSL = maxInDP.tp;
iTP = maxInDP.sl;
iMode = X_ORDER_MODE_STOP;
iType = POSITION_TYPE_SELL;
//
bool isPrepared = iSignal.Prepare(
iSymbol,
XEQMSupportToken,
iPeriod,
iType,
iMode,
iEntry,
iVolume,
iSL,
iTP //
);
if (isPrepared)
{
//
iSignal.comment = GenerateSupportTag(maxInDP.ticket);
//
AddRef(
iSignal,
supports ///
);
//
iSignal.Clean();
}
}
//
if (iResistance > 0 && !isLong && iResistance < maxInDP.sl && maxInDP.sl > 0)
{
//
// Add Long Support for Short ...
iEntry = iResistance;
iSL = maxInDP.tp;
iTP = maxInDP.sl;
iMode = X_ORDER_MODE_STOP;
iType = POSITION_TYPE_BUY;
//
bool isPrepared = iSignal.Prepare(
iSymbol,
XEQMSupportToken,
iPeriod,
iType,
iMode,
iEntry,
iVolume,
iSL,
iTP //
);
if (isPrepared)
{
//
iSignal.comment = GenerateSupportTag(maxInDP.ticket);
//
AddRef(
iSignal,
supports ///
);
//
iSignal.Clean();
}
}
}
}
//
int supportsCount = ArraySize(supports);
if (!IsValidSize(supportsCount))
{
return;
}
//
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
int executeds = mTrader.ExecuteSignals(
supports,
states,
ORDER_TIME_GTC,
false,
false // Ignore Policies
);
if (IsValidSize(executeds))
{
//
string message = XEQMSupportToken + " Execute " + ToString(executeds) + " Supports ...";
//
Alert(message);
}
}
};
//
+1 -1
View File
@@ -3009,7 +3009,7 @@ protected:
symbol,
provider,
period,
ToOrderType(type),
type,
ORDER_STATE_PLACED,
true // Filter by Magic ...
//
+18 -18
View File
@@ -2523,14 +2523,14 @@ public:
//
// Retrieve All Orders ...
int GetOrders(
XOrder &result[], // Hold's Result
string symbol = NULL, // Trading Symbol
string provider = NULL, // Signal Provider
ENUM_TIMEFRAMES period = NULL, // Trading Period
ENUM_ORDER_TYPE type = NULL, // Long (Buy) or Short (Sell)
ENUM_ORDER_STATE state = NULL, // Order State
bool filterByMagic = true, // Get Only Self Open Positions
bool forceClean = true // Clean Result Array
XOrder &result[], // Hold's Result
string symbol = NULL, // Trading Symbol
string provider = NULL, // Signal Provider
ENUM_TIMEFRAMES period = NULL, // Trading Period
ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell)
ENUM_ORDER_STATE state = NULL, // Order State
bool filterByMagic = true, // Get Only Self Open Positions
bool forceClean = true // Clean Result Array
)
{
//
@@ -2605,16 +2605,16 @@ public:
//
// Retrieve Historical Orders ...
int GetOrders(
XOrder &result[], // Hold's Result
string symbol = NULL, // Trading Symbol
string provider = NULL, // Signal Provider
ENUM_TIMEFRAMES period = NULL, // Trading Period
ENUM_ORDER_TYPE type = NULL, // Long (Buy) or Short (Sell)
ENUM_ORDER_STATE state = NULL, // Order State
datetime startDate = NULL, // Specify Start Date
datetime endDate = NULL, // Specify End Date
bool filterByMagic = true, // Get Only Self Open Positions
bool forceClean = true // Clean Result Array
XOrder &result[], // Hold's Result
string symbol = NULL, // Trading Symbol
string provider = NULL, // Signal Provider
ENUM_TIMEFRAMES period = NULL, // Trading Period
ENUM_X_POSITION_TYPE type = NULL, // Long (Buy) or Short (Sell)
ENUM_ORDER_STATE state = NULL, // Order State
datetime startDate = NULL, // Specify Start Date
datetime endDate = NULL, // Specify End Date
bool filterByMagic = true, // Get Only Self Open Positions
bool forceClean = true // Clean Result Array
)
{
//