last ...
This commit is contained in:
@@ -26,9 +26,9 @@
|
|||||||
//
|
//
|
||||||
#include <ChartObjects/ChartObject.mqh>
|
#include <ChartObjects/ChartObject.mqh>
|
||||||
#include <ChartObjects/ChartObjectsArrows.mqh>
|
#include <ChartObjects/ChartObjectsArrows.mqh>
|
||||||
|
#include <ChartObjects/ChartObjectsFibo.mqh>
|
||||||
#include <ChartObjects/ChartObjectsLines.mqh>
|
#include <ChartObjects/ChartObjectsLines.mqh>
|
||||||
#include <ChartObjects/ChartObjectsShapes.mqh>
|
#include <ChartObjects/ChartObjectsShapes.mqh>
|
||||||
#include <ChartObjects/ChartObjectsFibo.mqh>
|
|
||||||
#include <ChartObjects/ChartObjectsTxtControls.mqh>
|
#include <ChartObjects/ChartObjectsTxtControls.mqh>
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -155,6 +155,207 @@ string ToString(ENUM_X_CHART_IDS value)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Library Functions ...
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a XBoxZone struct to XSignal instance ...
|
||||||
|
*
|
||||||
|
* @param box: XBoxZone instance reference, provide source info ...
|
||||||
|
* @param signal: XSignal instance reference, holds prepared converted signal ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool ToSignal(
|
||||||
|
XBoxZone &box,
|
||||||
|
XSignal &signal,
|
||||||
|
double &rewardRatios[] //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
signal.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
result = box.IsValid() &&
|
||||||
|
HasChild(rewardRatios);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
XOHCL entryBar;
|
||||||
|
result = entryBar.Init(
|
||||||
|
box.symbol,
|
||||||
|
box.period,
|
||||||
|
box.ToIndex() - 1 //
|
||||||
|
);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
entryBar.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isBullish = box.IsBullish();
|
||||||
|
bool isBearish = box.IsBearish();
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_POSITION_TYPE iType =
|
||||||
|
isBullish
|
||||||
|
? POSITION_TYPE_BUY
|
||||||
|
: POSITION_TYPE_SELL;
|
||||||
|
ENUM_X_POSITION_TYPES iXType =
|
||||||
|
isBullish
|
||||||
|
? X_POSITION_TYPE_LONG
|
||||||
|
: X_POSITION_TYPE_SHORT;
|
||||||
|
|
||||||
|
//
|
||||||
|
double points = GetPoints(box.symbol);
|
||||||
|
|
||||||
|
//
|
||||||
|
double risk = box.GetRange();
|
||||||
|
|
||||||
|
//
|
||||||
|
double entry =
|
||||||
|
isBullish
|
||||||
|
? box.upper
|
||||||
|
: box.lower;
|
||||||
|
entry = entryBar.open;
|
||||||
|
|
||||||
|
//
|
||||||
|
double sl =
|
||||||
|
isBullish
|
||||||
|
? box.lower
|
||||||
|
: box.upper;
|
||||||
|
|
||||||
|
//
|
||||||
|
double tp = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Target ...
|
||||||
|
XTarget targets[];
|
||||||
|
|
||||||
|
//
|
||||||
|
double tmp[];
|
||||||
|
int idx = -1;
|
||||||
|
XTarget iTarget;
|
||||||
|
bool has = false;
|
||||||
|
double iRatio = 0;
|
||||||
|
double iReward = 0;
|
||||||
|
double iRewardPrice = 0;
|
||||||
|
Copy(
|
||||||
|
rewardRatios,
|
||||||
|
tmp //
|
||||||
|
);
|
||||||
|
while (HasChild(tmp))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
idx = -1;
|
||||||
|
iRatio = GetMaxWidthIndex(
|
||||||
|
tmp,
|
||||||
|
idx //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
has = IsValidIndex(idx);
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
has = iRatio > 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
ArrayRemove(
|
||||||
|
tmp,
|
||||||
|
idx,
|
||||||
|
1 //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool canSetTP = tp <= 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
iReward = iRatio * risk;
|
||||||
|
|
||||||
|
//
|
||||||
|
iRewardPrice =
|
||||||
|
isBullish
|
||||||
|
? entry + iReward
|
||||||
|
: entry - iReward;
|
||||||
|
if (canSetTP)
|
||||||
|
{
|
||||||
|
tp = iRewardPrice;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
iTarget.target = iRewardPrice;
|
||||||
|
AddRef(
|
||||||
|
iTarget,
|
||||||
|
targets //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
iTarget.Clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Clean(tmp);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filling Signal ...
|
||||||
|
signal.tp = tp;
|
||||||
|
signal.sl = sl;
|
||||||
|
signal.type = iType;
|
||||||
|
signal.comment = "";
|
||||||
|
signal.entry = entry;
|
||||||
|
signal.time = box.to;
|
||||||
|
signal.volume = 0.01;
|
||||||
|
signal.provider = box.type;
|
||||||
|
signal.symbol = box.symbol;
|
||||||
|
signal.period = box.period;
|
||||||
|
signal.mode = X_ORDER_MODE_MARKET;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (HasChild(targets))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Copy(
|
||||||
|
targets,
|
||||||
|
signal.targets //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = signal.IsValid();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup Resources ...
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
signal.Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(tmp);
|
||||||
|
Clean(targets);
|
||||||
|
iTarget.Clean();
|
||||||
|
entryBar.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Implementation ...
|
// Implementation ...
|
||||||
|
|
||||||
@@ -1774,6 +1975,7 @@ class XCSignalObject : public XCBaseObject
|
|||||||
* @param name: String ...
|
* @param name: String ...
|
||||||
* @param window: Integer ...
|
* @param window: Integer ...
|
||||||
* @param signal: XSignal instance ...
|
* @param signal: XSignal instance ...
|
||||||
|
* @param length: int, Specified Length of Signal ...
|
||||||
*
|
*
|
||||||
* @return ( bool )
|
* @return ( bool )
|
||||||
*/
|
*/
|
||||||
@@ -1781,12 +1983,16 @@ class XCSignalObject : public XCBaseObject
|
|||||||
long chart_id,
|
long chart_id,
|
||||||
const int window,
|
const int window,
|
||||||
XSignal &signal,
|
XSignal &signal,
|
||||||
|
int length = 3,
|
||||||
string prefix = NULL //
|
string prefix = NULL //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
length = NormalizeInt(length, 3);
|
||||||
|
|
||||||
//
|
//
|
||||||
result = signal.IsValid();
|
result = signal.IsValid();
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -1803,7 +2009,7 @@ class XCSignalObject : public XCBaseObject
|
|||||||
string nameMD5 = ToMD5(name);
|
string nameMD5 = ToMD5(name);
|
||||||
|
|
||||||
//
|
//
|
||||||
int delay = (PeriodSeconds(signal.period) * 2);
|
int delay = (PeriodSeconds(signal.period) * length);
|
||||||
datetime time1 = (datetime)((int)signal.time - delay);
|
datetime time1 = (datetime)((int)signal.time - delay);
|
||||||
datetime time2 = (datetime)((int)signal.time + delay);
|
datetime time2 = (datetime)((int)signal.time + delay);
|
||||||
|
|
||||||
@@ -2108,6 +2314,70 @@ class XCSignalObject : public XCBaseObject
|
|||||||
CArrayObj mTargetTrends;
|
CArrayObj mTargetTrends;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// XRR Object ...
|
||||||
|
class XCRRObject : public XCSignalObject
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Public ...
|
||||||
|
public:
|
||||||
|
//
|
||||||
|
// Constructor ...
|
||||||
|
bool CreateBoxRR(
|
||||||
|
long chart_id,
|
||||||
|
const int window,
|
||||||
|
XBoxZone &box,
|
||||||
|
double &rewardRatios[],
|
||||||
|
int length = 3,
|
||||||
|
string prefix = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
length = NormalizeInt(length, 3);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = box.IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
XSignal signal;
|
||||||
|
result = ToSignal(
|
||||||
|
box,
|
||||||
|
signal,
|
||||||
|
rewardRatios //
|
||||||
|
);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
signal.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = Create(
|
||||||
|
chart_id,
|
||||||
|
window,
|
||||||
|
signal,
|
||||||
|
length,
|
||||||
|
prefix //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
signal.Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class XCOHCLObject : public XCBaseObject
|
class XCOHCLObject : public XCBaseObject
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -3267,7 +3267,8 @@ class XCPOIDrawer : public XCBase
|
|||||||
*/
|
*/
|
||||||
bool DrawSignal(
|
bool DrawSignal(
|
||||||
XSignal &signal,
|
XSignal &signal,
|
||||||
XCSignalObject *&object //
|
XCSignalObject *&object,
|
||||||
|
int length = 3 //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -3275,6 +3276,7 @@ class XCPOIDrawer : public XCBase
|
|||||||
|
|
||||||
//
|
//
|
||||||
object = NULL;
|
object = NULL;
|
||||||
|
length = NormalizeInt(length, 3);
|
||||||
|
|
||||||
//
|
//
|
||||||
result = signal.IsValid();
|
result = signal.IsValid();
|
||||||
@@ -3294,6 +3296,7 @@ class XCPOIDrawer : public XCBase
|
|||||||
chartID,
|
chartID,
|
||||||
window,
|
window,
|
||||||
signal,
|
signal,
|
||||||
|
length,
|
||||||
prefix //
|
prefix //
|
||||||
);
|
);
|
||||||
if (!result)
|
if (!result)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -4339,7 +4339,7 @@ T GetMax(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T GetMax(
|
T GetMaxWidthIndex(
|
||||||
T &buffer[], // the Buffer which required to search
|
T &buffer[], // the Buffer which required to search
|
||||||
int &index, // Item Index ...
|
int &index, // Item Index ...
|
||||||
int start = 0, // Start Index
|
int start = 0, // Start Index
|
||||||
@@ -4407,14 +4407,14 @@ T GetSpecifiedMax(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T GetSpecifiedMax(
|
T GetSpecifiedMaxWidthIndex(
|
||||||
T &buffer[], // the Buffer which required to search
|
T &buffer[], // the Buffer which required to search
|
||||||
int &index, // Item Index ...
|
int &index, // Item Index ...
|
||||||
int start = 0, // Start Index
|
int start = 0, // Start Index
|
||||||
int count = 0 // Count for Search
|
int count = 0 // Count for Search
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return GetMax(
|
return GetMaxWidthIndex(
|
||||||
buffer,
|
buffer,
|
||||||
index,
|
index,
|
||||||
start,
|
start,
|
||||||
@@ -4477,7 +4477,7 @@ T GetMin(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T GetMin(
|
T GetMinWidthIndex(
|
||||||
T &buffer[], // the Buffer which required to search
|
T &buffer[], // the Buffer which required to search
|
||||||
int &index, // Item Index ...
|
int &index, // Item Index ...
|
||||||
int start = 0, // Start Index
|
int start = 0, // Start Index
|
||||||
@@ -4545,14 +4545,14 @@ T GetSpecifiedMin(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T GetSpecifiedMin(
|
T GetSpecifiedMinWidthIndex(
|
||||||
T &buffer[], // the Buffer which required to search
|
T &buffer[], // the Buffer which required to search
|
||||||
int &index, // Item Index ...
|
int &index, // Item Index ...
|
||||||
int start = 0, // Start Index
|
int start = 0, // Start Index
|
||||||
int count = 0 // Count for Search
|
int count = 0 // Count for Search
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return GetMin(
|
return GetMinWidthIndex(
|
||||||
buffer,
|
buffer,
|
||||||
index,
|
index,
|
||||||
start,
|
start,
|
||||||
|
|||||||
Reference in New Issue
Block a user