Hi All,
I've created an EA and added drawing objects using the standard library.
In a custom indicator, can you still draw on the main window using the standard library or can you only use the index buffers to draw on the chart?
I've created an indicator but using the standard library, the objects (on this occasion, trend lines) aren't rendering on the chart, despite returning "true" from the Create method.
Thanks.
Yes, you can draw objects on the chart instead of using the buffers. Always check that you are using the correct create method when using the lib because if you accidentally call the Create method for the parent class instead of derived - you will create the wrong chart-object type. Also, make sure that you are adding the object to the correct (sub)window.
Yes, you can draw objects on the chart instead of using the buffers. Always check that you are using the correct create method when using the lib because if you accidentally call the Create method for the parent class instead of derived - you will create the wrong chart-object type. Also, make sure that you are adding the object to the correct (sub)window.
Hi @nicholishen, thanks for the heads-up! :) Here's my code:
//+------------------------------------------------------------------+ //| wwWave.mqh | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //--- #include<ChartObjects\ChartObjectsLines.mqh> #include<gwObjVector.mqh> #include <wwBar.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CWave : public CChartObjectTrend { private: datetime _time1; datetime _time2; double _waveTotal; bool _created; int m_instance; string _name; void _createWave(); //--- CBar *_lastBar; CObjVector<CBar>_bars; public: CWave(datetime time1); ~CWave(); CWave(const CWave &wave); // Copy CWave *operator=(const CWave &wave) { return(GetPointer(this)); } datetime Time1(); datetime Time2(); void Time2(datetime time); void AddBar(CBar *bar); CBar *LastBar(); //--- static int s_instances; }; int CWave::s_instances=0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CWave::~CWave() { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CWave::CWave(datetime time1) : _time1(time1) { m_instance=++s_instances; _name="__WWave__"+string(m_instance)+"__"; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CWave::_createWave() { _created=CChartObjectTrend::Create(0,_name,0,_time1,Close[iBarShift(NULL,0,_time1,true)],_time2,Close[iBarShift(NULL,0,_time2,true)]); if(_created) { this.Width(2); this.Color(clrGray); this.Selectable(true); WindowRedraw(); } else { #ifdef LoggingOn Print("Error: unable to create Wave! Error code #",GetLastError()); #endif } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CWave::CWave(const CWave &wave) { _time1=wave._time1; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ datetime CWave::Time2() { return _time2; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CWave::Time2(datetime time) { _time2=time; _createWave(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CWave::AddBar(CBar *bar) { _bars.Add(bar); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CBar *CWave::LastBar() { return _lastBar; } //+------------------------------------------------------------------+
I'm actually trying to add the trendlines to the main chart window. I can't see the lines drawn, despite the create method returning true, and when I try to expand the bar size in the debug chart window, the screen just locks up and I cant click on it to adjust its properties etc.
Does anything look suspicious to you?
Cheers! --G
Hi @nicholishen, thanks for the heads-up! :) Here's my code:
I'm actually trying to add the trendlines to the main chart window. I can't see the lines drawn, despite the create method returning true, and when I try to expand the bar size in the debug chart window, the screen just locks up and I cant click on it to adjust its properties etc.
Does anything look suspicious to you?
Cheers! --G
You're over-complicating it, and mostly redefining methods already available in the parent... This is all you need.
#include <ChartObjects\ChartObjectsLines.mqh> class CWave : public CChartObjectTrend { protected: int m_instance; static int s_instances; public: CWave(){ m_instance = ++s_instances; } bool Create(datetime time1, double price1, datetime time2, double price2); }; int CWave::s_instances=0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CWave::Create(datetime time1, double price1, datetime time2, double price2) { string name = "__WWave__"+string(m_instance)+"__"; if(!CChartObjectTrend::Create(0,name,0,time1,price1,time2,price2)) return false; this.Width(2); this.Color(clrRed); this.Selectable(true); return true; }
You're over-complicating it, and mostly redefining methods already available in the parent... This is all you need.
Thanks for the critique. Just un-complicated mine! ;)
- 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 All,
I've created an EA and added drawing objects using the standard library.
In a custom indicator, can you still draw on the main window using the standard library or can you only use the index buffers to draw on the chart?
I've created an indicator but using the standard library, the objects (on this occasion, trend lines) aren't rendering on the chart, despite returning "true" from the Create method.
Thanks.