complete srbr strategy ...
This commit is contained in:
@@ -4641,6 +4641,86 @@ bool CalculateTPSLByPoint(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool CalculateTPSLBtPrice(
|
||||
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
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(mType);
|
||||
|
||||
//
|
||||
// Set Default R2R ...
|
||||
if (mR2R < 1)
|
||||
{
|
||||
mR2R = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (mEntry <= 0 ||
|
||||
(mSL <= 0 && mTP <= 0))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double risk = 0;
|
||||
double reward = 0;
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnSL = mSL > 0;
|
||||
bool canCalculateBasedOnTP = mTP > 0;
|
||||
|
||||
//
|
||||
if (
|
||||
!canCalculateBasedOnSL &&
|
||||
!canCalculateBasedOnTP)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (!canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
reward = MathAbs(mTP - mEntry);
|
||||
risk = reward / mR2R;
|
||||
}
|
||||
else if (canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
risk = MathAbs(mEntry - mSL);
|
||||
reward = risk * mR2R;
|
||||
}
|
||||
|
||||
//
|
||||
result = risk > 0 && reward > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mTP = isLong
|
||||
? mEntry + reward
|
||||
: mEntry - reward;
|
||||
|
||||
//
|
||||
mSL = isLong
|
||||
? mEntry - risk
|
||||
: mEntry + risk;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetTick(
|
||||
string mSymbol,
|
||||
|
||||
@@ -1082,16 +1082,16 @@ struct XPivot
|
||||
;
|
||||
if (result)
|
||||
{
|
||||
DrawArrow(
|
||||
0,
|
||||
"PBar",
|
||||
0,
|
||||
pBar.time,
|
||||
pBar.low,
|
||||
233,
|
||||
ANCHOR_TOP,
|
||||
clrYellow //
|
||||
);
|
||||
// DrawArrow(
|
||||
// 0,
|
||||
// "PBar",
|
||||
// 0,
|
||||
// pBar.time,
|
||||
// pBar.low,
|
||||
// 233,
|
||||
// ANCHOR_TOP,
|
||||
// clrYellow //
|
||||
// );
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user