last works on create X121Setup ...
This commit is contained in:
@@ -2405,6 +2405,9 @@ struct XBarTracker
|
||||
//
|
||||
int lastTrackedBar; // Last Tracked Bar ...
|
||||
|
||||
//
|
||||
bool waitsUntilNext; // Waits Until Next Bar ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XBarTracker()
|
||||
@@ -2473,6 +2476,37 @@ struct XBarTracker
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool CanProcessBar()
|
||||
{
|
||||
//
|
||||
bool isInTestMode = IsRunningOnTestMode();
|
||||
|
||||
//
|
||||
bool isNewBar = IsNewBar();
|
||||
|
||||
//
|
||||
bool result =
|
||||
isInTestMode
|
||||
? isNewBar
|
||||
: !waitsUntilNext
|
||||
? true
|
||||
: isNewBar;
|
||||
if (result && waitsUntilNext)
|
||||
{
|
||||
waitsUntilNext = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void Waits()
|
||||
{
|
||||
this.waitsUntilNext = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
void Clean()
|
||||
@@ -4516,6 +4550,29 @@ void CalculateTPSL(
|
||||
//
|
||||
return;
|
||||
}
|
||||
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
|
||||
@@ -4528,6 +4585,100 @@ void CalculateTPSL(
|
||||
: mEntry + risk;
|
||||
}
|
||||
|
||||
//
|
||||
bool CalculateTPSLByPoint(
|
||||
double &mSL, // Hold SL
|
||||
double &mTP, // Hold TP
|
||||
ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell)
|
||||
double mEntry, // Entry Price
|
||||
double mPointValue, // Point Value
|
||||
double mR2R = 1, // Provided Risk To Reward Ratio
|
||||
double slPoint = 0, // Provided SL Point
|
||||
double tpPoint = 0 // Provided TP Point
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSL = 0;
|
||||
mTP = 0;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(mType);
|
||||
|
||||
//
|
||||
// Set Default R2R ...
|
||||
if (mR2R < 1)
|
||||
{
|
||||
mR2R = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (mEntry <= 0 ||
|
||||
mPointValue <= 0 ||
|
||||
(slPoint <= 0 && tpPoint <= 0))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double risk = 0;
|
||||
double reward = 0;
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnSL = slPoint > 0;
|
||||
|
||||
//
|
||||
bool canCalculateBasedOnTP = tpPoint > 0;
|
||||
|
||||
//
|
||||
if (!canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
reward = tpPoint * mPointValue;
|
||||
risk = slPoint * mPointValue;
|
||||
}
|
||||
else if (!canCalculateBasedOnSL && canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
reward = tpPoint * mPointValue;
|
||||
risk = reward / mR2R;
|
||||
}
|
||||
else if (canCalculateBasedOnSL && !canCalculateBasedOnTP)
|
||||
{
|
||||
//
|
||||
risk = slPoint * mPointValue;
|
||||
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,
|
||||
@@ -6161,14 +6312,14 @@ double GetAverage(
|
||||
//
|
||||
// Get Max of Specific Loopback of a Buffer ...
|
||||
template <typename T>
|
||||
double GetMax(
|
||||
T GetMax(
|
||||
T &buffer[], // the Buffer which required to search
|
||||
int start = 0, // Start Index
|
||||
int count = 0 // Count for Search
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
T result = 0;
|
||||
|
||||
//
|
||||
if (count <= 0)
|
||||
@@ -6195,7 +6346,7 @@ double GetMax(
|
||||
for (int i = 0; i < tmpCount; i++)
|
||||
{
|
||||
//
|
||||
double iValue = tmp[i];
|
||||
T iValue = tmp[i];
|
||||
|
||||
//
|
||||
result =
|
||||
@@ -6216,14 +6367,14 @@ double GetMax(
|
||||
//
|
||||
// Get Min of Specific Loopback of a Buffer ...
|
||||
template <typename T>
|
||||
double GetMin(
|
||||
T GetMin(
|
||||
T &buffer[], // the Buffer which required to search
|
||||
int start = 0, // Start Index
|
||||
int count = 0 // Count for Search
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
T result = 0;
|
||||
|
||||
//
|
||||
if (count <= 0)
|
||||
@@ -6250,7 +6401,7 @@ double GetMin(
|
||||
for (int i = 0; i < tmpCount; i++)
|
||||
{
|
||||
//
|
||||
double iValue = tmp[i];
|
||||
T iValue = tmp[i];
|
||||
|
||||
//
|
||||
result =
|
||||
|
||||
Reference in New Issue
Block a user