backup v1 and compile ...
This commit is contained in:
@@ -1,384 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XNNTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XNNTest
|
||||
// Description: an Exper Advisor which used RSI and MA
|
||||
// to Analyse Market ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XNNTest"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XNNTest"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
input group "Weights";
|
||||
input double w0 = 0.5;
|
||||
input double w1 = 0.5;
|
||||
input double w2 = 0.5;
|
||||
input double w3 = 0.5;
|
||||
input double w4 = 0.5;
|
||||
input double w5 = 0.5;
|
||||
input double w6 = 0.5;
|
||||
input double w7 = 0.5;
|
||||
input double w8 = 0.5;
|
||||
input double w9 = 0.5;
|
||||
|
||||
//
|
||||
input double eaVolume = 0.01;
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
int barsTotal;
|
||||
|
||||
//
|
||||
string eaSymbol;
|
||||
ENUM_TIMEFRAMES eaPeriod;
|
||||
|
||||
//
|
||||
// This is our Data Provider ...
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
double rsi[];
|
||||
|
||||
//
|
||||
double nnInputs[]; // Storing Inputs
|
||||
double nnWeights[]; // Storing Weights;
|
||||
|
||||
//
|
||||
double nnOutput; // Output Neuron Value
|
||||
|
||||
//
|
||||
XSCTrade *mTrader;
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XSampleEA Providers ...
|
||||
IndicatorRelease(rsiHandler);
|
||||
ArrayFree(rsi);
|
||||
ArrayFree(nnInputs);
|
||||
ArrayFree(nnWeights);
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
XPosition positions[];
|
||||
|
||||
//
|
||||
XPosition longs[];
|
||||
int longsCount = 0;
|
||||
|
||||
//
|
||||
XPosition shorts[];
|
||||
int shortsCount = 0;
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.GetPositions(
|
||||
positions //
|
||||
);
|
||||
if (IsValidSize(positionsCount))
|
||||
{
|
||||
//
|
||||
ExtractPositions(
|
||||
positions,
|
||||
longs,
|
||||
shorts //
|
||||
);
|
||||
|
||||
//
|
||||
longsCount = ArraySize(longs);
|
||||
shortsCount = ArraySize(shorts);
|
||||
}
|
||||
|
||||
//
|
||||
if (longsCount == 0 && shortsCount == 0)
|
||||
{
|
||||
//
|
||||
double longEntry = GetEntry(eaSymbol, POSITION_TYPE_BUY);
|
||||
mTrader.Buy(
|
||||
eaSymbol,
|
||||
eaPeriod,
|
||||
eaVolume,
|
||||
longEntry //
|
||||
);
|
||||
|
||||
//
|
||||
double shortEntry = GetEntry(eaSymbol, POSITION_TYPE_SELL);
|
||||
mTrader.Sell(
|
||||
eaSymbol,
|
||||
eaPeriod,
|
||||
eaVolume,
|
||||
shortEntry //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
// int rsiCopiedData = CopyBuffer(
|
||||
// rsiHandler,
|
||||
// 0, // Line Index
|
||||
// 1, // BarIndex
|
||||
// 10, // Count
|
||||
// rsi // Buffer
|
||||
// );
|
||||
// if (rsiCopiedData < 0)
|
||||
// {
|
||||
// //
|
||||
// // Ignore Moving Forward when there isn't any Copied Data ...
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Normalize Input Data ...
|
||||
// double lower = 0;
|
||||
// double upper = 1;
|
||||
|
||||
// //
|
||||
// double max = rsi[ArrayMaximum(rsi)];
|
||||
// double min = rsi[ArrayMinimum(rsi)];
|
||||
|
||||
// //
|
||||
// ArrayFree(nnInputs);
|
||||
// ArrayResize(nnInputs, 10);
|
||||
|
||||
// //
|
||||
// for (int i = 0; i < ArraySize(rsi); i++)
|
||||
// {
|
||||
// nnInputs[i] = ((rsi[i] - min) * (upper - lower) / (max - min)) + lower;
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Calculating Output ...
|
||||
// nnOutput = CalculateNeuron(
|
||||
// nnInputs,
|
||||
// nnWeights //
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Now we Can Use NN Output for Placing Trades ...
|
||||
|
||||
// //
|
||||
// bool canBuy = nnOutput < 0.5;
|
||||
// bool canSell = nnOutput >= 0.5;
|
||||
|
||||
// //
|
||||
// XPosition positions[];
|
||||
// XPosition longs[];
|
||||
// XPosition shorts[];
|
||||
// int positionsCount = mTrader.GetPositions(
|
||||
// positions //
|
||||
// );
|
||||
// if (IsValidSize(positionsCount))
|
||||
// {
|
||||
// //
|
||||
// ExtractPositions(
|
||||
// positions,
|
||||
// longs,
|
||||
// shorts //
|
||||
// );
|
||||
|
||||
// //
|
||||
// if (canBuy)
|
||||
// {
|
||||
// //
|
||||
// mTrader.Close(shorts, "Opposit");
|
||||
|
||||
// //
|
||||
// if (ArraySize(longs) > 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// else if (canSell)
|
||||
// {
|
||||
// //
|
||||
// mTrader.Close(longs, "Opposit");
|
||||
|
||||
// //
|
||||
// if (ArraySize(shorts) > 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// //
|
||||
// double mEntry =
|
||||
// canBuy
|
||||
// ? GetEntry(eaSymbol, POSITION_TYPE_BUY)
|
||||
// : GetEntry(eaSymbol, POSITION_TYPE_SELL);
|
||||
|
||||
// //
|
||||
// if (canBuy)
|
||||
// {
|
||||
// //
|
||||
// mTrader.Buy(
|
||||
// eaSymbol,
|
||||
// eaPeriod,
|
||||
// eaVolume,
|
||||
// mEntry //
|
||||
// );
|
||||
// }
|
||||
// else if (canSell)
|
||||
// {
|
||||
// //
|
||||
// mTrader.Sell(
|
||||
// eaSymbol,
|
||||
// eaPeriod,
|
||||
// eaVolume,
|
||||
// mEntry //
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
eaSymbol = _Symbol;
|
||||
eaPeriod = _Period;
|
||||
|
||||
//
|
||||
// Initialize RSI Handler ...
|
||||
rsiHandler = iRSI(
|
||||
eaSymbol,
|
||||
eaPeriod,
|
||||
14,
|
||||
PRICE_CLOSE //
|
||||
);
|
||||
result = rsiHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mTrader = new XSCTrade(
|
||||
1,
|
||||
78692110 //
|
||||
);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rsi, true);
|
||||
|
||||
//
|
||||
ArrayResize(nnWeights, 10);
|
||||
|
||||
//
|
||||
// Filling Weights Buffer ...
|
||||
nnWeights[0] = w0;
|
||||
nnWeights[1] = w1;
|
||||
nnWeights[2] = w2;
|
||||
nnWeights[3] = w3;
|
||||
nnWeights[4] = w4;
|
||||
nnWeights[5] = w5;
|
||||
nnWeights[6] = w6;
|
||||
nnWeights[7] = w7;
|
||||
nnWeights[8] = w8;
|
||||
nnWeights[9] = w9;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Activation Function ...
|
||||
double Activate(double neuron)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
result = 1 / (1 + exp(-neuron));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Neuron ...
|
||||
// NET Inputs ...
|
||||
double CalculateNeuron(
|
||||
double &x[], // Inputs
|
||||
double &w[] // Weights
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double netInput = 0;
|
||||
for (int i = 0; i < ArraySize(x); i++)
|
||||
{
|
||||
//
|
||||
netInput += x[i] * w[i];
|
||||
}
|
||||
|
||||
//
|
||||
// Change The Shape of Sigmoid Graph for Smoothing ...
|
||||
netInput *= 0.4;
|
||||
|
||||
//
|
||||
// Calculate Activated Result ...
|
||||
result = Activate(netInput);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,652 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center X121EA MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121EA
|
||||
// Description: an Exper Advisor which used RSI and MA
|
||||
// to Analyse Market ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Classes/x-saherelm.x121.setup.xea.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "X121EA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long x121EAMagicNumber = 78692110; // Magic Number
|
||||
input int x121EASlippage = 10; // Slippgae
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
input group "Symbol(s)";
|
||||
input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols
|
||||
input bool x121EAUseAllSymbols = false; // Use All Available Symbols
|
||||
input bool x121EAUseAllWatchListSymbols = false; // Use All Watch List Symbols
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input bool x121EAAllowLong = true; // Allow Long Trades
|
||||
input bool x121EAAllowShort = true; // Allow Short Trades
|
||||
input int x121EAStartSignallingHoure = 3; // Start Signalling at Specific Time
|
||||
input int x121EAEndSignallingHoure = 22; // End Signalling at Specific Time
|
||||
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
|
||||
input int x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals
|
||||
input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals
|
||||
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
|
||||
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input double x121EAVolume = 0.01; // Static Volume
|
||||
input double x121EATPPoint = 1000; // TP Point
|
||||
input double x121EASLPoint = 1000; // SL Point
|
||||
input bool x121EAIgnoreSL = false; // Ignore Calculated SL
|
||||
input bool x121EAIgnoreTP = false; // Ignore Calculated TP
|
||||
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
|
||||
input int x121EAMaxAllowedTrades = 2; // Max Allowed Positions Per Symbol
|
||||
input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction
|
||||
input int x121EAMinFreeMargingForOpenTrades = 900; // Min Margin For Opening Trades
|
||||
input bool x121EAIncreaseNextSignalsVolume = true; // Increase Next Signals Volume
|
||||
input double x121EAIncreaseNextSignalsVolumeMultiplier = 1; // Increase Next Signals Volume Multiplier
|
||||
input bool x121EAAcceptNextDirectionalSignalsWhenFirstInProfit = true; // Accept Same Symbol/Type Signal when Last in Profit
|
||||
|
||||
//
|
||||
input group "Trailling";
|
||||
input bool x121EAAllowTrailStop = true; // Enable Trailling Stop Losses
|
||||
input bool x121EADisableTrailingWhenOpposit = true; // Disable Trailling When has Opposite In Drawdown
|
||||
input double x121EAFirstTrailDistance = 100; // Start Trailling Distance
|
||||
input double x121EAFirstTrailPoint = 60; // First Stop Trail
|
||||
input double x121EANextTrailDistance = 50; // Next Trailling Distance
|
||||
input double x121EANextTrailPoint = 25; // Next Trailling Step
|
||||
|
||||
//
|
||||
input group "Supporting";
|
||||
input bool x121EAAllowSupport = false; // Allow Support Signals
|
||||
input bool x121EASupportOnlyForces = false; // Support Only Force Signals
|
||||
double x121EASupportDistance = 0; // Supporting Distance
|
||||
input int x121EAMaxNumberOfSupports = 0; // Max Number of Support Signals
|
||||
input double x121EASupportVolumeMultiplier = 0; // Support Signals Volume Multiplier
|
||||
input double x121EAMaxAllowedSupportVolume = 0; // Max Allowed Support Signals Volume
|
||||
|
||||
//
|
||||
input group "Grid";
|
||||
input bool x121EAAllowGrid = false; // Allow Grid Signals
|
||||
input bool x121EAGridOnlyForces = false; // Grid Only Force Signals
|
||||
input int x121EAMaxNumberOfGrids = 0; // Max Number of Grid Signals
|
||||
input double x121EAGridDistance = 0; // Grid Distance
|
||||
input double x121EAGridVolumeMultiplier = 0; // Grid Volume Multiplier
|
||||
input double x121EAMaxAllowedGridVolume = 0; // Max Allowed Grid Signals Volume
|
||||
|
||||
//
|
||||
input group "Recovery";
|
||||
input bool x121EAAllowRecovery = false; // Allow Recovery Signals
|
||||
input bool x121EARecoverOnlyForces = false; // Recover Only Force Signals
|
||||
input int x121EAMaxNumberOfRecoveries = 0; // Max Number of Recovery Signals
|
||||
input double x121EARecoveryDistance = 0; // Recovery Distance
|
||||
input double x121EARecoveryVolumeMultiplier = 0; // Recovery Volume Multiplier
|
||||
input double x121EAMaxAllowedRecoveryVolume = 0; // Max Allowed Recovery Signals Volume
|
||||
|
||||
//
|
||||
input group "Hedging";
|
||||
input int x121EARestingAfterHedge = 1000; // Resting Seconds After Hedge
|
||||
input double x121EAMinRequiredProfitPerTrade = 0.3; // Minimum Required Profit for Hedging
|
||||
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
input group "Alerts";
|
||||
input bool x121EAEnableAlerts = true; // Enable Alerts
|
||||
input bool x121EALogAlerts = true; // Log Alerts
|
||||
input bool x121EAMailAlerts = false; // Mail Alerts
|
||||
input bool x121EAPushAlerts = false; // Push Alerts
|
||||
input bool x121EATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Local Variables ...
|
||||
|
||||
//
|
||||
string x121EAUsedSymbols[];
|
||||
XSCX121SetupEA *x121EA;
|
||||
|
||||
//
|
||||
XSCXCTHelper *x121EACTHelper;
|
||||
XSCXCCHelper *x121EACCHelper;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XSampleEA Providers ...
|
||||
delete x121EA;
|
||||
|
||||
//
|
||||
delete x121EACTHelper;
|
||||
delete x121EACCHelper;
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
x121EA.OnTick();
|
||||
|
||||
//
|
||||
X121ReportState();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default();
|
||||
x121EACTHelper = new XSCXCTHelper();
|
||||
result = x121EACTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default();
|
||||
x121EACCHelper = new XSCXCCHelper();
|
||||
result = x121EACCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TesterHideIndicators(true);
|
||||
|
||||
//
|
||||
string inputSymbols[];
|
||||
int inputSymbolsCount = SplitContent(
|
||||
inputSymbols,
|
||||
x121EASymbols //
|
||||
);
|
||||
|
||||
//
|
||||
string allSymbols[];
|
||||
int allSymbolsCount = GetAllSymbols(
|
||||
allSymbols //
|
||||
);
|
||||
|
||||
//
|
||||
string watchListSymbols[];
|
||||
int watchListSymbolsCount = GetAllSymbols(
|
||||
watchListSymbols,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
Clean(x121EAUsedSymbols);
|
||||
if (x121EAUseAllSymbols)
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
allSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else if (x121EAUseAllWatchListSymbols)
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
watchListSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else if (IsValidSize(inputSymbolsCount))
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
inputSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Add(
|
||||
_Symbol,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
int symbolsCount = ArraySize(x121EAUsedSymbols);
|
||||
result = IsValidSize(symbolsCount);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
x121EA = new XSCX121SetupEA(
|
||||
x121EASlippage,
|
||||
x121EAMagicNumber //
|
||||
);
|
||||
|
||||
//
|
||||
// Configure EA Class Instance ...
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
x121EA.AllowLong(x121EAAllowLong);
|
||||
x121EA.AllowShort(x121EAAllowShort);
|
||||
x121EA.DelayBetweenTwoSignal(x121EADelayBetweenTwoSignal);
|
||||
x121EA.ExecuteSignalsOnBreakout(x121EAExecuteSignalsOnBreakout);
|
||||
x121EA.ReuiredSignalVerifications(x121EAReuiredSignalVerifications);
|
||||
x121EA.GetVerificationFromOtherTimeFrames(x121EAGetVerificationFromOtherTimeFrames);
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
x121EA.Volume(x121EAVolume);
|
||||
x121EA.TPPoint(x121EATPPoint);
|
||||
x121EA.SLPoint(x121EASLPoint);
|
||||
x121EA.IgnoreSL(x121EAIgnoreSL);
|
||||
x121EA.IgnoreTP(x121EAIgnoreTP);
|
||||
x121EA.MaxAllowedTrades(x121EAMaxAllowedTrades);
|
||||
x121EA.IncreaseNextSignalsVolume(x121EAIncreaseNextSignalsVolume);
|
||||
x121EA.UseMaxAllowedPerDirection(x121EAUseMaxAllowedPerDirection);
|
||||
x121EA.MinFreeMargingForOpenTrades(x121EAMinFreeMargingForOpenTrades);
|
||||
x121EA.IncreaseNextSignalsVolumeMultiplier(x121EAIncreaseNextSignalsVolumeMultiplier);
|
||||
x121EA.AcceptNextDirectionalSignalsWhenFirstInProfit(x121EAAcceptNextDirectionalSignalsWhenFirstInProfit);
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
x121EA.CloseOnOpposit(x121EACloseOnOpposit);
|
||||
x121EA.EndSignallingHoure(x121EAEndSignallingHoure);
|
||||
x121EA.CloseOnSpecificTime(x121EACloseOnSpecificTime);
|
||||
x121EA.StartSignallingHoure(x121EAStartSignallingHoure);
|
||||
|
||||
//
|
||||
// Trailling ...
|
||||
x121EA.AllowTrailStop(x121EAAllowTrailStop);
|
||||
x121EA.NextTrailPoint(x121EANextTrailPoint);
|
||||
x121EA.FirstTrailPoint(x121EAFirstTrailPoint);
|
||||
x121EA.NextTrailDistance(x121EANextTrailDistance);
|
||||
x121EA.FirstTrailDistance(x121EAFirstTrailDistance);
|
||||
x121EA.DisableTrailingWhenOpposit(x121EADisableTrailingWhenOpposit);
|
||||
|
||||
//
|
||||
// Supporting ...
|
||||
x121EA.AllowSupport(x121EAAllowSupport);
|
||||
x121EA.SupportOnlyForces(x121EASupportOnlyForces);
|
||||
x121EA.SupportDistance(x121EASupportDistance);
|
||||
x121EA.MaxNumberOfSupports(x121EAMaxNumberOfSupports);
|
||||
x121EA.SupportVolumeMultiplier(x121EASupportVolumeMultiplier);
|
||||
x121EA.MaxAllowedSupportVolume(x121EAMaxAllowedSupportVolume);
|
||||
|
||||
//
|
||||
// Grid ...
|
||||
x121EA.AllowGrid(x121EAAllowGrid);
|
||||
x121EA.GridOnlyForces(x121EAGridOnlyForces);
|
||||
x121EA.GridDistance(x121EAGridDistance);
|
||||
x121EA.MaxNumberOfGrids(x121EAMaxNumberOfGrids);
|
||||
x121EA.GridVolumeMultiplier(x121EAGridVolumeMultiplier);
|
||||
x121EA.MaxAllowedGridVolume(x121EAMaxAllowedGridVolume);
|
||||
|
||||
//
|
||||
// Recovery ...
|
||||
x121EA.AllowRecovery(x121EAAllowRecovery);
|
||||
x121EA.RecoverOnlyForces(x121EARecoverOnlyForces);
|
||||
x121EA.RecoveryDistance(x121EARecoveryDistance);
|
||||
x121EA.MaxNumberOfRecoveries(x121EAMaxNumberOfRecoveries);
|
||||
x121EA.RecoveryVolumeMultiplier(x121EARecoveryVolumeMultiplier);
|
||||
x121EA.MaxAllowedRecoveryVolume(x121EAMaxAllowedRecoveryVolume);
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
x121EA.RestingAfterHedge(x121EARestingAfterHedge);
|
||||
x121EA.MinProfitPerTrade(x121EAMinRequiredProfitPerTrade);
|
||||
x121EA.MinProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor);
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
x121EA.SetAlertPrefix(ShortName);
|
||||
x121EA.SetAlertEnableAlerts(x121EAEnableAlerts);
|
||||
x121EA.SetAlertLogAlerts(x121EALogAlerts);
|
||||
x121EA.SetAlertMailAlerts(x121EAMailAlerts);
|
||||
x121EA.SetAlertPushAlerts(x121EAPushAlerts);
|
||||
x121EA.SetAlertTerminalAlerts(x121EATerminalAlerts);
|
||||
|
||||
//
|
||||
// Configure Indicators ...
|
||||
X121SetupInputs setupInputsDefault;
|
||||
setupInputsDefault.Default();
|
||||
X121PreConfigureStyles(setupInputsDefault);
|
||||
|
||||
//
|
||||
// Prepare Providers and Add them into mX121EA class ...
|
||||
for (int i = 0; i < symbolsCount; i++)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
string iSymbol = x121EAUsedSymbols[i];
|
||||
ENUM_TIMEFRAMES iHostPeriod = _Period;
|
||||
|
||||
//
|
||||
XSCX121SetupCycles *iSetupCycle;
|
||||
iSetupCycle = new XSCX121SetupCycles();
|
||||
result = iSetupCycle.Init(
|
||||
setupInputsDefault,
|
||||
iSymbol,
|
||||
iHostPeriod //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = x121EA.AddSetup(iSetupCycle);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void X121PreConfigureStyles(X121SetupInputs &inputs)
|
||||
{
|
||||
//
|
||||
// XHTD ...
|
||||
inputs.htdInputs.show = false;
|
||||
|
||||
//
|
||||
// XATSL ...
|
||||
inputs.atslInputs.show = false;
|
||||
|
||||
//
|
||||
// XSLN ...
|
||||
inputs.slnInputs.show = false;
|
||||
|
||||
//
|
||||
// XDMNT ...
|
||||
inputs.dmntInputs.showBull = false;
|
||||
inputs.dmntInputs.showBear = false;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
inputs.strInputs.showTrends = false;
|
||||
inputs.strInputs.fillTrends = false;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
inputs.pvInputs.showPeaksAndVales = false;
|
||||
inputs.pvInputs.showLevels = false;
|
||||
inputs.pvInputs.showConsolidations = false;
|
||||
inputs.pvInputs.showFibo1Levels = false;
|
||||
inputs.pvInputs.showFibo2Levels = false;
|
||||
inputs.pvInputs.showFibo3Levels = false;
|
||||
inputs.pvInputs.showFibo4Levels = false;
|
||||
inputs.pvInputs.showFibo5Levels = false;
|
||||
|
||||
//
|
||||
// XMC ...
|
||||
inputs.mcInputs.showSar = false;
|
||||
inputs.mcInputs.showFastMa = false;
|
||||
inputs.mcInputs.showSlowMa = false;
|
||||
inputs.mcInputs.showVerifierMa = false;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
inputs.hkInputs.drawHikenAshi = false;
|
||||
inputs.hkInputs.drawSmoothedHikenAshi = false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
inputs.cheInputs.showLongExit1Line = false;
|
||||
inputs.cheInputs.showShortExit1Line = false;
|
||||
inputs.cheInputs.showLongExit2Line = false;
|
||||
inputs.cheInputs.showShortExit2Line = false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
inputs.ichInputs.showTenkanSen = false;
|
||||
inputs.ichInputs.showKijunSen = false;
|
||||
inputs.ichInputs.showKijunSenPlus = false;
|
||||
inputs.ichInputs.showKijunSenNegative = false;
|
||||
inputs.ichInputs.showChikouSpan = false;
|
||||
inputs.ichInputs.showSenkouSpanA = false;
|
||||
inputs.ichInputs.showSenkouSpanB = false;
|
||||
inputs.ichInputs.showKumo = false;
|
||||
|
||||
//
|
||||
// XMRB ...
|
||||
inputs.mrbInputs.showFastMa = false;
|
||||
inputs.mrbInputs.showSlowMa = false;
|
||||
inputs.mrbInputs.showRibbon = false;
|
||||
|
||||
//
|
||||
// XASCT ...
|
||||
inputs.asctInputs.showLongs = false;
|
||||
inputs.asctInputs.showShorts = false;
|
||||
|
||||
//
|
||||
// XSSLC ...
|
||||
inputs.sslcInputs.showUp = false;
|
||||
inputs.sslcInputs.showDown = false;
|
||||
|
||||
//
|
||||
// XHULL ...
|
||||
inputs.hullInputs.showUpZone = false;
|
||||
inputs.hullInputs.showDownZone = false;
|
||||
}
|
||||
|
||||
//
|
||||
void X121ReportState()
|
||||
{
|
||||
//
|
||||
string comment = NULL;
|
||||
|
||||
//
|
||||
comment =
|
||||
ShortName + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Trading Symbols: " + ToString(ArraySize(x121EAUsedSymbols)) + "\n" + "\n";
|
||||
|
||||
//
|
||||
// Detect What we Want to Show as Comment ...
|
||||
// bool isInForceState = x121EA.ForceState();
|
||||
double bullishScore = 0; // x121EA.GetBullishScore();
|
||||
double bearishScore = 0; // x121EA.GetBearishScore();
|
||||
double drawDownPercent = x121EA.GetDrawdownPercent();
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
(bullishScore > 0 || bearishScore > 0
|
||||
? "Scores:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Bullish: " + ToString(bullishScore) + "\n" +
|
||||
"Bearish: " + ToString(bearishScore) + "\n" +
|
||||
"------------" + "\n"
|
||||
: "") +
|
||||
"Drawdown: " + ToString(drawDownPercent) + "%" + "\n" +
|
||||
// "------------" + "\n" +
|
||||
// "Force State: " + ToString(isInForceState) + "\n" +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = x121EA.mTrader.GetPositions(
|
||||
positions //
|
||||
);
|
||||
if (IsValidSize(positionsCount))
|
||||
{
|
||||
//
|
||||
int longs = 0;
|
||||
double longVolumes = 0;
|
||||
double longProfits = 0;
|
||||
|
||||
//
|
||||
int shorts = 0;
|
||||
double shortVolumes = 0;
|
||||
double shortProfits = 0;
|
||||
|
||||
//
|
||||
// Retrieve Required Informations of Positions ...
|
||||
CountPositions(
|
||||
positions,
|
||||
longs,
|
||||
longProfits,
|
||||
longVolumes,
|
||||
shorts,
|
||||
shortProfits,
|
||||
shortVolumes //
|
||||
);
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
"------------" + "\n" +
|
||||
"Positions: " + "\n" +
|
||||
"------------" + "\n" +
|
||||
(longs <= 0
|
||||
? ""
|
||||
: "\n" + "Longs:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Count: " + ToString(longs) + "\n" +
|
||||
"Profits: " + ToString(longProfits) + "\n" +
|
||||
""
|
||||
//
|
||||
) +
|
||||
//
|
||||
(shorts <= 0
|
||||
? ""
|
||||
: "\n" + "Shorts:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Count: " + ToString(shorts) + "\n" +
|
||||
"Profits: " + ToString(shortProfits) + "\n" +
|
||||
""
|
||||
//
|
||||
) +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
if (positionsCount > 1 && x121EAMinRequiredProfitPerTrade > 0 && x121EAMinRequiredProfitPerVolumeFactor > 0)
|
||||
{
|
||||
//
|
||||
double profit = SpecifiedCalculatePositionsProfit(
|
||||
positions //
|
||||
);
|
||||
double requiredProfitForHedge = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
x121EAMinRequiredProfitPerTrade,
|
||||
x121EAMinRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
"\n" + "Hedging: " + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Profits: " + ToString(profit) + "\n" +
|
||||
"RequiredProft: " + ToString(requiredProfitForHedge) + "\n" +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValid(comment))
|
||||
{
|
||||
Comment(comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,619 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XSAMPLE
|
||||
// Description: an Exper Advisor which used RSI and MA
|
||||
// to Analyse Market ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XSAMPLE"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XSAMPLE"
|
||||
|
||||
//
|
||||
int pivotLifeTime = 20;
|
||||
int pivotBreakoutsLifeTime = 10;
|
||||
ENUM_TIMEFRAMES destPEriod = PERIOD_H4;
|
||||
|
||||
//
|
||||
int xAge = 0;
|
||||
|
||||
//
|
||||
double lastHH = 0;
|
||||
double lastUpper = 0;
|
||||
double lastDestHH = 0;
|
||||
|
||||
//
|
||||
double lastLL = 0;
|
||||
double lastLower = 0;
|
||||
double lastDestLL = 0;
|
||||
|
||||
//
|
||||
datetime lastTime = NULL;
|
||||
datetime lastDestTime = NULL;
|
||||
|
||||
//
|
||||
XSCAlert *mAlert;
|
||||
XSCTrade *mTrader;
|
||||
|
||||
//
|
||||
XBarTracker xBarTracker;
|
||||
XMarketCycle xDestCycle;
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XSampleEA Providers ...
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
if (!xBarTracker.IsNewBar())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
xDestCycle.Update(0);
|
||||
|
||||
//
|
||||
Analyze();
|
||||
|
||||
//
|
||||
ManxAge();
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mAlert = new XSCAlert();
|
||||
mAlert.SetLogAlerts(true);
|
||||
mAlert.SetPrefix(ShortName);
|
||||
mAlert.SetEnableAlerts(true);
|
||||
mAlert.SetPushAlerts(false);
|
||||
mAlert.SetMailAlerts(false);
|
||||
mAlert.SetTerminalAlerts(false);
|
||||
|
||||
//
|
||||
mTrader = new XSCTrade(
|
||||
10,
|
||||
78692110,
|
||||
0,
|
||||
0,
|
||||
0 //
|
||||
);
|
||||
|
||||
//
|
||||
result = xBarTracker.Init(
|
||||
_Symbol,
|
||||
_Period //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = xDestCycle.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
X_MARKET_CYCLE_MEDIUM,
|
||||
X_PERIOD_MANUALLY,
|
||||
destPEriod,
|
||||
"DEST" //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void Analyze()
|
||||
{
|
||||
//
|
||||
XOHCL cBar;
|
||||
cBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
if (IsLookingForBoundary())
|
||||
{
|
||||
FindBoundary();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double longSLPrice = 0;
|
||||
double shortSLPrice = 0;
|
||||
|
||||
// //
|
||||
// xAge = 0;
|
||||
// if (IsValid(lastTime))
|
||||
// {
|
||||
// //
|
||||
// xAge = iBarShift(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// lastTime //
|
||||
// );
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (xAge > pivotBreakoutsLifeTime)
|
||||
// {
|
||||
// //
|
||||
// lastHH = cBar.FindHighest(
|
||||
// xAge - 1,
|
||||
// MODE_HIGH //
|
||||
// );
|
||||
|
||||
// //
|
||||
// lastLL = cBar.FindLowest(
|
||||
// xAge - 1,
|
||||
// MODE_LOW //
|
||||
// );
|
||||
|
||||
// //
|
||||
// DrawPivot(lastLL, clrAqua, "PVB_L_", true);
|
||||
// DrawPivot(lastHH, clrMagenta, "PVB_H_", true);
|
||||
// }
|
||||
|
||||
//
|
||||
// Detect Breakouts for Long ...
|
||||
// - Upper Must Breaked as Resistance ...
|
||||
// - Lower Must Rejects as Support ...
|
||||
|
||||
// //
|
||||
// bool isSupRejected = cBar.IsSupportRejected(lastLower);
|
||||
// bool isResBreaked = cBar.IsResistanceBreaked(lastUpper);
|
||||
// bool isLastLLRejectedAsSupport = cBar.IsSupportRejected(lastDestLL);
|
||||
// bool isLastHHBreakedAsResistance = cBar.IsResistanceBreaked(lastDestHH);
|
||||
|
||||
// //
|
||||
// bool hasLong =
|
||||
// //
|
||||
// cBar.HasStrongBody() &&
|
||||
// (
|
||||
// //
|
||||
// (isLastLLRejectedAsSupport
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// isLastHHBreakedAsResistance)
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// (cBar.GetMid() > MathMax(lastLower, lastUpper) &&
|
||||
// (isResBreaked
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// isSupRejected))
|
||||
// //
|
||||
// )
|
||||
// //
|
||||
// ;
|
||||
|
||||
// //
|
||||
// if (hasLong)
|
||||
// {
|
||||
// //
|
||||
// longSLPrice = isResBreaked
|
||||
// ? lastUpper
|
||||
// : isLastHHBreakedAsResistance
|
||||
// ? lastDestHH
|
||||
// : isSupRejected
|
||||
// ? lastLower
|
||||
// : lastDestLL;
|
||||
// }
|
||||
|
||||
//
|
||||
// Detect Breakouts for Long ...
|
||||
// - Upper Must Rejects as Resistance ...
|
||||
// - Lower Must Breaked as Support ...
|
||||
|
||||
// //
|
||||
// bool isResRejected = cBar.IsResistanceRejected(lastUpper);
|
||||
// bool isSupBreaked = cBar.IsSupportBreaked(lastLower);
|
||||
// bool isLastLLBreadedAsSupport = cBar.IsSupportBreaked(lastDestLL);
|
||||
// bool isLastHHRejectedAsResistance = cBar.IsResistanceRejected(lastDestHH);
|
||||
|
||||
// //
|
||||
// bool hasShort =
|
||||
// //
|
||||
// cBar.HasStrongBody() &&
|
||||
// (
|
||||
// //
|
||||
// (isLastLLBreadedAsSupport
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// isLastHHRejectedAsResistance)
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// (cBar.GetMid() < MathMin(lastLower, lastUpper) &&
|
||||
// (isSupBreaked
|
||||
// //
|
||||
// ||
|
||||
// //
|
||||
// isResRejected))
|
||||
// //
|
||||
// )
|
||||
// //
|
||||
// ;
|
||||
|
||||
// //
|
||||
// if (hasShort)
|
||||
// {
|
||||
// //
|
||||
// shortSLPrice = isSupBreaked
|
||||
// ? lastLower
|
||||
// : isLastLLBreadedAsSupport
|
||||
// ? lastDestLL
|
||||
// : isResRejected
|
||||
// ? lastUpper
|
||||
// : lastDestHH;
|
||||
// }
|
||||
|
||||
//
|
||||
//
|
||||
bool hasLong = false;
|
||||
bool hasShort = false;
|
||||
|
||||
//
|
||||
bool hasSignal = hasLong || hasShort;
|
||||
if (hasSignal)
|
||||
{
|
||||
//
|
||||
double slPrice =
|
||||
hasLong
|
||||
? longSLPrice
|
||||
: shortSLPrice;
|
||||
// double slPrice =
|
||||
// hasLong
|
||||
// ? shortSLPrice
|
||||
// : longSLPrice;
|
||||
|
||||
//
|
||||
ENUM_POSITION_TYPE mType =
|
||||
hasLong
|
||||
? POSITION_TYPE_BUY
|
||||
: POSITION_TYPE_SELL
|
||||
//
|
||||
;
|
||||
// ENUM_POSITION_TYPE mType =
|
||||
// hasLong
|
||||
// ? POSITION_TYPE_BUY
|
||||
// : POSITION_TYPE_SELL
|
||||
// //
|
||||
// ;
|
||||
|
||||
//
|
||||
double mEntry = GetEntry(
|
||||
_Symbol,
|
||||
mType //
|
||||
);
|
||||
|
||||
//
|
||||
double priceToRisk = PointToPrice(30, _Symbol);
|
||||
double priceToReward = PointToPrice(30, _Symbol);
|
||||
|
||||
//
|
||||
double mSL = 0;
|
||||
double mTP = 0;
|
||||
CalculateTPSL(
|
||||
mSL,
|
||||
mTP,
|
||||
mType,
|
||||
mEntry,
|
||||
1,
|
||||
slPrice,
|
||||
0,
|
||||
priceToRisk,
|
||||
priceToReward //
|
||||
);
|
||||
|
||||
//
|
||||
// Ignore Zero TP SL ...
|
||||
if (mTP > 0 && mSL > 0)
|
||||
{
|
||||
//
|
||||
XSignal signal;
|
||||
bool isPrepared = signal.Prepare(
|
||||
_Symbol,
|
||||
"X92",
|
||||
_Period,
|
||||
mType,
|
||||
X_ORDER_MODE_MARKET,
|
||||
mEntry,
|
||||
0.01,
|
||||
mSL,
|
||||
mTP //
|
||||
);
|
||||
|
||||
//
|
||||
if (isPrepared)
|
||||
{
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
bool isExecuted = mTrader.ExecuteSignal(
|
||||
signal,
|
||||
state //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool resetLast =
|
||||
xAge > pivotLifeTime || hasSignal;
|
||||
|
||||
//
|
||||
if (resetLast)
|
||||
{
|
||||
//
|
||||
lastUpper = 0;
|
||||
lastLower = 0;
|
||||
|
||||
//
|
||||
RemoveDraws();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void ManxAge()
|
||||
{
|
||||
//
|
||||
return;
|
||||
double profit = mTrader.Profit();
|
||||
if (profit > 50 || profit < -100)
|
||||
{
|
||||
//
|
||||
string comment = "EQM Hedge: " + ToString(profit);
|
||||
|
||||
//
|
||||
int numberOfClosed = mTrader.Close(comment);
|
||||
if (numberOfClosed > 0)
|
||||
{
|
||||
mAlert.Alert(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool IsLookingForBoundary()
|
||||
{
|
||||
//
|
||||
bool result = lastUpper == 0 && lastLower == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void FindBoundary()
|
||||
{
|
||||
//
|
||||
int zIndex = 0;
|
||||
int cIndex = 1;
|
||||
int pIndex = 2;
|
||||
int ppIndex = 3;
|
||||
|
||||
//
|
||||
// Detect Inside Bar ...
|
||||
XOHCL cBar;
|
||||
cBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
XOHCL cDestBar = xDestCycle.GetBar(1);
|
||||
|
||||
//
|
||||
if (cDestBar.time != lastDestTime) {
|
||||
//
|
||||
lastDestLL = cDestBar.low;
|
||||
lastDestHH = cDestBar.high;
|
||||
|
||||
//
|
||||
lastDestTime = cDestBar.time;
|
||||
|
||||
//
|
||||
DrawPivot(lastUpper, clrOrangeRed, "Pvt_");
|
||||
DrawPivot(lastLower, clrLimeGreen, "Pvt_");
|
||||
}
|
||||
|
||||
//
|
||||
// if (cDestBar.IsInsideBar())
|
||||
// {
|
||||
// //
|
||||
// lastUpper = cDestBar.high;
|
||||
// lastLower = cDestBar.low;
|
||||
|
||||
// //
|
||||
// lastTime = TimeCurrent();
|
||||
|
||||
// //
|
||||
// DrawPivot(lastUpper, clrOrangeRed, "Pvt_");
|
||||
// DrawPivot(lastLower, clrLimeGreen, "Pvt_");
|
||||
// }
|
||||
|
||||
// //
|
||||
// if (lastUpper != cDestBar.high && lastLower != cDestBar.low)
|
||||
// {
|
||||
// //
|
||||
// lastDestHH = cDestBar.high;
|
||||
// lastDestLL = cDestBar.low;
|
||||
|
||||
// //
|
||||
// DrawPivot(lastDestLL, clrYellow, "LDST_LL_", true);
|
||||
// DrawPivot(lastDestHH, clrYellow, "LDST_HH_", true);
|
||||
|
||||
// //
|
||||
// lastDestTime = TimeCurrent();
|
||||
// }
|
||||
|
||||
//
|
||||
DrawFibo();
|
||||
}
|
||||
|
||||
//
|
||||
void DrawPivot(
|
||||
double price,
|
||||
color clr,
|
||||
string prefix,
|
||||
bool forceRemove = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
long chartID = ChartID();
|
||||
datetime time1 = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
2 //
|
||||
);
|
||||
datetime time = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
0 //
|
||||
);
|
||||
|
||||
//
|
||||
string pPrefix = prefix + "P_" +
|
||||
ToString(price);
|
||||
|
||||
//
|
||||
if (IsDrawExists(prefix) && forceRemove)
|
||||
{
|
||||
RemoveDraws(prefix);
|
||||
}
|
||||
|
||||
//
|
||||
if (IsDrawExists(pPrefix))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartID,
|
||||
pPrefix,
|
||||
0,
|
||||
time1,
|
||||
price,
|
||||
time,
|
||||
price,
|
||||
clr,
|
||||
STYLE_SOLID,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
true //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
void DrawFibo()
|
||||
{
|
||||
//
|
||||
if (!IsValid(lastDestTime) || lastDestHH == 0 || lastDestLL == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string name = "LDST_FIb";
|
||||
|
||||
//
|
||||
datetime time1 = TimeCurrent();
|
||||
datetime time0 = lastDestTime;
|
||||
|
||||
//
|
||||
RemoveDraw(name);
|
||||
|
||||
//
|
||||
DrawFibonacci(
|
||||
ChartID(),
|
||||
name,
|
||||
0,
|
||||
time0,
|
||||
lastDestHH,
|
||||
time1,
|
||||
lastDestLL,
|
||||
clrAquamarine,
|
||||
STYLE_DOT //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1,263 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XZoneTest MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XZoneTest
|
||||
// Description: an Exper Advisor which used RSI and MA
|
||||
// to Analyse Market ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XZoneTest"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.xczone.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "XZoneTest"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
input int zoneRange = 21;
|
||||
input ENUM_TIMEFRAMES zonePeriod = PERIOD_M1;
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
int barsTotal;
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XSampleEA Providers ...
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
int bars = iBars(
|
||||
_Symbol,
|
||||
zonePeriod //
|
||||
);
|
||||
if (barsTotal == bars)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
barsTotal = bars;
|
||||
|
||||
//
|
||||
datetime startTime = iTime(
|
||||
_Symbol,
|
||||
zonePeriod,
|
||||
zoneRange + 1 //
|
||||
);
|
||||
datetime endTime = iTime(
|
||||
_Symbol,
|
||||
zonePeriod,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
MqlTick ticks[];
|
||||
CopyTicksRange(
|
||||
_Symbol,
|
||||
ticks,
|
||||
COPY_TICKS_ALL,
|
||||
startTime * 1000,
|
||||
endTime * 1000 //
|
||||
);
|
||||
|
||||
//
|
||||
double highs[];
|
||||
CopyHigh(
|
||||
_Symbol,
|
||||
zonePeriod,
|
||||
startTime,
|
||||
endTime,
|
||||
highs //
|
||||
);
|
||||
double iHigh = highs[ArrayMaximum(highs)];
|
||||
|
||||
//
|
||||
double lows[];
|
||||
CopyLow(
|
||||
_Symbol,
|
||||
zonePeriod,
|
||||
startTime,
|
||||
endTime,
|
||||
lows //
|
||||
);
|
||||
double iLow = lows[ArrayMinimum(lows)];
|
||||
|
||||
//
|
||||
double iSize = iHigh - iLow;
|
||||
|
||||
//
|
||||
CArrayObj zones;
|
||||
int zCount = 10;
|
||||
for (int i = 0; i < zCount; i++)
|
||||
{
|
||||
//
|
||||
double iH = iHigh - iSize * i / zCount;
|
||||
double iL = iHigh - iSize * (i + 1) / zCount;
|
||||
|
||||
//
|
||||
XSCZone *iZone = new XSCZone();
|
||||
iZone.high = iH;
|
||||
iZone.low = iL;
|
||||
|
||||
//
|
||||
zones.Add(iZone);
|
||||
}
|
||||
|
||||
//
|
||||
// Fill Ticks ...
|
||||
for (int i = 0; i < ArraySize(ticks); i++)
|
||||
{
|
||||
//
|
||||
MqlTick iTick = ticks[i];
|
||||
|
||||
//
|
||||
for (int j = 0; j < zones.Total(); j++)
|
||||
{
|
||||
//
|
||||
XSCZone *jZone = zones.At(j);
|
||||
|
||||
//
|
||||
bool isInRange = iTick.bid >= jZone.low && iTick.bid <= jZone.high;
|
||||
if (isInRange)
|
||||
{
|
||||
//
|
||||
jZone.ticks++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Sorting Zones ...
|
||||
zones.Sort();
|
||||
|
||||
//
|
||||
CArrayObj mChartObjects;
|
||||
for (int i = 0; i < zones.Total(); i++)
|
||||
{
|
||||
//
|
||||
XSCZone *iZone = zones.At(i);
|
||||
|
||||
//
|
||||
string iZoneName = "Zone " + IntegerToString(i);
|
||||
|
||||
//
|
||||
// Create Zone Rectangle ...
|
||||
CChartObjectRectangle *iRect = new CChartObjectRectangle();
|
||||
iRect.Create(
|
||||
0,
|
||||
iZoneName,
|
||||
0,
|
||||
startTime,
|
||||
iZone.high,
|
||||
endTime,
|
||||
iZone.low //
|
||||
);
|
||||
iRect.Fill(true);
|
||||
|
||||
//
|
||||
// Create Zone Label ...
|
||||
CChartObjectLabel *iLabel = new CChartObjectLabel();
|
||||
iLabel.Create(
|
||||
0,
|
||||
iZoneName + "_lbl",
|
||||
0,
|
||||
startTime,
|
||||
iZone.high //
|
||||
);
|
||||
iLabel.Color(clrWhite);
|
||||
|
||||
//
|
||||
// Calculate TickPercent ...
|
||||
double iZoneTickPercent = (double)iZone.ticks / ArraySize(ticks) * 100;
|
||||
iZoneTickPercent = NormalizeDouble(iZoneTickPercent, 2);
|
||||
string iZoneTickPercentStr = (string)iZoneTickPercent + "%";
|
||||
|
||||
//
|
||||
iLabel.Description(iZoneTickPercentStr);
|
||||
|
||||
//
|
||||
if (iZone.ticks > ArraySize(ticks) * 0.15)
|
||||
{
|
||||
iRect.Color(clrOrangeRed);
|
||||
}
|
||||
else if (iZone.ticks > ArraySize(ticks) * 0.10)
|
||||
{
|
||||
iRect.Color(clrOrange);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRect.Color(clrLightGray);
|
||||
}
|
||||
|
||||
//
|
||||
// mChartObjects.Add(iRect);
|
||||
// mChartObjects.Add(iLabel);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user