Files
xMQL5/MQLTestWorkspace/BKPS/14030322/Experts/x-be-test.mq5
T

352 lines
6.2 KiB
Plaintext

///////////////////////////////////////////////////////
//
// 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 swingLifeTime = 20;
ENUM_TIMEFRAMES destPEriod = PERIOD_H4;
//
XOHCL hSwing0;
XOHCL hSwing1;
//
XOHCL lSwing0;
XOHCL lSwing1;
//
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();
}
//
//
//
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 //
);
//
FindSwings(cBar);
}
//
void FindSwings(XOHCL &bar)
{
//
// High Swings ...
//
if (!hSwing0.IsValid())
{
//
int index = bar.FindSwing(X_SWING_HIGH, 10);
//
if (index >= 0)
{
//
bool isInited = hSwing0.Init(
bar.symbol,
bar.period,
index //
);
}
}
//
if (hSwing0.IsValid() && !hSwing1.IsValid())
{
//
int index = bar.FindNextSwing(X_SWING_HIGH, hSwing0.Index(), 10);
//
if (index >= 0)
{
//
index += hSwing0.Index();
//
bool isInited = hSwing1.Init(
bar.symbol,
bar.period,
index //
);
}
}
//
// Draw Swings ...
if (hSwing0.IsValid() && hSwing1.IsValid())
{
//
DrawSwing(
hSwing1,
X_PRICE_HIGH,
hSwing0,
X_PRICE_HIGH,
clrAqua,
"HH" //
);
}
//
// Low Swings ...
//
if (!lSwing0.IsValid())
{
//
int index = bar.FindSwing(X_SWING_LOW, 10);
//
if (index >= 0)
{
//
bool isInited = lSwing0.Init(
bar.symbol,
bar.period,
index //
);
}
}
//
if (lSwing0.IsValid() && !lSwing1.IsValid())
{
//
int index = bar.FindNextSwing(X_SWING_LOW, lSwing0.Index(), 10);
//
if (index >= 0)
{
//
index += lSwing0.Index();
//
bool isInited = lSwing1.Init(
bar.symbol,
bar.period,
index //
);
}
}
//
// Draw Swings ...
if (lSwing0.IsValid() && lSwing1.IsValid())
{
//
DrawSwing(
lSwing1,
X_PRICE_LOW,
lSwing0,
X_PRICE_LOW,
clrMagenta,
"LL" //
);
}
}
//
// Draw Line ...
//
void DrawSwing(
XOHCL &bar1, // From (Old) ...
ENUM_X_PRICE price1, // How to Select Bar 1 Price ...
XOHCL &bar0, // To (New) ...
ENUM_X_PRICE price0, // How to Select Bar 0 Price ...
color clr,
string prefix,
bool forceRemove = false //
)
{
//
long chartID = ChartID();
//
double b1Price = bar1.GetPrice(price1);
double b0Price = bar0.GetPrice(price0);
//
string lName = prefix + "Swing_" +
ToString(b1Price) + "_TO_" +
ToString(b0Price);
//
if (IsDrawExists(prefix) && forceRemove)
{
RemoveDraws(prefix);
}
//
// if (IsDrawExists(lName))
// {
// return;
// }
//
DrawTrendLine(
chartID,
lName,
0,
bar1.time,
b1Price,
bar0.time,
b0Price,
clr,
STYLE_SOLID,
2,
false,
false,
true //
);
}