last works ...

This commit is contained in:
2024-05-24 11:46:15 +03:30
parent dc4ee66b83
commit 7a50508816
10 changed files with 1515 additions and 567 deletions
+151 -423
View File
@@ -311,15 +311,15 @@ struct XSignal
//
bool PrepareLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -340,15 +340,15 @@ struct XSignal
//
bool PrepareShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
ENUM_X_ORDER_MODES mMode, // Execution Mode
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -372,14 +372,14 @@ struct XSignal
//
bool PrepareMarketLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -399,14 +399,14 @@ struct XSignal
//
bool PrepareMarketShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -429,14 +429,14 @@ struct XSignal
//
bool PrepareStopLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -456,14 +456,14 @@ struct XSignal
//
bool PrepareStopShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -486,14 +486,14 @@ struct XSignal
//
bool PrepareLimitLong(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -513,14 +513,14 @@ struct XSignal
//
bool PrepareLimitShort(
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
string mSymbol, // Trading Symbol
string mProvider, // Signal Provider
ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame
double mEntry, // Entry Price
double mVolume, // Volume
ENUM_X_SIGNAL_MANAGING_ACTIONS mAction = X_SIGNAL_USE_NOTHING, // Signal Management Action
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
double sl = 0, // Stop Loss
double tp = 0 // Take Profit
)
{
//
@@ -2637,153 +2637,114 @@ struct XPositionPack
};
//
// Use for Manage Positions ...
struct XPositionInfo
// Check Position SL Trails Structure ...
struct XTrail
{
//
// Props ...
ulong ticket; // Position Ticket
//
double tps[]; // Un Touched Tps ( not include regular TP ) / For Managing using XTrade Class ...
double sls[]; // Un Touched Sls ( not include regular SL ) / For Managing using XTrade Class ...
//
ENUM_X_SIGNAL_MANAGING_ACTIONS action; // Managing Action
double profits[]; // Check Postion profit
datetime times[]; // Last Times prfoit Checking
ulong ticket; // Position Ticket ...
ENUM_POSITION_TYPE type; // Type ...
datetime time; // Trail Time ...
double before; // SL Value Before Trailing ...
double after; // SL Value After Trailing ...
int level; // Number of Trails SL ...
double profit; // Profit in SL Time ...
//
// Constructor ...
void XPositionInfo()
XTrail()
{
Clean();
}
//
// Fill from a Signal ...
// The Signal must Executed ...
bool BySignal(
XSignal &mSignal // the Signal which need to use
)
{
//
bool result = false;
//
Clean();
//
result = mSignal.IsValid() && mSignal.IsExecuted() && mSignal.mode == X_ORDER_MODE_MARKET;
if (!result)
{
return result;
}
//
ticket = mSignal.positionId;
action = mSignal.action;
//
// Select TPS and SLS from signal ...
//
double sl = 0;
bool hasRegularSL = mSignal.RegularSL(sl);
Copy(
mSignal.sls,
sls
//
);
if (hasRegularSL)
{
//
Remove(
sl,
sls
//
);
}
//
double tp = 0;
bool hasRegularTP = mSignal.RegularTP(tp);
Copy(
mSignal.tps,
tps
//
);
if (hasRegularTP)
{
//
Remove(
tp,
tps
//
);
}
//
return result;
}
//
// Fill from a Position ...
bool ByPosition(
XPosition &position // the Position which need to use
)
{
//
bool result = false;
//
Clean();
//
result = position.IsValid();
if (!result)
{
return result;
}
//
ticket = position.ticket;
//
datetime time = TimeCurrent();
//
Add(
time,
times
//
);
Add(
position.profit,
profits
//
);
//
return result;
}
//
// Tools ...
//
bool Init(
ulong mTicket, // Ticket
ENUM_POSITION_TYPE mType, // Type
double mProfit, // Profit
double mBefore, // Before
double mAfter // After
)
{
//
Clean();
//
type = mType;
after = mAfter;
ticket = mTicket;
before = mBefore;
profit = mProfit;
//
level++;
//
time = TimeCurrent();
//
return IsValid();
}
//
bool Update(
double mSl, // new SL ...
double mProfit // Profit
)
{
//
bool result = false;
//
time = TimeCurrent();
//
double cAfter = after;
after = mSl;
before = cAfter;
profit = mProfit;
//
level++;
//
result = IsValid();
//
return result;
}
//
string GenerateTag()
{
//
string result = NULL;
//
string ticketLevelStr = ToString(ticket) + "," + ToString(level);
//
result = Surround(
XSLTrailToken,
ticketLevelStr //
);
//
return result;
}
//
// Cleanup ...
void Clean()
{
//
ticket = 0;
//
Clean(tps);
Clean(sls);
Clean(times);
Clean(profits);
time = 0;
before = 0;
after = 0;
level = 0;
}
//
@@ -2793,125 +2754,18 @@ struct XPositionInfo
//
bool result = false;
//
result = NotEmpty(ticket) && ticket > 0;
//
return result;
}
//
// Check this instance is Same os Given instance or not ...
bool IsSameAs(
const XPositionInfo &value // instance for Compare
)
{
//
bool result = false;
//
result =
//
ticket == value.ticket
ticket > 0 &&
time > 0 &&
level > 0
//
;
//
return result;
}
//
// Find index in a Collection ...
int FindIndex(
const XPositionInfo &values[] // Collection to Find
)
{
//
return FindIndex(
this,
values
//
);
}
//
// Retrieve Token ...
string GetToken()
{
return GetToken(this);
}
//
bool IsModelValid()
{
return IsValid();
}
//
// Convert to String Representation
string ToModelString()
{
//
string result = NULL;
//
if (!IsValid())
{
return result;
}
//
string ticketStr = Surround(XTicketToken, ticket);
string actionStr = Surround(XActionToken, action);
//
string tpsStr = SurroundArray(XTPToken, tps);
string slsStr = SurroundArray(XSLToken, sls);
string timesStr = SurroundArray(XTimeToken, times);
string profitsStr = SurroundArray(XProfitToken, profits);
//
result =
//
GetToken() + "[" +
//
ticketStr +
actionStr +
tpsStr +
slsStr +
timesStr +
profitsStr +
//
"]"
//
;
//
return result;
}
//
// Parse and Fill from Given String Representation
bool ParseModel(string value)
{
//
bool result = false;
//
ticket = ParseLongSurrounded(value, XTicketToken);
action = ((ENUM_X_SIGNAL_MANAGING_ACTIONS)ParseIntSurrounded(value, XActionToken));
//
ParseDoubleArraySurrounded(tps, value, XTPToken);
ParseDoubleArraySurrounded(sls, value, XSLToken);
ParseDoubleArraySurrounded(profits, value, XProfitToken);
ParseTimeArraySurrounded(times, value, XTimeToken);
//
result = IsValid();
//
return result;
}
};
//
@@ -3120,132 +2974,6 @@ private:
// Tools ...
};
//
// Create a Position Info Data Collector ...
class XSCPositionInfoCollector
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
void XSCPositionInfoCollector()
{
//
XSCDataCollector<XPositionInfo> mBase;
mBase.Clear();
}
//
// Deconstructor ...
//
// Tools ...
//
// Inheritanced Functions ...
//
// Cleaning Store ...
void Clear()
{
//
XSCDataCollector<XPositionInfo> mBase;
//
mBase.Clear();
}
//
// Collect All Store ...
int Collect(XPositionInfo &result[])
{
//
int mResult = 0;
//
XSCDataCollector<XPositionInfo> mBase;
//
mResult = mBase.Collect(result);
//
return mResult;
}
//
// Add Item To Store ...
bool Add(XPositionInfo &item)
{
//
bool result = false;
//
XSCDataCollector<XPositionInfo> mBase;
//
result = mBase.Add(item);
//
return result;
}
//
// Add Item(s) To Store ...
int Add(XPositionInfo &items[])
{
//
int result = 0;
//
XSCDataCollector<XPositionInfo> mBase;
//
result = mBase.Add(items);
//
return result;
}
//
// Remove an Item from Store ...
bool Remove(XPositionInfo &item)
{
//
bool result = false;
//
XSCDataCollector<XPositionInfo> mBase;
//
result = mBase.Remove(item);
//
return result;
}
//
// Custom Functions ...
//
// Protected ...
protected:
//
// Tools ...
//
// Private ...
private:
//
// Props ...
//
// Tools ...
};
//
// Tools ...