Draw vertical lines on every crossover in an EA
I found a problem with the dimensions of the array, but critically the problem of drawing only the latest vline is that the names were not unique.
This fixed the problem for me:
string name = "L" + IntegerToString(i); // ObjectCreate(0, name, OBJ_VLINE, 0, TimeLong,0 ); //labels at the bottom ObjectCreate(0,name, OBJ_TRENDBYANGLE, 0, TimeLong, 0, TimeLong, 1); //only lines
#include <ChartObjects\ChartObjectsLines.mqh> //---we include the meta quotes header (mqh) file from the Include folder CChartObjectVLine vline[]; //---and declare a dynamic array of the class that works with vlines int vline_number = 5; //---how many lines do we want for demonstration? int OnInit() { //--- for(int i = 0; i < vline_number; i++) { ArrayResize(vline, i + 1); // We create an array of vline obects so we can call them by index and not by name. // the names are stored in the lines on the chart //--- so this is how the class methods(functions) are calles. //--- You can look at the methods in the in the CChartObjects base class in the ChartObjects.mqh vline[i].Create(0, "my_vline_" + string(i), 0, iTime(_Symbol, _Period, (7 * i))); vline[i].Width(3); //changing values like this is way more convenient, right? vline[i].Color(clrBlue); } //--- return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { }
And it is a nice first look at object oriented programming.
'
A totally different thing is that there will be crossovers coming and going between two most recent bars because the most recent bar isn't fully developed yet.
I higly recommend you to look into the CChartObjectsVline class for this, it wraps the functions of Vlines into a much simpler form.
And it is a nice first look at object oriented programming.
'
A totally different thing is that there will be crossovers coming and going between two most recent bars because the most recent bar isn't fully developed yet.
I would like to draw vertical lines for times when a new signal appears in an EA. Signals can be of several natures and are returned by an independent function, but for simplicity lets say a signal is simply the Price close crossover an EMA.
Using a command like:
I managed to create a vertical line only on the latest signal. As any new signal appears, all prior Vlines disappear.
Looking over an old POST, I noted that one may have to update the positions of all vertical lines each new candle. The problem with that post, is that it re-runs all the calculations at each new candle, which appears inefficient.
So my solution was to create an array of datetime and store the time each new signal appears, and then loop over that array to place vertical lines over the time of all prior signals. However, the lines do not deploy and I get a warning saying " array out of range in 'BBOnly.mq5' (40,60)". Any thought what could be wrong, or is there any other way to place such vlines on all crossovers in an EA?
Here is a simplified version of the code: