last works ...
This commit is contained in:
@@ -374,6 +374,16 @@ class XCAccount : public XCBase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Specified Message for Report Balance ...
|
||||||
|
*
|
||||||
|
* @return ( string )
|
||||||
|
*/
|
||||||
|
string GetBalanceReportMessage()
|
||||||
|
{
|
||||||
|
return "Balance: " + ToXString(GetBalance()) + " " + GetCurrency();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// END Provided Functions ...
|
// END Provided Functions ...
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ class XCBaseSignaller : public XCBase
|
|||||||
string symbol; // Symbol ...
|
string symbol; // Symbol ...
|
||||||
ENUM_TIMEFRAMES period; // Period ...
|
ENUM_TIMEFRAMES period; // Period ...
|
||||||
|
|
||||||
|
//
|
||||||
|
double slAdditionDistance; // SL Addition Distance ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Restrictions ...
|
||||||
|
datetime restUntil; // Resting Time ...
|
||||||
|
int restingSignals; // Resting Signals ...
|
||||||
|
datetime lastSignalAt; // Holding Last Signal's Time ...
|
||||||
|
int restingDelay; // Resting Bars After Last Signal ...
|
||||||
|
|
||||||
//
|
//
|
||||||
TCanAnalyse canAnalyseEventListener;
|
TCanAnalyse canAnalyseEventListener;
|
||||||
|
|
||||||
@@ -80,6 +90,9 @@ class XCBaseSignaller : public XCBase
|
|||||||
symbol = _symbol;
|
symbol = _symbol;
|
||||||
period = _period;
|
period = _period;
|
||||||
|
|
||||||
|
//
|
||||||
|
slAdditionDistance = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
processAllTicks = _processAllTicks;
|
processAllTicks = _processAllTicks;
|
||||||
defaultSignalR2R = _defaultSignalR2R;
|
defaultSignalR2R = _defaultSignalR2R;
|
||||||
@@ -350,12 +363,27 @@ class XCBaseSignaller : public XCBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Restrictions ...
|
||||||
|
if (HasRestrictions())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool ignore = HandleRestrictions(signal);
|
||||||
|
if (ignore)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Do Notify ...
|
// Do Notify ...
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
onSignalEventListeners[i](signal);
|
onSignalEventListeners[i](signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
lastSignalAt = signal.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -526,6 +554,139 @@ class XCBaseSignaller : public XCBase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check Signaller Has Restrictions or not ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool HasRestrictions()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result =
|
||||||
|
//
|
||||||
|
// Rest Delay ...
|
||||||
|
restingDelay > 0 ||
|
||||||
|
//
|
||||||
|
// Resting Signals ...
|
||||||
|
restingSignals > 0 ||
|
||||||
|
//
|
||||||
|
// Rest Until ...
|
||||||
|
IsXValid(restUntil)
|
||||||
|
//
|
||||||
|
;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Restrictions On Signal ...
|
||||||
|
*
|
||||||
|
* @param signal: XSignal, reference to Provided Sginal ...
|
||||||
|
*
|
||||||
|
* @return ( bool )
|
||||||
|
*/
|
||||||
|
bool HandleRestrictions(XSignal &signal)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Ignore Signal Execution ...
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Restrictions Exists ...
|
||||||
|
if (!HasRestrictions())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Disable Signal Ignoring and Allow Notify Signal ...
|
||||||
|
result = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime cTime = TimeCurrent();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Resting Signals ...
|
||||||
|
if (restingSignals > 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
restingSignals--;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Rest Until ...
|
||||||
|
if (IsXValid(restUntil))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (cTime > restUntil)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
restUntil = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Disable Signal Ignoring and Allow Notify Signal ...
|
||||||
|
result = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Ignore Signal ...
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Resting Delay ...
|
||||||
|
if (restingDelay > 0 &&
|
||||||
|
IsXValid(lastSignalAt))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int lastSignalIDX = GetBarIndex(
|
||||||
|
signal.symbol,
|
||||||
|
signal.period,
|
||||||
|
lastSignalAt //
|
||||||
|
);
|
||||||
|
if (IsValidIndex(lastSignalIDX))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (lastSignalIDX > restingDelay)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
restingDelay = 0;
|
||||||
|
//
|
||||||
|
// Disable Signal Ignoring and Allow Notify Signal ...
|
||||||
|
result = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Ignore Signal ...
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset All Restrictions ...
|
||||||
|
*/
|
||||||
|
void ResetRestrictions()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
restingDelay = 0;
|
||||||
|
restUntil = NULL;
|
||||||
|
restingSignals = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Private ...
|
// Private ...
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ int OnInit()
|
|||||||
eaSignallerRiskInPoint, // Default Risk In Points ...
|
eaSignallerRiskInPoint, // Default Risk In Points ...
|
||||||
eaSignallerVolume // Defaul Volume ...
|
eaSignallerVolume // Defaul Volume ...
|
||||||
);
|
);
|
||||||
|
fima1Signaller.slAdditionDistance = 15;
|
||||||
fima1Signaller.AddOnSignalEventHandler(OnSignalTriggered);
|
fima1Signaller.AddOnSignalEventHandler(OnSignalTriggered);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -722,7 +723,12 @@ int CheckForGuard(
|
|||||||
*/
|
*/
|
||||||
void OnStopLossTriggered(const XDeal &deal)
|
void OnStopLossTriggered(const XDeal &deal)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
eaExpert.HandleOnStopLossTriggered(deal);
|
eaExpert.HandleOnStopLossTriggered(deal);
|
||||||
|
|
||||||
|
//
|
||||||
|
HandleBalanceReport();
|
||||||
|
HandleLoosingPosition(deal.positionId, deal.profit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -732,7 +738,11 @@ void OnStopLossTriggered(const XDeal &deal)
|
|||||||
*/
|
*/
|
||||||
void OnTakeProfitTriggered(const XDeal &deal)
|
void OnTakeProfitTriggered(const XDeal &deal)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
eaExpert.HandleOnTakeProfitTriggered(deal);
|
eaExpert.HandleOnTakeProfitTriggered(deal);
|
||||||
|
|
||||||
|
//
|
||||||
|
HandleBalanceReport();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -754,6 +764,10 @@ void OnPositionForceClosed(
|
|||||||
position,
|
position,
|
||||||
comment //
|
comment //
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
HandleBalanceReport();
|
||||||
|
HandleLoosingPosition(ticket, position.profit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -838,4 +852,44 @@ void OnTradeStateChanged(const XOnTradeHandlerState &state)
|
|||||||
eaExpert.HandleOnTradeStateChanged(state);
|
eaExpert.HandleOnTradeStateChanged(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Resting Signals ...
|
||||||
|
*
|
||||||
|
* @param ticket: ulong, Position Ticket ...
|
||||||
|
*/
|
||||||
|
void HandleLoosingPosition(
|
||||||
|
ulong ticket = 0,
|
||||||
|
double profit = 0 //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Position Loose ...
|
||||||
|
bool has = ticket > 0 &&
|
||||||
|
profit < 0;
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// NOTE: Here we Can Add Restrictions on Signaller based on our Requirements ...
|
||||||
|
// restingSignals: Specified Number of Signals which must to Ignore ...
|
||||||
|
// restUntil: Specified DateTime to Ignore all Signals before it Expiration ...
|
||||||
|
// restingDelay: Specified Bars Delay to Ignore all Signals before it passed ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Increase Resting Signals of Signallers ...
|
||||||
|
fima1Signaller.restingSignals++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Balance Report ...
|
||||||
|
*/
|
||||||
|
void HandleBalanceReport()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
string message = eaExpert.eaTrader.mAccount.GetBalanceReportMessage();
|
||||||
|
eaExpert.eaAlert.SendAlert(message);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -719,11 +719,11 @@ struct XTarget
|
|||||||
//
|
//
|
||||||
// Props ...
|
// Props ...
|
||||||
bool doRF; // Do RF on Target
|
bool doRF; // Do RF on Target
|
||||||
bool doRFOnEntry; // Do RF on Entry
|
bool doRFOnEntry; // Do RF on Entry
|
||||||
double actingDistance; // Acting Distances
|
double actingDistance; // Acting Distances
|
||||||
double target; // Target Price for Actions
|
double target; // Target Price for Actions
|
||||||
double volumeMultiplier; // Volume Multiplier for Partial Close
|
double volumeMultiplier; // Volume Multiplier for Partial Close
|
||||||
double tpValue; // TP Value Changed ...
|
double tpValue; // TP Value Changed ...
|
||||||
|
|
||||||
//
|
//
|
||||||
// Constructor ...
|
// Constructor ...
|
||||||
|
|||||||
@@ -215,6 +215,10 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
|
|||||||
result = fimaInputs.IsValid() &&
|
result = fimaInputs.IsValid() &&
|
||||||
fimaHelper != NULL &&
|
fimaHelper != NULL &&
|
||||||
poiDetector != NULL;
|
poiDetector != NULL;
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -358,13 +362,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Handle Resting Signals ...
|
||||||
has = HasDirection(iDir) &&
|
has = HasDirection(iDir) &&
|
||||||
iZone.IsValid();
|
iZone.IsValid();
|
||||||
if (has)
|
if (has)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Draw Zone ...
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// has = false;
|
// has = false;
|
||||||
// iZone.Clean();
|
// iZone.Clean();
|
||||||
@@ -372,6 +374,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Prepare Signal ...
|
||||||
if (has)
|
if (has)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -379,30 +382,73 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
|||||||
isBearish = IsXBearish(iDir);
|
isBearish = IsXBearish(iDir);
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Provided SL ...
|
// Provided SL ...
|
||||||
double _point = GetPoints(iBar.symbol);
|
double _point = GetPoints(iBar.symbol);
|
||||||
double slAddition = 10 * _point;
|
double slAddition =
|
||||||
double atrAddition = GetAverageTrueRange(
|
slAdditionDistance <= 0
|
||||||
iZone.symbol,
|
? 0
|
||||||
iZone.period,
|
: slAdditionDistance * _point;
|
||||||
0 //
|
|
||||||
);
|
|
||||||
double slPrice =
|
double slPrice =
|
||||||
isBullish
|
isBullish
|
||||||
? iZone.lower - slAddition
|
? iZone.lower - slAddition
|
||||||
: iZone.upper + slAddition;
|
: iZone.upper + slAddition;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prepare Founded Signal ...
|
// Preparing Signal Targets ...
|
||||||
|
XTarget iTarget;
|
||||||
|
double spread = GetSpread(iZone.symbol);
|
||||||
|
double entry = GetEntry(iZone.symbol, iZone.dir);
|
||||||
|
double risk = MathAbs(entry - (isBullish ? iZone.lower : iZone.upper));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle Signal Targets ...
|
// Handle Partial Close Position if Reached TP 1.5 ...
|
||||||
|
iTarget.Clean();
|
||||||
|
iTarget.actingDistance = 1;
|
||||||
|
iTarget.volumeMultiplier = 0.5;
|
||||||
|
iTarget.target = isBullish ? entry + (1.5 * risk) : entry - (1.5 * risk);
|
||||||
|
iTarget.tpValue = isBullish ? entry + (2.5 * risk) : entry - (2.5 * risk);
|
||||||
|
AddRef(iTarget, iTargets);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle Ignore Signal Targets if Forced ...
|
||||||
if (ignoreTargets)
|
if (ignoreTargets)
|
||||||
{
|
{
|
||||||
XClean(iTargets);
|
XClean(iTargets);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Handle Restrictions Based Signal Targets ...
|
||||||
|
if (risk > 0 && HasRestrictions())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Here we Can Do Target Preparing if Signaller Restricted and
|
||||||
|
// then ignore restrictions if required ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Risk Free On Entry:
|
||||||
|
iTarget.Clean();
|
||||||
|
iTarget.doRF = true;
|
||||||
|
iTarget.actingDistance = (5 * spread) / _point;
|
||||||
|
iTarget.target = isBullish ? entry + (2 * spread) : entry - (2 * spread);
|
||||||
|
AddRef(iTarget, iTargets);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Partial Close Position Half on TP 1 ...
|
||||||
|
// Increase Rewards to TP 3 ...
|
||||||
|
iTarget.Clean();
|
||||||
|
iTarget.actingDistance = 1;
|
||||||
|
iTarget.volumeMultiplier = 0.5;
|
||||||
|
iTarget.target = isBullish ? entry + risk : entry - risk;
|
||||||
|
iTarget.tpValue = isBullish ? entry + (3 * risk) : entry - (3 * risk);
|
||||||
|
AddRef(iTarget, iTargets);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reset Restrictions ...
|
||||||
|
ResetRestrictions();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Founded Signal ...
|
||||||
has = PrepareSignal(
|
has = PrepareSignal(
|
||||||
iSignal,
|
iSignal,
|
||||||
iDir,
|
iDir,
|
||||||
@@ -417,10 +463,14 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
|
|||||||
// Notify On Signal Event ...
|
// Notify On Signal Event ...
|
||||||
NotifySignalEventListeners(iSignal);
|
NotifySignalEventListeners(iSignal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup ...
|
||||||
|
iTarget.Clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Cleanup Resources ...
|
// Cleanup ...
|
||||||
iBar.Clean();
|
iBar.Clean();
|
||||||
iZone.Clean();
|
iZone.Clean();
|
||||||
iSignal.Clean();
|
iSignal.Clean();
|
||||||
|
|||||||
Reference in New Issue
Block a user