Opening a CChart object in an EA?? How does that work?? Is there more documentation???

 

I have been trying to open a chart (CChart) during the "int OnInit()" phase of my EA. It doesn't work. I tried using the old MT4, non object oriented, version of this function, ChartOpen, and still no joy. I get an error ID. I can't find any more documentation or example code on this anywhere. This should be a fundamental function for this kind of platform so I would think there should be more information on the subject.


I am a long time C++, Java, Object Oriented software engineer. I have been evaluating this platform for over a year, trying to get it to do some basic trading. I am not a noob by any means. I don't get how this platform can be taken seriously. WHAT am I missing here!!!!

 

Where is the code? 

long chartID = ChartOpen(SymbolName(0,1),PERIOD_H1);
 
Marco vd Heijden:

Where is the code? 

Your code is exactly the same as one of my iterations. I figure you don't need my code because I have tried so MANY variations. It is just an EA and I am trying to use ChartOpen in the OnInit() stage.

I was about to use it during the OnTick() function but that seemed a waste of time because I can get a new chart to open by creating an Indicator with a different period than the main chart.

Can we just use ChartOpen(SymbolName(0,1),PERIOD_H1) ANYPLACE we like?? Is it just supposed to work anyplace anytime?? Or is there a secret to it??? Anymore documentation I can read??? Because using it just like you put up there does NOT WORK for me.


I did look through the object oriented lib (CChart object) code and saw that in essence it is still just using ChartOpen. CChart just looks like an OOP wrapper around the old MT4 code.

Documentation on MQL5: Chart Operations / ChartOpen
Documentation on MQL5: Chart Operations / ChartOpen
  • www.mql5.com
Chart Operations / ChartOpen - Reference on algorithmic/automated trading language for MetaTrader 5
 
//+------------------------------------------------------------------+
//|                                                    ChartOpen.mq5 |
//|      Copyright 2020, Marco vd Heijden, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Marco vd Heijden, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

long chartID = ChartOpen(SymbolName(0,1),PERIOD_H1); // this works

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//---
   long chartID = ChartOpen(SymbolName(0,1),PERIOD_H1); // this works
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
   long chartID = ChartOpen(SymbolName(0,1),PERIOD_H1); // this works (upon exit)
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
   long chartID = ChartOpen(SymbolName(0,1),PERIOD_H1); // bad idea
}
//+------------------------------------------------------------------+
I guess you can do that but i personally never use it and i wonder why you would.
 
Marco vd Heijden:
I guess you can do that but i personally never use it and i wonder why you would.
I am setting up a class that does candle chart analysis on a specific period. Each instance will have a different period. I want each instance to contain or have access to its own specific chart in that specific period. In some cases an instance may put an Indicator on the chart so it usually does that during the OnInit() phase. If I had to do it during the OnTick() function, I would just have the instance initialize only once but the way you have it would be a very bad idea.

I will copy your code and try it out, minus the ChartOpen in the OnTick() function. It is simple and if it works, I can work backwards from there.

Thanks!!!
 
Marco vd Heijden:
I guess you can do that but i personally never use it and i wonder why you would.
Nope!!! No joy on that one either.

Is there an issue with running it in the debugger?? I ran it from the MetaEditor and the Strategy Tester Vizualization window only had ONE Chart. It was the 5 min chart set in the Strategy Tester Settings. If it worked, it should have also have added a 1 hr chart from the global declaration and a 3 hr chart from the OnInit() function.

Did you try yours??? Did it work?? Or am I still missing something???
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 

ChartOpen does not work in strategy tester.

You can do lots of function calls where you pass the timeframe as a parameter so that you do not need a chart.

 
Marco vd Heijden:

ChartOpen does not work in strategy tester.

You can do lots of function calls where you pass the timeframe as a parameter so that you do not need a chart.

Whaaaaaaaaaaaaaat!!!? Seriously!!!??? That is completely retarded!

I absolutely need multiple charts. I need them because I annotate them with decisions my EA is making. Each module is like a separate brain that is looking at something specific and I need it to tell me what it is doing. I need it for debugging purposes for my trades. I need to see WHY I may have made a bad trade or a good one. I am just a simple trader and I can hardly see how you can survive with less.


And just the fact that I can accidentally create another chart just by creating an instance of an Indicator with a different period tells me that an MT5 EA should be allowed to open up another chart tab. And the function works when just running as an EA attached to a chart, so it seems extremely inconsistent.

There are so many things about the architecture of MT5 platform that seems contrary to expert trading. It is almost like they want you to fail.


SMH

 

Yes so it's your job to make it work.

There are usually always work arounds but it takes time and effort to make these things work and the real question is if it will be worth the hassle in the end.

For example, you won't see me investing time in anything related to strategy tester, but i will draw complete charts on live feeds even in HTML and Javascript so that i can load them in a browser thereby completely escaping the chart limitations in MetaTrader itself. 

There are always multiple solutions but you have to implement them yourself.
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 
Marco vd Heijden:

Yes so it's your job to make it work.

There are usually always work arounds but it takes time and effort to make these things work and the real question is if it will be worth the hassle in the end.

For example, you won't see me investing time in anything related to strategy tester, but i will draw complete charts on live feeds even in HTML and Javascript so that i can load them in a browser thereby completely escaping the chart limitations in MetaTrader itself. 

There are always multiple solutions but you have to implement them yourself.
Yes, there are many alternatives. I know of many open source libs that can do all kinds of candle charts but I didn't want to reinvent the wheel. But if MetaTrader is that broken, I may as well go the route of writing my own system. Google has some great libraries for doing some kick ass trading features but I would probably need another year of coding time to get where I need to be.

For now I have figured out a coding work around but circuitous route looks so stupid when one line should have worked. It is an obvious and egregious bug.
 
Ok, even the work arounds don't work. It seems that NONE of the Chart functions work in the debugger. NONE of them!!!! How is that possible??? Why would you let the product out like that???
Reason: