MetaTrader: indicator buffers amount is less than needed - mql4

I get this error on compilation in MetaTrader:
indicator buffers amount is less than needed
any help?

MQL4 Indicator setup may look as a dual-headed nightmare.Maybe yes,maybe no:
There are two principal methods used for an Indicator setup.
one, using #property ... syntax interface,
and
another, using function calls ...
Why these two exist? How do they co-exist?
#property ...
indicator_chart_window Show the indicator in the chart window
indicator_separate_window Show the indicator in a separate window
indicator_height int Fixed height of the indicator subwindow in pixels (property INDICATOR_HEIGHT)
indicator_buffers int Number of buffers for indicator calculation
indicator_minimum double The bottom scaling limit for a separate indicator window
indicator_maximum double The top scaling limit for a separate indicator window
indicator_labelN string Sets a label for the N-th graphic series displayed in DataWindow
indicator_colorN color The color for displaying line N, where N is the number of graphic series; numbering starts from 1
indicator_widthN int Line thickness in graphic series, where N is the number of graphic series; numbering starts from 1
indicator_styleN int Line style in graphic series, specified by the values of ENUM_LINE_STYLE. N is the number of graphic series; numbering starts from 1
indicator_typeN int Type of indicator drawing style. N is the number of graphic series; numbering starts from 1
indicator_levelN double Horizontal level of N in a separate indicator window
indicator_levelcolor color Color of horizontal levels of the indicator
indicator_levelwidth int Thickness of horizontal levels of the indicator
indicator_levelstyle int Style of horizontal levels of the indicator
After some time in MQL4 you will adopt your own best way to go forwards.
Why failed to work?
Short version: a compile-time decision sets the amount of arrays preset for indicator time-series aligned data. Going past this set ceiling then must throw an exception as there is no further buffer to store data in.
However, setting a much bigger ceiling first is possible and may help, somewhere at a later time, to have still space enough, even when you do not use it right now.

That seems to be a problem of:
#property indicator_buffers XXX //How Many Plots
XXX should be correct number of Buffers/plots

Related

Open a trade when an indicator places an arrow in a chart

Is it possible for an EA to open a trade when an indicator places an arrow on the current candle or a previous candle? If yes, how?
I have an indicator that places an arrow where a trade say a BUY or a SELL can be placed. I know that we use code below to get the values of the signal.
double signal_v = iCustom(Symbol(),PERIOD_M1, "My Custom Indicator", 0, 1);
The indicator in this question places an arrow, and I want to know if there is a way one can tell if an arrow has been placed on the current or previous candle by this specific indicator. I have seen any sample codes so I was asking. Kindly.
1 in your example is number of bar (0 - current, 1 - previous one), 0 is the buffer.
For sure you will have at least two buffers if arrows are implemented from buffers (easy to check - open chart and delete all objects. if arrows stay there - then indicator has buffers and arrows are based on buffers. Open data window and check the bar that has an arrow - it must have value in some buffer line that is not zero and not empty, you can compare to other bars with no buffers.
Do not forget that you have to pass all indicator inputs after "My Custom Indicator" otherwise you will upload the indicator with default settings, not what you need.

MQL4 max bars in chart

I'm trying to limit resources consumed by MT4 and go to options to set max bars in chart to something smaller like 500. My custom indicator calculates values from a 10 and 20 EMA.
Now the indicator does not even want to attach to the chart!
Even if I increase the number I cannot get my CI to attach to the chart again.
Please can you let me know what the minimum number should be for max bars in chart and why a simple CI as set out above will not attach to the chart?
Lastly, could you please help me also by stating what the default value for max bars in chart normally is? I thought it is 999999 but cannot remember.
Thanks so much for your effort.
In order to use your resources efficiently, ask your indicator to compute only last bars, prev_calculated should be used and go only since that value to the end of the chart(to the current bar). You can also make your indicator sleeping if number of bars is same, and let it run only when new bar appears (rates_total>prev_calculated) if that can be accepted for your task

Tweaking display of quality histogram, exporting the colormap

I have a couple of questions, which get tied back to a simple need - I want to use the quality histogram as a colorbar in my publication. To export it along with labels for publication, I tried just taking a snapshot with the appropriate tool, but if I use alpha/ solid white background the text/ colorbars is not visible. If I use the solid black or meshlab background, the text is white, or can not be used directly in publication.
My questions are as follows:
I know how to change the text color on meshlab window. Is there a similar function to change the text font size on meshlab window?
As a more demanding question, is there a way I can import the quality map file into matlab or some other software, and plot a custom colorbar. I will append my .qmap file here, but it seems that the color field is empty, and I can not reproduce the colors without them.
%%%%%QMAP FILE TO FOLLOW%%%%%
// COLOR BAND FILE STRUCTURE - first row: RED CHANNEL DATA - second row GREEN CHANNEL DATA - third row: BLUE CHANNEL DATA
// CHANNEL DATA STRUCTURE - the channel structure is grouped in many triples. The items of each triple represent respectively: X VALUE, Y_LOWER VALUE, Y_UPPER VALUE of each node-key of the transfer function
0;0.5;0.125;1;0.375;1;0.625;0;0.875;0;1;0;
0;0;0.125;0;0.375;1;0.625;1;0.875;0;1;0;
0;0;0.125;0;0.375;0;0.625;1;0.875;1;1;0.5;
//THE FOLLOWING 4 VALUES REPRESENT EQUALIZER SETTINGS - the first and the third values represent respectively the minimum and the maximum quality values used in histogram, the second one represent the position (in percentage) of the middle quality, and the last one represent the level of brightness as a floating point number (0 copletely dark, 1 original brightness, 2 completely white)
-0.001;0.714286;0.0004;1;

How Do I Keep Bar Width the Same Across Multiple Charts?

Suppose I want to create two charts with horizontal bars. The names of the objects are listed on the y-axis and the horizontal bars represents some quantity. The first chart has 100 items and the second chart has 5 items.
When I create the charts the horizontal bars have different widths. I'd like the bars to be the same width across all of my charts.
I know I can try different values for the height parameter to the AddShape function. But that seems time-consuming and unreliable since the number of items can change. I'd like to do something like:
Chart.BarWidth = 10
The "thickness" of each bar will be primarily determined by the number of data points that need to be plotted. The more data points to plot, the thinner the bars will be. There are some options to further tweak them, such as IChartGroup.GapWidth, and you're welcome to try to adjust this so that both charts match. But I suspect that it will be very difficult to do this reliably, particularly if the number of plotted points is expected to change over time.
To maintain the same bar thickness for multiple charts, I think your best option will be to ensure both charts' series refer to the same size range. So if your first chart refers to 100 cells, have your second chart refer to 100 cells, even if only 5 are populated with values. The empty cells should not plot but will still take up space and therefore maintain consistent bar thicknesses between your two charts.

Plot an array into bitmap in C/C++ for thermal printer

I am trying to accomplish something a bit backwards from everyone else. Given an array of sensor data, I wish to print a graph plot of it. My test bench uses a stepper motor to move the input shaft of a sensor, stop, get ADC value of sensor's voltage, repeat.
My current version 0.9 bench does not have a graphical output. The proper end solution will. Currently, I have 35 data points, and I'm looking to get 90 to 100. The results are simply stored in an int array. The index is linear, so it's not a complicated plot, but I'm having problems conceptualizing the plot from bottom-left to top-right to display to the operator. I figure on the TFT screen, I can literally translate an origin and then draw lines from point to point...
Worse, I want to also print out this to a thermal printer, so I'll need to translate this into a sub-384 pixel wide graph. I'm not too worried about the semantics of communicating the image to the printer, but how to convert the array to an image.
It gets better: I'm doing this on an Arduino Mega, so the libraries aren't very robust. At least it has a lot of RAM for the code. :/
Here's an example of when I take my data from the Arduino test and feed it into Excel. I'm not looking for color, but I'd like the graph to appear and this setup not be connected to a computer. Or the network. This is the ESC/POS printer, btw.
The algorithm for this took three main stages:
1) Translate the Y from top left to bottom left.
2) Break up the X into word:bit values.
3) Use Bresenham's algorithm to draw lines between the points. And then figure out how to make the line thicker.
For my exact case, the target bitmap is 384x384, so requires 19k of SRAM to store in memory. I had to ditch the "lame" Arduino Mega and upgrade to the ChipKIT uC32 to pull this off, 32k of RAM, 80 MHz cpu, & twice the I/O!
The way I figured out this was to base my logic on Adafruit's Thermal library for Arduino. In their examples, they include how to convert a 1-bit bitmap into a static array for printing. I used their GFX library to implement the setXY function as well as their GFX Bresenham's algorithm to draw lines between (X,Y)s using my setXY().
It all boiled down to the code in this function I wrote:
// *bitmap is global or class member pointer to byte array of size 384/8*384
// bytesPerRow is 384/8
void setXY(int x, int y) {
// integer divide by 8 (/8) because array size is byte or char
int xByte = x/8;
// modulus 8 (%8) to get the bit to set
uint8_t shifty = x%8;
// right shift because we start from the LEFT
int xVal = 0x80 >> shifty;
// inverts Y from bottom to start of array
int yRow = yMax - y;
// Get the actual byte in the array to manipulate
int offset = yRow*bytesPerRow + xByte;
// Use logical OR in case there is other data in the bitmap,
// such as a frame or a grid
*(bitmap+offset)|=xVal;
}
The big point is to remember with an array, we are starting at the top left of the bitmap, going right across the row, then down one Y row and repeating. The gotchya's are in translating the X into the word:bit combo. You've got to shift from the left (sort-of like translating the Y backwards). Another gotchya is one-off error in bookkeeping for the Y.
I put all of this in a class, which helped prevent me from making one big function to do it all and through better design made the implementation easier than I thought it would be.
Pic of the printout:
Write-up of the project is here.

Resources