No need to attach the chart before using it.
i thought i needed that because my background color statement ( ch.ColorBackground(clrBeige); ) has no effect.
Must be missing something.
See this example: https://www.mql5.com/en/code/877
- votes: 8
- 2012.04.16
- Karlis Balcers
- www.mql5.com
By the way, how do you execute a script from an ea, like the one you showed https://www.mql5.com/en/code/877.
I downloaded it, then what ?
- votes: 8
- 2012.04.16
- Karlis Balcers
- www.mql5.com
From MetaEditor compile it first, then click on the Red button to run the script.
Found the reason:
The CChart variable mustn't be declared inside OnInit(). Probably on leaving OnInit(), the CChart instance is killed (which is right since it leaves the local scope) and so it closes the chart.
When declaring the variable outside, it works:
CChart ch; int OnInit() { ch.Attach(); ch.ColorBackground(clrBeige); return(0); }Or you do a Detach() after all insider OnInit().
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm a total newbie to mql5. And started playing with it.
Basically I want to modify the color of the price chart via the CCHart class.
It compiles with no errors or warnings. But it crashes as soon as I run the program
This is my code, it seems to crash on my attach function.
If I leave that out, no crash.
Thanks
int OnInit()
{
CChart ch;
ch.Attach();
ch.ColorBackground(clrBeige);
return(0);
}