Files
xMQL5/MQLTestWorkspace/BKPS/old.mq5
T
2024-05-11 05:36:03 +03:30

315 lines
8.3 KiB
Plaintext

//
// Prepare Signal ...
void PrepareConditionsSignal(X121MarketConditions &conditions)
{
//
if (!conditions.hasSignal)
{
return;
}
//
bool isLong = IsLong(conditions.signal.type);
//
// Check Calculate TP ...
if (
conditions.signal.sl > 0 &&
conditions.signal.tp <= 0 &&
conditions.signal.r2r > 0 &&
conditions.signal.entry > 0)
{
//
double riskPrice = MathAbs(conditions.signal.entry - conditions.signal.sl);
double riskPoint = PriceToPoint(
conditions.signal.symbol,
riskPrice);
double rewardPoint = riskPoint * conditions.signal.r2r;
double rewardPrice = PointToPrice(
conditions.signal.symbol,
rewardPoint);
//
double tp =
isLong
? conditions.signal.entry + rewardPrice
: conditions.signal.entry - rewardPrice;
//
conditions.signal.tp = tp;
}
//
PrepareSignal(conditions.signal);
//
conditions.signal.supportAndResistance = conditions.supportResistances;
}
//
// TODO: Delete This ...
void DrawConditionsSignalOnChart(X121MarketConditions &conditions)
{
//
ulong mTicket = MathRand() * 100000;
//
DrawSignal(
mTicket,
conditions.signal);
//
DrawSupportResistance(
0,
conditions.supportResistances,
conditions.signal.providers[0]);
}
//
// Catch Trend Changes ...
if (ArraySize(trendStateBuffer) > 1)
{
//
bool isChanged =
trendStateBuffer[0] != trendStateBuffer[1] &&
trendStateBuffer[0] != EMPTY_VALUE;
if (isChanged)
{
//
double to = trendBuffer[0];
double from = trendBuffer[1];
ENUM_XMAN_STATES state = (ENUM_XMAN_STATES)(int)trendStateBuffer[0];
datetime at = iTime(
mSymbol,
mPeriod,
barIndex);
//
XValueChanged lastChange;
bool hasLastChange = GetLastItem(
lastChange,
trendChanges);
bool canAdd =
!hasLastChange
? true
: lastChange.at < at;
//
if (canAdd)
{
//
// Here also we Free Trend Changes Sizes if
// its More than 500 ...
if (ArraySize(trendChanges) >= 500)
{
//
// Retrieve Last Change model and add theme
// again ...
//
Clean(trendChanges);
//
if (hasLastChange)
{
//
Add(
lastChange,
trendChanges);
}
}
//
XValueChanged model;
//
model.to = to;
model.from = from;
model.at = at;
//
Add(
model,
trendChanges);
// //
// LogMessage(
// "Trend Changed On: " + ToString(trendChangeddOn) +
// "\n state: " + EnumToString(state) +
// "\n from: " + ToString(lastTrend) +
// "\n to: " + ToString(trend) +
// "\n"
// //
// );
}
}
}
//
Copy(
trendChanges,
result.trendChanges);
ArraySetAsSeries(
result.trendChanges,
true);
//
// Catch Peaks Changes ...
if (ArraySize(peaksBuffer) > 1)
{
//
bool isPeakChanged =
peaksBuffer[0] != peaksBuffer[1] &&
peaksBuffer[0] != EMPTY_VALUE;
if (isPeakChanged)
{
//
double peak = peaksBuffer[0];
double lastPeak = peaksBuffer[1];
//
datetime at = iTime(
mSymbol,
mPeriod,
barIndex);
//
XValueChanged lastChange;
bool hasLastChange = GetLastItem(
lastChange,
peakChanges);
bool canAdd =
!hasLastChange
? true
: lastChange.at < at;
//
if (canAdd)
{
//
// Here also we Free Trend Changes Sizes if
// its More than 500 ...
if (ArraySize(peakChanges) >= 500)
{
//
// Retrieve Last Change model and add theme
// again ...
//
Clean(peakChanges);
//
if (hasLastChange)
{
//
Add(
lastChange,
peakChanges);
}
}
//
XValueChanged model;
//
model.to = peak;
model.from = lastPeak;
model.at = at;
//
Add(
model,
peakChanges);
}
}
}
//
Copy(
peakChanges,
result.peakChanges);
ArraySetAsSeries(
result.peakChanges,
true);
//
// Catch Vales Changes ...
if (ArraySize(valesBuffer) > 1)
{
//
bool isChanged =
valesBuffer[0] != valesBuffer[1] &&
valesBuffer[0] != EMPTY_VALUE;
if (isChanged)
{
//
double peak = peaksBuffer[0];
double lastPeak = peaksBuffer[1];
//
datetime at = iTime(
mSymbol,
mPeriod,
barIndex);
//
XValueChanged lastChange;
bool hasLastChange = GetLastItem(
lastChange,
peakChanges);
bool canAdd =
!hasLastChange
? true
: lastChange.at < at;
//
if (canAdd)
{
//
// Here also we Free Trend Changes Sizes if
// its More than 500 ...
if (ArraySize(peakChanges) >= 500)
{
//
// Retrieve Last Change model and add theme
// again ...
//
Clean(peakChanges);
//
if (hasLastChange)
{
//
Add(
lastChange,
peakChanges);
}
}
//
XValueChanged model;
//
model.to = peak;
model.from = lastPeak;
model.at = at;
//
Add(
model,
peakChanges);
}
}
}
//
Copy(
peakChanges,
result.peakChanges);
ArraySetAsSeries(
result.peakChanges,
true);