last works ...
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
|
||||
//
|
||||
#include "../Strategies/x-saherelm.xchkm.strategy.mq5"
|
||||
#include "../Strategies/x-saherelm.xch.strategy.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
@@ -36,32 +36,24 @@ long eaMagicNumber = 78692110; // Magic Number
|
||||
int eaSlippage = 10; // Slippgae
|
||||
|
||||
//
|
||||
double eaVolume = 0.01; // Static Volume
|
||||
double eaAllowLong = true; // Allow Long Positions
|
||||
double eaAllowShort = true; // Allow Short Positions
|
||||
|
||||
//
|
||||
int eaMaxAllowedLongs = 1; // Max Allowed Long Positions
|
||||
int eaMaxAllowedShorts = 1; // Max Allowed Short Positions
|
||||
|
||||
//
|
||||
double eaTPPoint = 150; // Static TP Point
|
||||
double eaSLPoint = 500; // Static SL Point
|
||||
|
||||
//
|
||||
double eaVolume = 0.01; // Static Volume
|
||||
bool eaIgnoreTP = false; // Ignore TP
|
||||
bool eaIgnoreSL = false; // Ignore SL
|
||||
double eaTPPoint = 150; // Static TP Point
|
||||
double eaSLPoint = 500; // Static SL Point
|
||||
|
||||
//
|
||||
// int eaMaxAllowedSLsInDay = 0;
|
||||
double eaR2R = 1.5; // Risk to Reward Ratio
|
||||
double eaAllowLong = true; // Allow Long Positions
|
||||
double eaAllowShort = true; // Allow Short Positions
|
||||
int eaMaxAllowedLongs = 1; // Max Allowed Long Positions
|
||||
int eaMaxAllowedShorts = 1; // Max Allowed Short Positions
|
||||
double eaMaxDrawdownPercentForOpenTrades = 3; // Max Drawdown Percent for Open Trades
|
||||
|
||||
//
|
||||
double eaR2R = 1.5; // Risk to Reward Ratio
|
||||
|
||||
//
|
||||
bool eaMultiSymbol = false; // Use Multi Symbol
|
||||
bool eaUseMaxAllowedTradesPerSymbol = true; // Use Max Allowed Trades Per Symbol
|
||||
string eaSymbols = "EURUSDb,USDJPYb"; // Trading Symbols
|
||||
bool eaMultiSymbol = false; // Use Multi Symbol
|
||||
bool eaUseMaxAllowedTradesPerSymbol = true; // Use Max Allowed Trades Per Symbol
|
||||
string eaSymbols = "EURUSDb,USDJPYb"; // Trading Symbols
|
||||
// string eaSymbols = "EURUSDb,USDJPYb,USDCHFb,GBPUSDb,XAUUSDb,XAGUSDb"; // Trading Symbols
|
||||
|
||||
//
|
||||
@@ -272,11 +264,19 @@ bool InitialEA()
|
||||
eaTradeHandler.SaveTrades(true);
|
||||
eaTradeHandler.SaveSignals(true);
|
||||
|
||||
//
|
||||
eaTradeHandler.AllowLong(eaAllowLong);
|
||||
eaTradeHandler.AllowShort(eaAllowShort);
|
||||
eaTradeHandler.MaxAllowedLongs(eaMaxAllowedLongs);
|
||||
eaTradeHandler.MaxAllowedShorts(eaMaxAllowedShorts);
|
||||
eaTradeHandler.UseMaxAllowedTradesPerSymbol(eaUseMaxAllowedTradesPerSymbol);
|
||||
eaTradeHandler.MaxDrawdownPercentForOpenTrades(eaMaxDrawdownPercentForOpenTrades);
|
||||
|
||||
//
|
||||
// Configure Hedging ...
|
||||
eaTradeHandler.AllowHedging(true);
|
||||
eaTradeHandler.MinTradesForHedge(2);
|
||||
eaTradeHandler.HedgeVolumeFactor(eaVolume);
|
||||
eaTradeHandler.OnlyHedgeSupportedPositions(false);
|
||||
eaTradeHandler.HedgeMinProfitPerVolumeFactor(0.3);
|
||||
|
||||
//
|
||||
@@ -302,8 +302,8 @@ bool InitialEA()
|
||||
if (!eaMultiSymbol)
|
||||
{
|
||||
//
|
||||
XSCXCHKMStrategy *xchmStrategy;
|
||||
xchmStrategy = new XSCXCHKMStrategy(
|
||||
XSCXCHStrategy *xchStrategy;
|
||||
xchStrategy = new XSCXCHStrategy(
|
||||
_Symbol,
|
||||
_Period,
|
||||
PERIOD_H1, // Analyzing Period
|
||||
@@ -323,15 +323,15 @@ bool InitialEA()
|
||||
eaMaxAllowedLongs, // Max Longs
|
||||
eaMaxAllowedShorts // Max Shorts
|
||||
);
|
||||
xchmStrategy.EnableXCHM(true);
|
||||
xchmStrategy.EnableXCHHK(true);
|
||||
xchmStrategy.EnableXCHSTR(true);
|
||||
xchmStrategy.EnableXCHCHE(false);
|
||||
xchmStrategy.SetAlertLogAlerts(true);
|
||||
xchmStrategy.DrawImportantAreas(false);
|
||||
xchmStrategy.SetAlertEnableAlerts(true);
|
||||
xchmStrategy.AddSignalEventHandler(OnSignalRecieved);
|
||||
RegisterStrategy(xchmStrategy);
|
||||
xchStrategy.EnableXCHM(true);
|
||||
xchStrategy.EnableXCHHK(true);
|
||||
xchStrategy.EnableXCHSTR(true);
|
||||
xchStrategy.EnableXCHCHE(true);
|
||||
xchStrategy.SetAlertLogAlerts(true);
|
||||
xchStrategy.DrawImportantAreas(false);
|
||||
xchStrategy.SetAlertEnableAlerts(true);
|
||||
xchStrategy.AddXCHSignalEventHandler(OnSignalRecieved);
|
||||
RegisterStrategy(xchStrategy);
|
||||
}
|
||||
//
|
||||
// Multi Symbol ...
|
||||
@@ -357,8 +357,8 @@ bool InitialEA()
|
||||
string iSymbol = symbols[i];
|
||||
|
||||
//
|
||||
XSCXCHKMStrategy *iStrategy;
|
||||
iStrategy = new XSCXCHKMStrategy(
|
||||
XSCXCHStrategy *iStrategy;
|
||||
iStrategy = new XSCXCHStrategy(
|
||||
iSymbol,
|
||||
_Period,
|
||||
PERIOD_H1, // Analyzing Period
|
||||
@@ -381,11 +381,11 @@ bool InitialEA()
|
||||
iStrategy.EnableXCHM(true);
|
||||
iStrategy.EnableXCHHK(true);
|
||||
iStrategy.EnableXCHSTR(true);
|
||||
iStrategy.EnableXCHCHE(false);
|
||||
iStrategy.EnableXCHCHE(true);
|
||||
iStrategy.SetAlertLogAlerts(true);
|
||||
iStrategy.DrawImportantAreas(false);
|
||||
iStrategy.SetAlertEnableAlerts(true);
|
||||
iStrategy.AddSignalEventHandler(OnSignalRecieved);
|
||||
iStrategy.AddXCHSignalEventHandler(OnSignalRecieved);
|
||||
|
||||
//
|
||||
RegisterStrategy(iStrategy);
|
||||
@@ -467,8 +467,14 @@ void HandleTimeReport()
|
||||
//
|
||||
// All Signals from Strategies Comming Here for Execution or
|
||||
// Analyzing ...
|
||||
void OnSignalRecieved(XSignal &signal)
|
||||
void OnSignalRecieved(
|
||||
XSignal &signal,
|
||||
XCHStrategyConditions &conditions //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Signal and Conditions Validations ...
|
||||
|
||||
//
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
@@ -476,134 +482,39 @@ void OnSignalRecieved(XSignal &signal)
|
||||
}
|
||||
|
||||
//
|
||||
bool isLong = IsLong(signal.type);
|
||||
|
||||
//
|
||||
// Check Allow Trade Type ...
|
||||
if ((isLong && !eaAllowLong) ||
|
||||
(!isLong && !eaAllowShort))
|
||||
if (!conditions.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Max Allowed ...
|
||||
if (eaMaxAllowedLongs > 0 || eaMaxAllowedShorts > 0)
|
||||
{
|
||||
//
|
||||
XPosition longs[];
|
||||
XPosition shorts[];
|
||||
|
||||
//
|
||||
if (eaUseMaxAllowedTradesPerSymbol)
|
||||
{
|
||||
//
|
||||
eaTrader.GetPositions(
|
||||
longs,
|
||||
shorts,
|
||||
signal.symbol //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
eaTrader.GetPositions(
|
||||
longs,
|
||||
shorts,
|
||||
NULL // All Symbols ...
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int longsCount = ArraySize(longs);
|
||||
int shortsCount = ArraySize(shorts);
|
||||
|
||||
//
|
||||
if ((isLong &&
|
||||
eaMaxAllowedLongs > 0 &&
|
||||
longsCount >= eaMaxAllowedLongs) ||
|
||||
(!isLong &&
|
||||
eaMaxAllowedShorts > 0 &&
|
||||
shortsCount >= eaMaxAllowedShorts))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Can Execute or not ...
|
||||
bool canExecute = eaTradeHandler.CanExecute(signal);
|
||||
if (!canExecute)
|
||||
XCHStartegyConditionsParser parser;
|
||||
bool isFiltered = parser.IsFiltered(
|
||||
signal,
|
||||
conditions //
|
||||
);
|
||||
if (isFiltered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// //
|
||||
// if (eaMaxAllowedSLsInDay > 0 &&
|
||||
// mNumberOfSLs >= eaMaxAllowedSLsInDay)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (signal.pushers < 2)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Attach Conditions Summary to Signal ...
|
||||
string conditionsSummary = conditions.GenerateSummary(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false //
|
||||
);
|
||||
signal.conditions = conditionsSummary;
|
||||
|
||||
//
|
||||
// Execute Signal Using Trade Handler ...
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
bool isExecuted = eaTrader.ExecuteSignal(
|
||||
bool isExecuted = eaTradeHandler.ExecuteSignal(
|
||||
signal,
|
||||
state //
|
||||
);
|
||||
|
||||
//
|
||||
if (isExecuted)
|
||||
{
|
||||
//
|
||||
// Find Executed Signal Deal History ...
|
||||
XDeal deals[];
|
||||
double commission = 0;
|
||||
int dealsCount = eaTrader.GetDeals(
|
||||
deals,
|
||||
signal.symbol,
|
||||
signal.provider,
|
||||
signal.period,
|
||||
NULL,
|
||||
DEAL_ENTRY_IN //
|
||||
);
|
||||
if (IsValidSize(dealsCount))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < dealsCount; i++)
|
||||
{
|
||||
//
|
||||
XDeal iDeal = deals[i];
|
||||
if (iDeal.positionId == signal.positionId)
|
||||
{
|
||||
//
|
||||
commission = iDeal.commission;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Add Signal to Trade Handler ...
|
||||
eaTradeHandler.AddData(
|
||||
signal,
|
||||
commission //
|
||||
);
|
||||
|
||||
//
|
||||
string msg = (signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
|
||||
" Signal Provided by: " + signal.provider +
|
||||
" on: " + signal.symbol +
|
||||
" in: " + ToString(signal.period) +
|
||||
" Executed Successfully ...";
|
||||
eaAlert.Alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user