515 lines
9.5 KiB
Plaintext
515 lines
9.5 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XSCXCHEHelper
|
|
// 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
|
|
|
|
//
|
|
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
enum ENUM_XCHE_BUFFERS
|
|
{
|
|
X_CHE_LONG_EXIT_1_LINE = 0,
|
|
X_CHE_SHORT_EXIT_1_LINE = 1,
|
|
X_CHE_LONG_EXIT_2_LINE = 2,
|
|
X_CHE_SHORT_EXIT_2_LINE = 3,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct XCHEInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Market ...
|
|
int length; // Length
|
|
int loopback; // Loopback
|
|
double multiplier1; // 1st Multiplier
|
|
double multiplier2; // 2nd Multiplier
|
|
|
|
//
|
|
// Calculation ...
|
|
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied To
|
|
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied To
|
|
|
|
//
|
|
// Presentation ...
|
|
bool showLongExit1Line; // Show 1st Long Exit
|
|
bool showShortExit1Line; // Show 1st Short Exit
|
|
bool showLongExit2Line; // Show 2st Long Exit
|
|
bool showShortExit2Line; // Show 2st Short Exit
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
XCHEInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
length = 0;
|
|
loopback = 0;
|
|
multiplier1 = 0;
|
|
multiplier2 = 0;
|
|
|
|
//
|
|
upAppliedTo = PRICE_HIGH;
|
|
downAppliedTo = PRICE_LOW;
|
|
|
|
//
|
|
showLongExit1Line = false;
|
|
showShortExit1Line = false;
|
|
showLongExit2Line = false;
|
|
showShortExit2Line = false;
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
length = 35;
|
|
loopback = 26;
|
|
multiplier1 = 3.0;
|
|
multiplier2 = 3.5;
|
|
|
|
//
|
|
upAppliedTo = PRICE_HIGH;
|
|
downAppliedTo = PRICE_LOW;
|
|
|
|
//
|
|
showLongExit1Line = true;
|
|
showShortExit1Line = true;
|
|
showLongExit2Line = true;
|
|
showShortExit2Line = true;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
length > 0 &&
|
|
loopback < length &&
|
|
multiplier1 > 0 &&
|
|
multiplier2 > multiplier1
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(length, loopback);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Class ...
|
|
class XSCXCHEHelper : public XSCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XSCXCHEHelper() : XSCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XSCXCHEHelper() {}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
XCHEInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
ArraySetAsSeries(longExit1Buffer, true);
|
|
ArraySetAsSeries(longExit2Buffer, true);
|
|
ArraySetAsSeries(shortExit1Buffer, true);
|
|
ArraySetAsSeries(shortExit2Buffer, true);
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.xche",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
mInputs.length,
|
|
mInputs.loopback,
|
|
mInputs.multiplier1,
|
|
mInputs.multiplier2,
|
|
//
|
|
// Calculations ...
|
|
"",
|
|
mInputs.upAppliedTo,
|
|
mInputs.downAppliedTo,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
mInputs.showLongExit1Line, // Show 1st Long Exit,
|
|
mInputs.showShortExit1Line, // Show 1st Short Exit,
|
|
mInputs.showLongExit2Line, // Show 2st Long Exit,
|
|
mInputs.showShortExit2Line // Show 2st Short Exit
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
XCHEInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
XCHEInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs);
|
|
}
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
double GetLongExit1(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return longExit1Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Long Exits 1 ...
|
|
int CopyLongExit1(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
longExit1Buffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetLongExit2(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return longExit2Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Long Exits 2 ...
|
|
int CopyLongExit2(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
longExit2Buffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetShortExit1(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return shortExit1Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Short Exits 1 ...
|
|
int CopyShortExit1(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
shortExit1Buffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetShortExit2(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
return shortExit2Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Short Exits 2 ...
|
|
int CopyShortExit2(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate();
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
start,
|
|
count,
|
|
shortExit2Buffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
XCHEInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
//
|
|
double longExit1Buffer[];
|
|
double longExit2Buffer[];
|
|
double shortExit1Buffer[];
|
|
double shortExit2Buffer[];
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Calculate Values Until Now ...
|
|
void Calculate()
|
|
{
|
|
//
|
|
int totalBars = CountBars();
|
|
int calculatedBars = CountCalculatedBars();
|
|
|
|
//
|
|
// Long Exit 1 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_CHE_LONG_EXIT_1_LINE,
|
|
0,
|
|
totalBars,
|
|
longExit1Buffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Long Exit 2 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_CHE_LONG_EXIT_2_LINE,
|
|
0,
|
|
totalBars,
|
|
longExit2Buffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Short Exit 1 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_CHE_SHORT_EXIT_1_LINE,
|
|
0,
|
|
totalBars,
|
|
shortExit1Buffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Short Exit 2 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X_CHE_SHORT_EXIT_2_LINE,
|
|
0,
|
|
totalBars,
|
|
shortExit2Buffer
|
|
//
|
|
);
|
|
}
|
|
};
|
|
|
|
//
|
|
// Tools ...
|