CCHart and attach function

 

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);

   

  }

 

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.

 

 

 
ColorChart
ColorChart
  • votes: 8
  • 2012.04.16
  • Karlis Balcers
  • www.mql5.com
Simple script to randomize all colors of your chart. Just click on it and see results yourself!
 

Already had a look at it.

I did start off using setInteger as shown in the article. 

But I want to use the CChart Class instead, since there are other things I want to do but can't seem to  get it going...;(

 

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 ? 


ColorChart
ColorChart
  • votes: 8
  • 2012.04.16
  • Karlis Balcers
  • www.mql5.com
Simple script to randomize all colors of your chart. Just click on it and see results yourself!
 

From MetaEditor compile it first, then click on the Red button to run the script.

 
I mean, how do I attach it to an EA running already.
 

Ok, same problem here.

If i call .Assign() in my EA's OnInit, the chart window immediately closes.

I looked into the CChart.mqh code but the Assign method doesn't do suspicious things. I don't get it.

 

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().