last works on XInd and XMid ...
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include <Indicators/Indicator.mqh>
|
||||
#include "../../Classes/x-saherelm.xind.class.mq5"
|
||||
|
||||
//
|
||||
// XSCMid Indicator Buffers ...
|
||||
@@ -136,8 +136,258 @@ struct XSCMidInputs
|
||||
//
|
||||
// a Simple Indicator ...
|
||||
|
||||
class XSCMid : public CIndicator
|
||||
class XSCMid : public XSCBaseInd
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCMid(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading TimeFrame
|
||||
) : XSCBaseInd(symbol, period)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mCalculatedBars = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCMid() {}
|
||||
//
|
||||
// Initialize Indicator ...
|
||||
bool Init(
|
||||
XSCMidInputs &inputs // Indicator Inputs ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Inputs ...
|
||||
this.mInputs = inputs;
|
||||
|
||||
//
|
||||
// Validate Indicator State ...
|
||||
result = this.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Register Required Buffers ...
|
||||
XBuffer main;
|
||||
string mTitle = GetTitle(XSCMID_MAIN_LINE);
|
||||
result = main.Init(
|
||||
mTitle,
|
||||
mSymbol,
|
||||
mPeriod //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = SetBuffer(main);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate First Time ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Property Getter(s) / Setter(s) ...
|
||||
|
||||
//
|
||||
XSCMidInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XSCMidInputs &inputs // Indicator Inputs
|
||||
)
|
||||
{
|
||||
return Init(inputs);
|
||||
}
|
||||
|
||||
//
|
||||
// Override(s) ...
|
||||
|
||||
//
|
||||
// Get Tag ...
|
||||
string GetTag() override
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = GetToken();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Token ...
|
||||
string GetToken() override
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = GetSpecificToken(this);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
bool IsValidInputs() override
|
||||
{
|
||||
return mInputs.IsValid();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void Calculate() override
|
||||
{
|
||||
//
|
||||
int max = mInputs.Max();
|
||||
int limit = CountLimit();
|
||||
int totalBars = CountBars();
|
||||
int prevCalculated = GetCalculatedBars();
|
||||
|
||||
//
|
||||
// Prepare Buffers Index ...
|
||||
int mainIDX = GetBufferIndexByLine(XSCMID_MAIN_LINE);
|
||||
|
||||
//
|
||||
// Print("Total: ", totalBars, ", prevCalculated: ", prevCalculated, ", Limit: ", limit);
|
||||
|
||||
//
|
||||
// Only Calculate Last Item ...
|
||||
bool onlyLast = false;
|
||||
if (prevCalculated == totalBars - 1)
|
||||
{
|
||||
onlyLast = true;
|
||||
}
|
||||
|
||||
//
|
||||
int start = totalBars - prevCalculated - 1;
|
||||
for (int i = start; i >= 0; i--)
|
||||
{
|
||||
//
|
||||
int barIndex = i - 1;
|
||||
// Print("barIndex: ", barIndex, ", onlyLast: ", onlyLast);
|
||||
if (barIndex < 0 && !onlyLast)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
if (onlyLast)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
datetime iBarTime = iTime(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
barIndex - 1
|
||||
//
|
||||
);
|
||||
int iBarIndex = iBarShift(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
iBarTime //
|
||||
);
|
||||
|
||||
//
|
||||
double iValue = iClose(mSymbol, mPeriod, iBarIndex);
|
||||
|
||||
//
|
||||
Print("Bar: ", barIndex, ", Bar Time: ", iBarTime, ", Bar Index: ", iBarIndex, ", iValue: ", iValue);
|
||||
if (iValue != 0.0)
|
||||
{
|
||||
//
|
||||
// Print("Bar: ", barIndex, ", Bar Time: ", iBarTime, ", Bar Index: ", iBarIndex, ", iValue: ", iValue);
|
||||
mBuffers[mainIDX].Add(barIndex, iValue);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent Double Calculation Same Bars ...
|
||||
mCalculatedBars = totalBars - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// De Initialize Class ...
|
||||
void DeInit(int reason)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
int GetBufferIndexByLine(
|
||||
ENUM_XSCMID_BUFFERS bufferLine // Specified Buffer Line
|
||||
)
|
||||
{
|
||||
//
|
||||
string mTitle = GetTitle(bufferLine);
|
||||
return GetBufferIndex(mTitle);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetBufferByLine(
|
||||
ENUM_XSCMID_BUFFERS bufferLine, // Specified Buffer Line
|
||||
XBuffer &buffer // Hold Result
|
||||
)
|
||||
{
|
||||
//
|
||||
string mTitle = GetTitle(bufferLine);
|
||||
return GetBuffer(mTitle, buffer);
|
||||
}
|
||||
|
||||
// //
|
||||
// double GetBufferValueByLine(
|
||||
// ENUM_XSCMID_BUFFERS bufferLine, // Specified Buffer Line
|
||||
// datetime time = NULL // Time
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// string mTitle = GetTitle(bufferLine);
|
||||
// return GetBufferValue(mTitle, time);
|
||||
// }
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
|
||||
Reference in New Issue
Block a user