last works on XInd and XMid ...
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Imports ...
|
// Imports ...
|
||||||
#include <Indicators/Indicator.mqh>
|
#include "../../Classes/x-saherelm.xind.class.mq5"
|
||||||
|
|
||||||
//
|
//
|
||||||
// XSCMid Indicator Buffers ...
|
// XSCMid Indicator Buffers ...
|
||||||
@@ -136,8 +136,258 @@ struct XSCMidInputs
|
|||||||
//
|
//
|
||||||
// a Simple Indicator ...
|
// 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 ...
|
// Protected ...
|
||||||
|
|||||||
@@ -48,14 +48,18 @@ struct XBuffer
|
|||||||
//
|
//
|
||||||
// Tools ...
|
// Tools ...
|
||||||
bool Init(
|
bool Init(
|
||||||
string mTitle // Title
|
string mTitle, // Title
|
||||||
|
string mSymbol, // Symbol
|
||||||
|
ENUM_TIMEFRAMES mPeriod // TimeFrame
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
//
|
//
|
||||||
result = IsValid(mTitle);
|
result = IsValid(mTitle) &&
|
||||||
|
IsValid(mSymbol) &&
|
||||||
|
IsValid(mPeriod);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
@@ -64,6 +68,10 @@ struct XBuffer
|
|||||||
//
|
//
|
||||||
Clean();
|
Clean();
|
||||||
|
|
||||||
|
//
|
||||||
|
this.symbol = mSymbol;
|
||||||
|
this.period = mPeriod;
|
||||||
|
|
||||||
//
|
//
|
||||||
result = StringToLower(mTitle);
|
result = StringToLower(mTitle);
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -72,8 +80,7 @@ struct XBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
title = mTitle;
|
this.title = mTitle;
|
||||||
// ArraySetAsSeries(values, false);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
result = IsValid();
|
result = IsValid();
|
||||||
@@ -155,7 +162,10 @@ struct XBuffer
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Add Value to Buffer ...
|
// Add Value to Buffer ...
|
||||||
int Add(double value)
|
int Add(
|
||||||
|
int index,
|
||||||
|
double value //
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
int result = -1;
|
int result = -1;
|
||||||
@@ -167,45 +177,13 @@ struct XBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
datetime time = GetPeriodStartTime(
|
if (index > 0)
|
||||||
this.symbol,
|
|
||||||
this.period);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Date Exists before ...
|
|
||||||
int timeIDX = FindIndex(
|
|
||||||
time,
|
|
||||||
times //
|
|
||||||
);
|
|
||||||
if (timeIDX >= 0)
|
|
||||||
{
|
{
|
||||||
//
|
Add(value, values);
|
||||||
// Item Exists ...
|
|
||||||
// Update it ...
|
|
||||||
|
|
||||||
//
|
|
||||||
values[timeIDX] = value;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
values[Count() - 1] = value;
|
||||||
// New Item ...
|
|
||||||
// Add It ...
|
|
||||||
|
|
||||||
//
|
|
||||||
int count = Count();
|
|
||||||
ArrayResize(
|
|
||||||
values,
|
|
||||||
count + 1 //
|
|
||||||
);
|
|
||||||
ArrayResize(
|
|
||||||
times,
|
|
||||||
count + 1 //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
times[count] = time;
|
|
||||||
values[count] = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -269,76 +247,6 @@ struct XBuffer
|
|||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
double Get(
|
|
||||||
datetime time = NULL //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double result = EMPTY_VALUE;
|
|
||||||
|
|
||||||
//
|
|
||||||
NormalizeTime(time);
|
|
||||||
|
|
||||||
//
|
|
||||||
datetime iTime = GetPeriodStartTime(
|
|
||||||
this.symbol,
|
|
||||||
this.period,
|
|
||||||
time //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
int timeIDX = FindIndex(
|
|
||||||
iTime,
|
|
||||||
this.times //
|
|
||||||
);
|
|
||||||
if (timeIDX < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = Get(timeIDX);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool Remove(
|
|
||||||
datetime time = NULL //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
NormalizeTime(time);
|
|
||||||
|
|
||||||
//
|
|
||||||
datetime iTime = GetPeriodStartTime(
|
|
||||||
this.symbol,
|
|
||||||
this.period,
|
|
||||||
time //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
int timeIDX = FindIndex(
|
|
||||||
iTime,
|
|
||||||
this.times //
|
|
||||||
);
|
|
||||||
if (timeIDX < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = Remove(timeIDX);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -415,6 +323,44 @@ public:
|
|||||||
//
|
//
|
||||||
// Tools ...
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime GetBarTime(
|
||||||
|
datetime time = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
NormalizeTime(time);
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime result = GetPeriodStartTime(
|
||||||
|
mSymbol,
|
||||||
|
mPeriod,
|
||||||
|
time //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int GetBarIndex(
|
||||||
|
datetime time = NULL //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
datetime iBarTime = GetBarTime(time);
|
||||||
|
|
||||||
|
//
|
||||||
|
int result = iBarShift(
|
||||||
|
mSymbol,
|
||||||
|
mPeriod,
|
||||||
|
iBarTime //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Retrieve Calculate Bars ...
|
// Retrieve Calculate Bars ...
|
||||||
int GetCalculatedBars()
|
int GetCalculatedBars()
|
||||||
@@ -459,6 +405,23 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Limit ...
|
||||||
|
// this means Required Bars for Calculation ...
|
||||||
|
int CountLimit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int totalBars = CountBars();
|
||||||
|
int calculatedBars = GetCalculatedBars();
|
||||||
|
result = MathAbs(totalBars - calculatedBars);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Buffer Registrations ...
|
// Buffer Registrations ...
|
||||||
|
|
||||||
@@ -626,25 +589,25 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
double GetBufferValue(
|
int CopyBufferValue(
|
||||||
string mTitle, // Required Buffer Title
|
string mTitle,
|
||||||
datetime time = NULL // Time
|
double &buffer[],
|
||||||
|
int start,
|
||||||
|
int count //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
NormalizeTime(time);
|
int result = 0;
|
||||||
double result = EMPTY_VALUE;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Validate State ...
|
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
int bufferIDX = GetBufferIndex(mTitle);
|
int sourceIDX = GetBufferIndex(mTitle);
|
||||||
if (bufferIDX < 0)
|
if (sourceIDX < 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -653,7 +616,13 @@ public:
|
|||||||
Calculate();
|
Calculate();
|
||||||
|
|
||||||
//
|
//
|
||||||
result = mBuffers[bufferIDX].Get(time);
|
result = ArrayCopy(
|
||||||
|
buffer,
|
||||||
|
mBuffers[sourceIDX].values,
|
||||||
|
start,
|
||||||
|
start,
|
||||||
|
count //
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -122,17 +122,17 @@ int OnCalculate(
|
|||||||
//
|
//
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||||
|
|
||||||
// //
|
//
|
||||||
// int midMainCopiedItems = mMid.CopyBufferValueByLine(
|
int midMainCopiedItems = mMid.CopyBufferValue(
|
||||||
// XSCMID_MAIN_LINE,
|
GetTitle(XSCMID_MAIN_LINE),
|
||||||
// mainBuffer,
|
mainBuffer,
|
||||||
// 0,
|
0,
|
||||||
// limit //
|
limit //
|
||||||
// );
|
);
|
||||||
// if (midMainCopiedItems <= 0)
|
if (midMainCopiedItems <= 0)
|
||||||
// {
|
{
|
||||||
// return prev_calculated;
|
return prev_calculated;
|
||||||
// }
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Main Loop ...
|
// Main Loop ...
|
||||||
@@ -211,6 +211,7 @@ void DefineBuffers()
|
|||||||
XBufferPlotStyle mainBufferStyle;
|
XBufferPlotStyle mainBufferStyle;
|
||||||
mainBufferStyle.clr = clrAqua;
|
mainBufferStyle.clr = clrAqua;
|
||||||
mainBufferStyle.type = DRAW_LINE;
|
mainBufferStyle.type = DRAW_LINE;
|
||||||
|
mainBufferStyle.width = 3;
|
||||||
|
|
||||||
//
|
//
|
||||||
SetIndexBuffer(
|
SetIndexBuffer(
|
||||||
@@ -220,8 +221,7 @@ void DefineBuffers()
|
|||||||
mainColorBuffer,
|
mainColorBuffer,
|
||||||
bufferLabel,
|
bufferLabel,
|
||||||
true,
|
true,
|
||||||
0,
|
EMPTY_VALUE //
|
||||||
max //
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,18 +235,4 @@ void SetIndicatorName()
|
|||||||
//
|
//
|
||||||
void CalculateBuffers(int barIndex)
|
void CalculateBuffers(int barIndex)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
double iValue = mMid.GetBufferValueByLine(
|
|
||||||
XSCMID_MAIN_LINE,
|
|
||||||
barIndex //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// double iValue = iClose(
|
|
||||||
// _Symbol,
|
|
||||||
// _Period,
|
|
||||||
// barIndex //
|
|
||||||
// );
|
|
||||||
|
|
||||||
mainBuffer[barIndex] = iValue;
|
|
||||||
}
|
}
|
||||||
@@ -4055,6 +4055,15 @@ void CalculateTPSL(
|
|||||||
: mEntry + reward;
|
: mEntry + reward;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
bool GetTick(
|
||||||
|
string mSymbol,
|
||||||
|
MqlTick &tick //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return SymbolInfoTick(mSymbol, tick);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Symbols ...
|
// Symbols ...
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user