last works on XInd and XMid ...
This commit is contained in:
@@ -48,14 +48,18 @@ struct XBuffer
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string mTitle // Title
|
||||
string mTitle, // Title
|
||||
string mSymbol, // Symbol
|
||||
ENUM_TIMEFRAMES mPeriod // TimeFrame
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mTitle);
|
||||
result = IsValid(mTitle) &&
|
||||
IsValid(mSymbol) &&
|
||||
IsValid(mPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -64,6 +68,10 @@ struct XBuffer
|
||||
//
|
||||
Clean();
|
||||
|
||||
//
|
||||
this.symbol = mSymbol;
|
||||
this.period = mPeriod;
|
||||
|
||||
//
|
||||
result = StringToLower(mTitle);
|
||||
if (!result)
|
||||
@@ -72,8 +80,7 @@ struct XBuffer
|
||||
}
|
||||
|
||||
//
|
||||
title = mTitle;
|
||||
// ArraySetAsSeries(values, false);
|
||||
this.title = mTitle;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
@@ -155,7 +162,10 @@ struct XBuffer
|
||||
|
||||
//
|
||||
// Add Value to Buffer ...
|
||||
int Add(double value)
|
||||
int Add(
|
||||
int index,
|
||||
double value //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
@@ -167,45 +177,13 @@ struct XBuffer
|
||||
}
|
||||
|
||||
//
|
||||
datetime time = GetPeriodStartTime(
|
||||
this.symbol,
|
||||
this.period);
|
||||
|
||||
//
|
||||
// Check Date Exists before ...
|
||||
int timeIDX = FindIndex(
|
||||
time,
|
||||
times //
|
||||
);
|
||||
if (timeIDX >= 0)
|
||||
if (index > 0)
|
||||
{
|
||||
//
|
||||
// Item Exists ...
|
||||
// Update it ...
|
||||
|
||||
//
|
||||
values[timeIDX] = value;
|
||||
Add(value, values);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// New Item ...
|
||||
// Add It ...
|
||||
|
||||
//
|
||||
int count = Count();
|
||||
ArrayResize(
|
||||
values,
|
||||
count + 1 //
|
||||
);
|
||||
ArrayResize(
|
||||
times,
|
||||
count + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
times[count] = time;
|
||||
values[count] = value;
|
||||
values[Count() - 1] = value;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -269,76 +247,6 @@ struct XBuffer
|
||||
//
|
||||
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 ...
|
||||
|
||||
//
|
||||
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 ...
|
||||
int GetCalculatedBars()
|
||||
@@ -459,6 +405,23 @@ public:
|
||||
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 ...
|
||||
|
||||
@@ -626,25 +589,25 @@ public:
|
||||
}
|
||||
|
||||
//
|
||||
double GetBufferValue(
|
||||
string mTitle, // Required Buffer Title
|
||||
datetime time = NULL // Time
|
||||
int CopyBufferValue(
|
||||
string mTitle,
|
||||
double &buffer[],
|
||||
int start,
|
||||
int count //
|
||||
)
|
||||
{
|
||||
//
|
||||
NormalizeTime(time);
|
||||
double result = EMPTY_VALUE;
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Validate State ...
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int bufferIDX = GetBufferIndex(mTitle);
|
||||
if (bufferIDX < 0)
|
||||
int sourceIDX = GetBufferIndex(mTitle);
|
||||
if (sourceIDX < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -653,7 +616,13 @@ public:
|
||||
Calculate();
|
||||
|
||||
//
|
||||
result = mBuffers[bufferIDX].Get(time);
|
||||
result = ArrayCopy(
|
||||
buffer,
|
||||
mBuffers[sourceIDX].values,
|
||||
start,
|
||||
start,
|
||||
count //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user