complete scoring and summary generating in x121 market cycle conditions class ...
This commit is contained in:
@@ -3711,6 +3711,109 @@ double GetAppliedPrice(
|
||||
return (0);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate TP/SL for Specified Type of Positions ...
|
||||
void CalculateTPSL(
|
||||
double &mSL, // Hold SL
|
||||
double &mTP, // Hold TP
|
||||
ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell)
|
||||
double mEntry, // Entry Price
|
||||
double mR2R = 1, // Provided Risk To Reward Ratio
|
||||
double slPrice = 0, // Provided SL Price
|
||||
double tpPrice = 0 // Provided TP Price
|
||||
)
|
||||
{
|
||||
//
|
||||
// if Both TP and SL Provided, ignore R2R and Calculate direct ...
|
||||
// if SL provided, Calculate TP based on Provided R2R ...
|
||||
// if TP provided, Calculate SL based on Provided R2R ...
|
||||
// default R2R is set to 1 ...
|
||||
|
||||
//
|
||||
mSL = 0;
|
||||
mTP = 0;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(mType);
|
||||
|
||||
//
|
||||
// Set Default R2R ...
|
||||
if (mR2R < 1)
|
||||
{
|
||||
mR2R = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (mEntry <= 0 ||
|
||||
(tpPrice <= 0 && slPrice <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double risk = 0;
|
||||
double reward = 0;
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnSL = slPrice > 0 &&
|
||||
(isLong
|
||||
? slPrice < mEntry
|
||||
: slPrice > mEntry);
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnTP = tpPrice > 0 &&
|
||||
(isLong
|
||||
? tpPrice > mEntry
|
||||
: tpPrice < mEntry);
|
||||
|
||||
//
|
||||
if (canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
risk = MathAbs(mEntry - slPrice);
|
||||
reward = risk * mR2R;
|
||||
}
|
||||
else if (!canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
reward = MathAbs(mEntry - tpPrice);
|
||||
risk = reward / mR2R;
|
||||
}
|
||||
else if (!canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
bool canSetTPPrice = isLong
|
||||
? tpPrice > mEntry
|
||||
: tpPrice < mEntry;
|
||||
if (canSetTPPrice)
|
||||
{
|
||||
mTP = tpPrice;
|
||||
}
|
||||
|
||||
//
|
||||
bool canSetSLPrice = isLong
|
||||
? slPrice < mEntry
|
||||
: slPrice > mEntry;
|
||||
if (canSetSLPrice)
|
||||
{
|
||||
mSL = slPrice;
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mTP = isLong
|
||||
? mEntry + reward
|
||||
: mEntry - reward;
|
||||
|
||||
//
|
||||
mSL = isLong
|
||||
? mEntry - reward
|
||||
: mEntry + reward;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
|
||||
@@ -5792,8 +5895,8 @@ string ToString(
|
||||
string prefix, // Title
|
||||
bool value, // Value
|
||||
bool ignoreFalseConditions = true, // Ignore False Conditions
|
||||
string prefixSeparator = ":", // Title Separator
|
||||
string lineSeparator = "\n" // Line Separator
|
||||
string lineSeparator = "\n", // Line Separator
|
||||
string prefixSeparator = ":" // Title Separator
|
||||
)
|
||||
{
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user