Files
xMQL5/MQLTestWorkspace/BKPS/14030228/Documents/BKP/x-sample.ea.mq5
T
2024-05-17 04:54:01 +03:30

181 lines
3.6 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
//
#define ShortName "XSAMPLE"
//
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
// Inputs ...
long xSampleEAMagicNumber = 78692110; // Magic Number
int xSampleEASlippage = 10; // Slippgae
//
double xSampleEAVolume = 0.01;
//
// Vars ...
string xSampleEASymbol;
ENUM_TIMEFRAMES xSampleEAPeriod;
//
int maxBuys = 1;
int maxSells = 1;
int buyCount = 0;
int sellCount = 0;
//
double _tp = 0;
double _sl = 0;
double _entry = 0;
ENUM_POSITION_TYPE _type = NULL;
//
MqlTick xSampleEATick;
XSCTrade *xSampleEATrader;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0)
{
xSampleEASymbol = _Symbol;
}
//
if (xSampleEAPeriod == NULL)
{
xSampleEAPeriod = _Period;
}
//
// Validate Inputs ...
if (!XSampleEAValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
drawPrefix = ShortName;
//
// Initialize XTrader ...
xSampleEATrader = new XSCTrade(
xSampleEASlippage,
xSampleEAMagicNumber);
//
// 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 xSampleEATrader;
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!IsNewCandle(
xSampleEASymbol,
xSampleEAPeriod))
{
return;
}
//
// Reading Tick ...
if (!SymbolInfoTick(xSampleEASymbol, xSampleEATick))
{
return;
}
//
// Counting Currently Open Positions ...
buyCount = xSampleEATrader.CountPositions(xSampleEASymbol, POSITION_TYPE_BUY);
sellCount = xSampleEATrader.CountPositions(xSampleEASymbol, POSITION_TYPE_SELL);
//
if (buyCount < maxBuys)
{
//
// Check For Buy Signals ...
}
//
if (sellCount < maxSells)
{
//
// Check for Sell Signals ...
}
}
//
// Custom Functions ...
//
// Validate Variables nd Inputs ...
bool XSampleEAValidateInputs()
{
//
bool result = false;
//
result =
//
xSampleEASlippage > 0 &&
xSampleEAMagicNumber > 0
//
;
//
return result;
}