Add Opposit Signal Generator Function in XSignal Structure ...
This commit is contained in:
@@ -3093,64 +3093,19 @@ public:
|
|||||||
// Generate Opposit Signal ...
|
// Generate Opposit Signal ...
|
||||||
|
|
||||||
//
|
//
|
||||||
XSignal sSignal;
|
// XSignal sSignal;
|
||||||
|
// bool isGenerated = mSignal.GenerateOpposit(sSignal);
|
||||||
|
// if (isGenerated)
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// // mSignal = sSignal;
|
||||||
|
|
||||||
//
|
// //
|
||||||
ENUM_POSITION_TYPE mType = IsLong(mSignal.type)
|
// AddRef(
|
||||||
? POSITION_TYPE_SELL
|
// sSignal,
|
||||||
: POSITION_TYPE_BUY;
|
// mSignal.supports //
|
||||||
|
// );
|
||||||
//
|
// }
|
||||||
bool isSLong = IsLong(mType);
|
|
||||||
|
|
||||||
//
|
|
||||||
double sEntry = GetEntry(
|
|
||||||
mSignal.symbol,
|
|
||||||
mType //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
double risk = MathAbs(mSignal.entry - sl);
|
|
||||||
|
|
||||||
//
|
|
||||||
double reward = risk * r2r;
|
|
||||||
|
|
||||||
//
|
|
||||||
double sSL = isSLong
|
|
||||||
? entry - risk
|
|
||||||
: entry + risk;
|
|
||||||
|
|
||||||
//
|
|
||||||
double sTP = isSLong
|
|
||||||
? entry + reward
|
|
||||||
: entry - reward;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isPrepared = sSignal.Prepare(
|
|
||||||
mSignal.symbol,
|
|
||||||
mSignal.provider,
|
|
||||||
mSignal.period,
|
|
||||||
mType,
|
|
||||||
mSignal.mode,
|
|
||||||
sEntry,
|
|
||||||
mSignal.volume,
|
|
||||||
mSignal.action,
|
|
||||||
sSL,
|
|
||||||
sTP //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (isPrepared)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// mSignal = sSignal;
|
|
||||||
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
sSignal,
|
|
||||||
mSignal.supports //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1467,7 +1467,8 @@ struct XOHCL
|
|||||||
// Candlestic Tools ...
|
// Candlestic Tools ...
|
||||||
|
|
||||||
//
|
//
|
||||||
bool IsDoji() {
|
bool IsDoji()
|
||||||
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
@@ -1475,7 +1476,8 @@ struct XOHCL
|
|||||||
// Validate Content and Ignore 0 Bar
|
// Validate Content and Ignore 0 Bar
|
||||||
// since it is not Completed ...
|
// since it is not Completed ...
|
||||||
result = IsValid() && Index() > 0;
|
result = IsValid() && Index() > 0;
|
||||||
if (!result) {
|
if (!result)
|
||||||
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2919,6 +2921,37 @@ bool IsShort(ENUM_ORDER_TYPE type)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Opposit Direction Type ...
|
||||||
|
ENUM_POSITION_TYPE GetOpposit(ENUM_POSITION_TYPE type)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ENUM_POSITION_TYPE result = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(type);
|
||||||
|
result = isLong
|
||||||
|
? POSITION_TYPE_SELL
|
||||||
|
: POSITION_TYPE_BUY;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
ENUM_ORDER_TYPE GetOpposit(ENUM_ORDER_TYPE type)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
ENUM_ORDER_TYPE result = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(type);
|
||||||
|
result = isLong
|
||||||
|
? ORDER_TYPE_SELL
|
||||||
|
: ORDER_TYPE_BUY;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check Expert Running in Testing Mode or not ...
|
// Check Expert Running in Testing Mode or not ...
|
||||||
bool IsRunningOnTestMode()
|
bool IsRunningOnTestMode()
|
||||||
|
|||||||
@@ -637,6 +637,73 @@ struct XSignal
|
|||||||
//
|
//
|
||||||
// Tools ...
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Generate Opposit Direction ...
|
||||||
|
bool GenerateOpposit(
|
||||||
|
XSignal &mSignal // Oppsoit Signal
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_POSITION_TYPE mType = GetOpposit(this.type);
|
||||||
|
double mEntry = GetExit(this.symbol, mType);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isLong = IsLong(mType);
|
||||||
|
|
||||||
|
//
|
||||||
|
double mTP = 0;
|
||||||
|
this.RegularTP(mTP);
|
||||||
|
|
||||||
|
//
|
||||||
|
double mSL = 0;
|
||||||
|
this.RegularSL(mSL);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Risk Reward Ratio ...
|
||||||
|
double risk = MathAbs(this.entry - mSL);
|
||||||
|
double reward = MathAbs(this.entry - mTP);
|
||||||
|
|
||||||
|
//
|
||||||
|
double r2r = reward / risk;
|
||||||
|
|
||||||
|
//
|
||||||
|
mSL = isLong
|
||||||
|
? mEntry - risk
|
||||||
|
: mEntry + risk;
|
||||||
|
|
||||||
|
//
|
||||||
|
mTP = isLong
|
||||||
|
? mEntry + reward
|
||||||
|
: mEntry - reward;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = mSignal.Prepare(
|
||||||
|
this.symbol,
|
||||||
|
this.provider,
|
||||||
|
this.period,
|
||||||
|
mType,
|
||||||
|
this.mode,
|
||||||
|
mEntry,
|
||||||
|
this.volume,
|
||||||
|
this.action,
|
||||||
|
mSL,
|
||||||
|
mTP //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Cleanup ...
|
// Cleanup ...
|
||||||
void Clean()
|
void Clean()
|
||||||
|
|||||||
Reference in New Issue
Block a user