Reputation: 394
I'm working on a custom indicator...
Double Arrays set as IndexBuffers automatically shift right each time a new bar is created. As do Constants such as Open[], Close[], etc. The reason for this is fairly obvious... the same code can be use when chart is loaded as when the graph updates, without having to recalculate existing bars.
int start()
{
int Counted_bars;
Counted_bars=IndicatorCounted();
i=Bars-Counted_bars-1;
while(i>=0)
{
IndicatorBuffer[i] = [Some-calculations];
i--;
}
return (1);
}
Is there a way to declare an array that will also shift automatically along with everything else whenever a new bar is created? Preferably using the Existing API. So like:
enum Range{Low, Mid, high};
Range[] BarRange; //A Range value corresponding to each bar, calculates in the start loop.
How to keep it in Sync with the other arrays?
Upvotes: 1
Views: 1394
Reputation: 1
The initial idea of
enum Range{ Low,
Mid,
high
};
Range[] BarRange;
will ( as-of-2018/Q1 ) go beyond compiler's will to compile such code,
just a slightly modified approach will fit ( have used vast array-based analytics and augmented-trading tools based on this mechanism ):
#define getLow 0
#define getMid 1
#define getHigh 2
double array_of_almost_structs[][];
// | |
// | +----------+
// | |
// fill data as needed row# ~ bar#, col# ~ { getLow | getMid | getHigh }
So the syntax-limit could be circumvented.
CustomIndicator
code-units interfacing has additional points:Given your code-execution unit is expected to be used via a CustomIndicator
process-to-process interface, more issues come to get aligned.
The ExpertAdvisor
-type of the MQL4/5 code issues a call to iCustom()
interfacing proxy.
These details prevent your innovations on the CustomIndicator
-type of MQL4/5 code, as the "remote" call-initiator will not be able to properly "pick"-data-elements from any smarter "remote"-storage than the implicitly aligned / addressed by a "nailed"-down plain double array1D[];
, "registered" into the distributed CustomIndicator
<->
ExpertAdvisor
data-mation mechanics via a call to SetIndexBuffer( index, array );
Not much to do about this.
Upvotes: 0
Reputation: 4681
Declare a new array and assign it to SetIndexBuffer(number of array,arrayName, INDICATOR_CALCULATIONS)
so that to keep in invisible for drawing. It can use array of only double
type I am afraid, if you need a struct - then you have to use something else (probably change struct
to class
and fill in into CArrayObj
and check each bar to extend it or to add new element)
Upvotes: 0