734 lines
13 KiB
Plaintext
734 lines
13 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XSCXFBBHelper
|
|
// Description: provides all Indicator
|
|
// Helper requirements ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
// START Definitions ...
|
|
//
|
|
|
|
//
|
|
// Inputs ...
|
|
struct XFBBInputs
|
|
{
|
|
//
|
|
// Market ...
|
|
//
|
|
// Length ...
|
|
int length;
|
|
//
|
|
// Multiplier ...
|
|
double multiplier;
|
|
//
|
|
// Applied To ...
|
|
ENUM_APPLIED_PRICE appliedTo;
|
|
|
|
//
|
|
// Presentation ...
|
|
//
|
|
// Show Base ...
|
|
bool showBase;
|
|
//
|
|
// Show Band ...
|
|
bool showBand;
|
|
//
|
|
// Show Golden Area ...
|
|
bool showGoldenArea;
|
|
//
|
|
// Show Other Levels ...
|
|
bool showOthers;
|
|
};
|
|
|
|
//
|
|
// Index of Lines ...
|
|
enum ENUM_XFBB_BUFFERS
|
|
{
|
|
//
|
|
// Main Requirements ...
|
|
XFBB_BASE_LINE = 0,
|
|
XFBB_BASE_STATE_LINE = 1,
|
|
XFBB_UP_BAND_LINE = 13,
|
|
XFBB_DOWN_BAND_LINE = 24,
|
|
//
|
|
XFBB_UP_1_LINE = 2,
|
|
XFBB_UP_2_LINE = 4,
|
|
XFBB_UP_3_LINE = 6,
|
|
XFBB_UP_4_LINE = 8,
|
|
XFBB_UP_5_LINE = 10,
|
|
//
|
|
XFBB_DOWN_1_LINE = 14,
|
|
XFBB_DOWN_2_LINE = 16,
|
|
XFBB_DOWN_3_LINE = 18,
|
|
XFBB_DOWN_4_LINE = 20,
|
|
XFBB_DOWN_5_LINE = 22,
|
|
};
|
|
|
|
//
|
|
// Retrieve Info Model ...
|
|
struct XFBBInfo
|
|
{
|
|
//
|
|
// Symbol ...
|
|
string symbol;
|
|
|
|
//
|
|
// Period ...
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
// Bar Time ...
|
|
datetime barTime;
|
|
|
|
//
|
|
// Bar Index ...
|
|
int barIndex;
|
|
|
|
//
|
|
// Values ...
|
|
double base;
|
|
double baseState;
|
|
|
|
//
|
|
double upBand;
|
|
double downBand;
|
|
|
|
//
|
|
double up1;
|
|
double up2;
|
|
double up3;
|
|
double up4;
|
|
double up5;
|
|
|
|
//
|
|
double down1;
|
|
double down2;
|
|
double down3;
|
|
double down4;
|
|
double down5;
|
|
|
|
//
|
|
double bases[];
|
|
double baseStates[];
|
|
double upBands[];
|
|
double downBands[];
|
|
double up1s[];
|
|
double up2s[];
|
|
double up3s[];
|
|
double up4s[];
|
|
double up5s[];
|
|
double down1s[];
|
|
double down2s[];
|
|
double down3s[];
|
|
double down4s[];
|
|
double down5s[];
|
|
|
|
//
|
|
// Conditions ...
|
|
};
|
|
|
|
//
|
|
// END Definitions ...
|
|
//
|
|
|
|
//
|
|
// START Import and Inclused requirements ...
|
|
//
|
|
|
|
//
|
|
// Includes ...
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
|
|
|
//
|
|
// END Import and Inclused requirements ...
|
|
//
|
|
|
|
//
|
|
// START Overrides ...
|
|
//
|
|
|
|
//
|
|
// END Overrides ...
|
|
//
|
|
|
|
//
|
|
// a Class for Helping Indicators Requirements ...
|
|
class XSCXFBBHelper : public XSCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Buffers ...
|
|
double baseBuffer[];
|
|
double baseStateBuffer[];
|
|
double upBandBuffer[];
|
|
double downBandBuffer[];
|
|
double up1Buffer[];
|
|
double up2Buffer[];
|
|
double up3Buffer[];
|
|
double up4Buffer[];
|
|
double up5Buffer[];
|
|
double down1Buffer[];
|
|
double down2Buffer[];
|
|
double down3Buffer[];
|
|
double down4Buffer[];
|
|
double down5Buffer[];
|
|
|
|
//
|
|
// Constructor ...
|
|
void XSCXFBBHelper(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period // Trading Time Frame
|
|
) : XSCBaseHelper(symbol, period)
|
|
{
|
|
PrepareTag();
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
void ~XSCXFBBHelper()
|
|
{
|
|
}
|
|
|
|
//
|
|
// START Properties ...
|
|
//
|
|
|
|
//
|
|
// END Properties ...
|
|
//
|
|
|
|
//
|
|
// START Provided Functions ...
|
|
//
|
|
|
|
//
|
|
// Prepare Tag ...
|
|
virtual void PrepareTag()
|
|
{
|
|
mTag = "XFBB" + GetTagPrefix();
|
|
}
|
|
|
|
//
|
|
virtual int GetMaxLength()
|
|
{
|
|
//
|
|
int result = -1;
|
|
|
|
//
|
|
result = mLength;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initial Indicator Handler ...
|
|
bool Init()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Validate Args ...
|
|
result =
|
|
//
|
|
(mLength >= 2 &&
|
|
mMultiplier >= 0)
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// Initialize Handler ...
|
|
mHandler = iCustom(
|
|
//
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.xfbb",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
//
|
|
// Length ...
|
|
mLength,
|
|
//
|
|
// Multiplier ...
|
|
mMultiplier,
|
|
//
|
|
// Applied To ...
|
|
mApliedTo,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
//
|
|
// Show Base ...
|
|
mShowBase,
|
|
//
|
|
// Show Band ...
|
|
mShowBand,
|
|
//
|
|
// Show Golden Area ...
|
|
mShowGoldenArea,
|
|
//
|
|
// Show Other Levels ...
|
|
mShowOthers
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve Current Config ...
|
|
XFBBInputs GetConfig()
|
|
{
|
|
//
|
|
XFBBInputs result;
|
|
|
|
//
|
|
result.length = mLength;
|
|
result.multiplier = mMultiplier;
|
|
result.appliedTo = mApliedTo;
|
|
result.showBase = mShowBase;
|
|
result.showBand = mShowBand;
|
|
result.showGoldenArea = mShowGoldenArea;
|
|
result.showOthers = mShowOthers;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Set Config ...
|
|
bool SetConfig(XFBBInputs &config)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mLength = config.length;
|
|
mMultiplier = config.multiplier;
|
|
mApliedTo = config.appliedTo;
|
|
mShowBase = config.showBase;
|
|
mShowBand = config.showBand;
|
|
mShowGoldenArea = config.showGoldenArea;
|
|
mShowOthers = config.showOthers;
|
|
|
|
//
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Show Base ...
|
|
bool ShowBase(
|
|
bool show // Show or Hide
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowBase == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowBase = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Show Band ...
|
|
bool ShowBand(
|
|
bool show // Show or Hide
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowBand == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowBand = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Show Golden Area ...
|
|
bool ShowGoldenArea(
|
|
bool show // Show or Hide
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowGoldenArea == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowGoldenArea = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Show Other Levels ...
|
|
bool ShowOthers(
|
|
bool show // Show or Hide
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (mShowOthers == show)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//
|
|
mShowOthers = show;
|
|
result = Init();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Reading Buffers based on Given Bar Index ...
|
|
virtual void Calculate(
|
|
int barIndex // Given Bar Index
|
|
)
|
|
{
|
|
//
|
|
// BASE ...
|
|
ArraySetAsSeries(baseBuffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_BASE_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
baseBuffer);
|
|
|
|
//
|
|
// BASE STATE ...
|
|
ArraySetAsSeries(baseStateBuffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_BASE_STATE_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
baseStateBuffer);
|
|
|
|
//
|
|
// UPBAND ...
|
|
ArraySetAsSeries(upBandBuffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_UP_BAND_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
upBandBuffer);
|
|
|
|
//
|
|
// DOWNBAND ...
|
|
ArraySetAsSeries(downBandBuffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_DOWN_BAND_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
downBandBuffer);
|
|
|
|
//
|
|
// UP 1 ...
|
|
ArraySetAsSeries(up1Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_UP_1_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
up1Buffer);
|
|
|
|
//
|
|
// UP 2 ...
|
|
ArraySetAsSeries(up2Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_UP_2_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
up2Buffer);
|
|
|
|
//
|
|
// UP 3 ...
|
|
ArraySetAsSeries(up3Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_UP_3_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
up3Buffer);
|
|
|
|
//
|
|
// UP 4 ...
|
|
ArraySetAsSeries(up4Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_UP_4_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
up4Buffer);
|
|
|
|
//
|
|
// UP 5 ...
|
|
ArraySetAsSeries(up5Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_UP_5_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
up5Buffer);
|
|
|
|
//
|
|
// DOWN 1 ...
|
|
ArraySetAsSeries(down1Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_DOWN_1_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
down1Buffer);
|
|
|
|
//
|
|
// DOWN 2 ...
|
|
ArraySetAsSeries(down2Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_DOWN_2_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
down2Buffer);
|
|
|
|
//
|
|
// DOWN 3 ...
|
|
ArraySetAsSeries(down3Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_DOWN_3_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
down3Buffer);
|
|
|
|
//
|
|
// DOWN 4 ...
|
|
ArraySetAsSeries(down4Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_DOWN_4_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
down4Buffer);
|
|
|
|
//
|
|
// DOWN 5 ...
|
|
ArraySetAsSeries(down5Buffer, true);
|
|
CopyBuffer(
|
|
mHandler,
|
|
XFBB_DOWN_5_LINE,
|
|
barIndex,
|
|
mLoopbackBars,
|
|
down5Buffer);
|
|
}
|
|
|
|
//
|
|
// Retrieve Info at Specific Bar Index ...
|
|
XFBBInfo GetInfo(
|
|
int barIndex // Given Bar Index
|
|
)
|
|
{
|
|
//
|
|
XFBBInfo result;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
// Do Calculations ...
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
// Generate Candle Time ...
|
|
datetime barTime = GetCandleTime(
|
|
mSymbol,
|
|
mPeriod,
|
|
barIndex);
|
|
|
|
//
|
|
// Fill Result ...
|
|
result.symbol = mSymbol;
|
|
result.period = mPeriod;
|
|
result.barTime = barTime;
|
|
result.barIndex = barIndex;
|
|
|
|
//
|
|
// values ...
|
|
result.base = baseBuffer[barIndex];
|
|
result.baseState = baseStateBuffer[barIndex];
|
|
result.upBand = upBandBuffer[barIndex];
|
|
result.downBand = downBandBuffer[barIndex];
|
|
result.up1 = up1Buffer[barIndex];
|
|
result.up2 = up2Buffer[barIndex];
|
|
result.up3 = up3Buffer[barIndex];
|
|
result.up4 = up4Buffer[barIndex];
|
|
result.up5 = up5Buffer[barIndex];
|
|
result.down1 = down1Buffer[barIndex];
|
|
result.down2 = down2Buffer[barIndex];
|
|
result.down3 = down3Buffer[barIndex];
|
|
result.down4 = down4Buffer[barIndex];
|
|
result.down5 = down5Buffer[barIndex];
|
|
|
|
//
|
|
Copy(
|
|
baseBuffer,
|
|
result.bases);
|
|
Copy(
|
|
baseStateBuffer,
|
|
result.baseStates);
|
|
Copy(
|
|
upBandBuffer,
|
|
result.upBands);
|
|
Copy(
|
|
downBandBuffer,
|
|
result.downBands);
|
|
Copy(
|
|
up1Buffer,
|
|
result.up1s);
|
|
Copy(
|
|
up2Buffer,
|
|
result.up2s);
|
|
Copy(
|
|
up3Buffer,
|
|
result.up3s);
|
|
Copy(
|
|
up4Buffer,
|
|
result.up4s);
|
|
Copy(
|
|
up5Buffer,
|
|
result.up5s);
|
|
Copy(
|
|
down1Buffer,
|
|
result.down1s);
|
|
Copy(
|
|
down2Buffer,
|
|
result.down2s);
|
|
Copy(
|
|
down3Buffer,
|
|
result.down3s);
|
|
Copy(
|
|
down4Buffer,
|
|
result.down4s);
|
|
Copy(
|
|
down5Buffer,
|
|
result.down5s);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// END Provided Functions ...
|
|
//
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Indicator Properties ...
|
|
//
|
|
// Market ...
|
|
//
|
|
// Length ...
|
|
int mLength;
|
|
//
|
|
// Multiplier ...
|
|
double mMultiplier;
|
|
//
|
|
// Applied To ...
|
|
ENUM_APPLIED_PRICE mApliedTo;
|
|
|
|
//
|
|
// Presentation ...
|
|
//
|
|
// Show Base ...
|
|
bool mShowBase;
|
|
//
|
|
// Show Band ...
|
|
bool mShowBand;
|
|
//
|
|
// Show Golden Area ...
|
|
bool mShowGoldenArea;
|
|
//
|
|
// Show Other Levels ...
|
|
bool mShowOthers;
|
|
};
|
|
|
|
//
|
|
// START Usefull Functions ...
|
|
//
|
|
|
|
//
|
|
// END Usefull Functions ...
|
|
//
|