355 lines
7.1 KiB
Plaintext
355 lines
7.1 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// ----------------------------------------------
|
|
// Name: XSCX121XTEST
|
|
// Description: X121 XTEST Signal Provider ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
#include "../Libraries/x-saherelm.x121.condition.parser.lib.mq5"
|
|
|
|
//
|
|
// CONDITIONS ...
|
|
|
|
//
|
|
// Longs ...
|
|
bool IsXTESTHasLongSignal(
|
|
const X121MarketConditions &conditions, // Specified Conditions
|
|
int index = 0 // Array Index
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isTrendBullish = IsTrendBullish(conditions, index);
|
|
bool isCandleBullish = IsBullishCandle(conditions.candles[1]);
|
|
bool isValidTrend = ArraySize(conditions.xmanInfo.trendChanges) > 2 &&
|
|
conditions.xmanInfo.trends[0] > conditions.xmanInfo.trends[1] &&
|
|
conditions.xmanInfo.trends[0] > conditions.xmanInfo.trendChanges[0].from;
|
|
|
|
//
|
|
result =
|
|
//
|
|
isValidTrend &&
|
|
isTrendBullish &&
|
|
isCandleBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Shorts ...
|
|
bool IsXTESTHasShortSignal(
|
|
const X121MarketConditions &conditions, // Specified Conditions
|
|
int index = 0 // Array Index
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isTrendBearish = IsTrendBearish(conditions, index);
|
|
bool isCandleBearish = IsBearishCandle(conditions.candles[1]);
|
|
bool isValidTrend = ArraySize(conditions.xmanInfo.trendChanges) > 2 &&
|
|
conditions.xmanInfo.trends[0] < conditions.xmanInfo.trends[1] &&
|
|
conditions.xmanInfo.trends[0] < conditions.xmanInfo.trendChanges[0].from;
|
|
|
|
//
|
|
result =
|
|
//
|
|
isValidTrend &&
|
|
isTrendBearish &&
|
|
isCandleBearish
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// CALCULATIONS ...
|
|
|
|
//
|
|
// Calculate Long Stop ...
|
|
double CalculateXTESTLongStop(const X121MarketConditions &conditions)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
result =
|
|
//
|
|
conditions.xmanInfo.vales[0]
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Calculate Long Take Profits ...
|
|
double CalculateXTESTLongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
if (sl > 0 && entry > 0 && r2r > 0)
|
|
{
|
|
//
|
|
double riskPrice = MathAbs(entry - sl);
|
|
double rewardPrice = riskPrice * r2r;
|
|
|
|
//
|
|
result = entry + rewardPrice;
|
|
}
|
|
else
|
|
{
|
|
result = entry + PointToPrice(conditions.symbol, 60);
|
|
}
|
|
|
|
//
|
|
double peak = conditions.xmanInfo.peaks[1];
|
|
result =
|
|
entry >= peak
|
|
? entry + PointToPrice(conditions.symbol, 60)
|
|
: peak;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Calculate Short Stop ...
|
|
double CalculateXTESTShortStop(const X121MarketConditions &conditions)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
result =
|
|
//
|
|
conditions.xmanInfo.peaks[0]
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Calculate Short Take Profits ...
|
|
double CalculateXTESTShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
if (sl > 0 && entry > 0 && r2r > 0)
|
|
{
|
|
//
|
|
double riskPrice = MathAbs(entry - sl);
|
|
double rewardPrice = riskPrice * r2r;
|
|
|
|
//
|
|
result = entry - rewardPrice;
|
|
}
|
|
else
|
|
{
|
|
result = entry - PointToPrice(conditions.symbol, 60);
|
|
}
|
|
|
|
//
|
|
double vale = conditions.xmanInfo.vales[1];
|
|
result =
|
|
entry <= vale
|
|
? entry - PointToPrice(conditions.symbol, 60)
|
|
: vale;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// SIGNALS ...
|
|
|
|
//
|
|
// Generate Signal ...
|
|
bool GenerateXTESTSignal(
|
|
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
|
|
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
|
|
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
|
|
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isLong = IsLong(type);
|
|
|
|
//
|
|
// Retrieve Entry Price ...
|
|
double entry = GetEntry(
|
|
conditions.symbol,
|
|
type);
|
|
|
|
//
|
|
result =
|
|
//
|
|
isLong
|
|
? IsXTESTHasLongSignal(conditions)
|
|
: IsXTESTHasShortSignal(conditions)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
Add(
|
|
ToString(XTEST),
|
|
conditions.signal.providers);
|
|
|
|
//
|
|
double sl =
|
|
//
|
|
isLong
|
|
? CalculateXTESTLongStop(conditions)
|
|
: CalculateXTESTShortStop(conditions)
|
|
//
|
|
;
|
|
|
|
//
|
|
double r2r = 1.5;
|
|
|
|
//
|
|
double tp =
|
|
//
|
|
isLong
|
|
? CalculateXTESTLongTarget(conditions, sl, entry, r2r)
|
|
: CalculateXTESTShortTarget(conditions, sl, entry, r2r)
|
|
//
|
|
;
|
|
|
|
//
|
|
double volume = 0.01;
|
|
|
|
//
|
|
conditions.hasSignal = true;
|
|
|
|
//
|
|
conditions.signal.type = type;
|
|
conditions.signal.symbol = conditions.symbol;
|
|
conditions.signal.period = conditions.period;
|
|
conditions.signal.supportResistances = supportAndResistances;
|
|
|
|
//
|
|
conditions.signal.sl = 0; // sl;
|
|
conditions.signal.tp = tp;
|
|
conditions.signal.r2r = r2r;
|
|
conditions.signal.entry = entry;
|
|
conditions.signal.volume = volume;
|
|
conditions.signal.mode = X_ORDER_MODE_MARKET;
|
|
|
|
//
|
|
if (generateSupports)
|
|
{
|
|
//
|
|
// Generate Required Support Signals ...
|
|
GenerateXTESTSignalSupports(conditions);
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// SUPPORTS ...
|
|
|
|
//
|
|
// Generate Required Support Signals and Attached Them into
|
|
// Exists Signal of Conditions ...
|
|
int GenerateXTESTSignalSupports(
|
|
X121MarketConditions &conditions)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// GUARDS ...
|
|
|
|
//
|
|
// Check Can Force Close All XTEST Long Signals or not ...
|
|
bool CanXTESTForceCloseLongs(const X121MarketConditions &conditions)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
|
|
|
|
//
|
|
result =
|
|
//
|
|
false
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check for Trailing Long Positions Stops ...
|
|
bool CanXTESTTrailLongsStop(
|
|
const X121MarketConditions &conditions,
|
|
double &newSL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check For Trailing Short Positions Stops ...
|
|
bool CanXTESTTrailShortsStop(
|
|
const X121MarketConditions &conditions,
|
|
double &newSL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
return result;
|
|
}
|