Still, I will need the variable "st" not only in Alert, but also for calculations, and when compiling the warning "possible data loss due to type conversion" comes out.
I assume this is because it turns out to be a 10-digit number, while the maximum value in int is 2 147 483 647, I currently have 1 380 758 400. Maybe it makes sense to use long, and probably the Expert Advisor will consume a lot of resources in this part?
Don't you understand the principle of type conversion? It's that simple:
I want to draw on canvas. To have a picture on canvas redrawn in OnInit, OnTimer, OnTick and in onChartEvent. I declare CCanvas canvas in global variables and call canvas.methods everywhere I want. But the compiler complains about unresolved static variable 'CCanvas::m_default_colors' (what does that have to do with colors?)
the code is like this
#include <Canvas\Canvas.mqh>
CCanvas canvas;
int OnInit() { //CCanvas canvas; if I declare it here, it draws but then how do I redraw it in OnTick?
I want to draw on canvas in Expert Advisor. I want the image on canvas to be redrawn in OnInit, OnTimer, OnTick and in onChartEvent. I declare CCanvas canvas in global variables and call canvas.methods everywhere I want. But the compiler complains about unresolved global declaration
...
How do you negotiate with the compiler? Is there an example with canvas in EA?
Well you are not a beginner! Publish the code correctly!
Well you're not a beginner! Publish the code correctly!
The code is right here. But it's a lot worse to dig into. And it doesn't work either. Error unresolved static variable 'CCanvas::m_default_colors' ProbeGraph.mq5 21 9
And a heap of warrants about overlapping heigth and width variables. As far as I understand, the compiler doesn't want to call CCanvas class constructor in global variables, but wants to call the constructor at OnInit. And then how to refer to an instance of the class outside of OnInit, I do not understand.
Also. Before, the body of the Draw function was inside onInit, but the Draw itself wasn't. Everything worked, but inside OnInit. I've already started to twist here, trying to pass a reference to an instance of the class into the Draw function, because global variables don't work.
In general, the code is being written, the problem with creating a global instance of the CCanvas class.
//+------------------------------------------------------------------+//| ProbeGraph.mq5 |//| Copyright 2013, MetaQuotes Software Corp. |//| http://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2013, MetaQuotes Software Corp."#property link"http://www.mql5.com"#property version"1.00"#include <Canvas\Canvas.mqh>
int heigth=500;
int width=500;
int Xcentr=round(width/2);
int Ycentr=round(width/2);
int Rmin=25;
int Rmax=round(heigth/2-1);
#define ArrayS 100000double arrayopen[ArrayS];
CCanvas canvas;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//CCanvas canvas;
canvas.CreateBitmapLabel("ProbeGraph",0,0,width,heigth,COLOR_FORMAT_ARGB_RAW);
//Draw(canvas);//--- create timerEventSetTimer(60);
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//--- destroy timerEventKillTimer();
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---//canvas.Update();
}
//+------------------------------------------------------------------+//| Timer function |//+------------------------------------------------------------------+voidOnTimer()
{
//---
}
//+------------------------------------------------------------------+//| ChartEvent function |//+------------------------------------------------------------------+voidOnChartEvent(constint id,
constlong &lparam,
constdouble &dparam,
conststring &sparam)
{
//---
}
//+------------------------------------------------------------------+int ChartVisibleBars(constlong chart_ID=0)
{
//--- подготовим переменную для получения значения свойстваlong result=-1;
//--- сбросим значение ошибкиResetLastError();
//--- получим значение свойстваif(!ChartGetInteger(chart_ID,CHART_VISIBLE_BARS,0,result))
{
//--- выведем сообщение об ошибке в журнал "Эксперты"Print(__FUNCTION__+", Error Code = ",GetLastError());
}
//--- вернем значение свойства графикаreturn((int)result);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+void Draw(CCanvas *canvas)
{
ArrayInitialize(arrayopen,0);
double r;
double A, Amin=0, Amax=2*3.1415;
int x,y, xprev=0, yprev=0;
//canvas.Erase(ColorToARGB(clrRed, 115));
canvas.Circle(Xcentr,Ycentr,Rmin,ColorToARGB(clrBlue, 115));
canvas.Circle(Xcentr,Ycentr,Rmax,ColorToARGB(clrBlue, 115));
int Nbars=CopyOpen(Symbol(),Period(),TimeCurrent(),ChartVisibleBars(0),arrayopen); Print("Nbars=",Nbars);
double KursMin=1000000,KursMax=0;
for(int i=0; i<Nbars; i++)
{
if(KursMin>arrayopen[i]) KursMin=arrayopen[i];
if(KursMax<arrayopen[i]) KursMax=arrayopen[i];
};
Print("KursMin=",KursMin); Print("KurMax=",KursMax);
for(int i=0; i<Nbars; i++)
{
if((KursMax-KursMin)>0) r=Rmin+(Rmax-Rmin)*(arrayopen[i]-KursMin)/(KursMax-KursMin);
if(Nbars>0) A=Amin+(Amax-Amin)*i/(Nbars);
x=round(Xcentr-r*MathSin(A));
y=round(Ycentr+r*MathCos(A));
canvas.PixelSetAA(x,y,ColorToARGB(clrGreen,155));
if(xprev>0 && yprev>0) canvas.Line(xprev,yprev,x,y,ColorToARGB(clrBlue,155));
xprev=x; yprev=y;
};
canvas.Update();
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Still, I will need the variable "st" not only in Alert, but also for calculations, and when compiling the warning "possible data loss due to type conversion" comes out.
I assume this is because it turns out to be a 10-digit number, while the maximum value in int is 2 147 483 647, I currently have 1 380 758 400. Maybe it makes sense to use long, and probably the Expert Advisor will consume a lot of resources in this part?
Don't you understand the principle of type conversion? It's that simple:
I want to draw on canvas. To have a picture on canvas redrawn in OnInit, OnTimer, OnTick and in onChartEvent. I declare CCanvas canvas in global variables and call canvas.methods everywhere I want. But the compiler complains about unresolved static variable 'CCanvas::m_default_colors' (what does that have to do with colors?)
the code is like this
#include <Canvas\Canvas.mqh>
CCanvas canvas;
int OnInit()
{
//CCanvas canvas; if I declare it here, it draws but then how do I redraw it in OnTick?
canvas.CreateBitmapLabel("ProbeGraph", 0, 0, width ,heigth, COLOR_FORMAT_ARGB_RAW);
canvas.Circle(Xcentr,Ycentr,Rmin,ColorToARGB(clrBlue, 115)); canvas.Update();
}
void OnTick()
How do I negotiate with the compiler? Is there an example with canvas in expert?{
canvas.Circle(Xcentr,Ycentr,Rmin,ColorToARGB(clrBlue, 115)); canvas.Update();
}
I want to draw on canvas in Expert Advisor. I want the image on canvas to be redrawn in OnInit, OnTimer, OnTick and in onChartEvent. I declare CCanvas canvas in global variables and call canvas.methods everywhere I want. But the compiler complains about unresolved global declaration
...
How do you negotiate with the compiler? Is there an example with canvas in EA?Well you are not a beginner! Publish the code correctly!
Well you're not a beginner! Publish the code correctly!
The code is right here. But it's a lot worse to dig into. And it doesn't work either. Error unresolved static variable 'CCanvas::m_default_colors' ProbeGraph.mq5 21 9
And a heap of warrants about overlapping heigth and width variables. As far as I understand, the compiler doesn't want to call CCanvas class constructor in global variables, but wants to call the constructor at OnInit. And then how to refer to an instance of the class outside of OnInit, I do not understand.
Also. Before, the body of the Draw function was inside onInit, but the Draw itself wasn't. Everything worked, but inside OnInit. I've already started to twist here, trying to pass a reference to an instance of the class into the Draw function, because global variables don't work.
In general, the code is being written, the problem with creating a global instance of the CCanvas class.
One thing I can't understand: if the compiler swears, why aren't the errors corrected? А?
One thing I can't understand: if the compiler swears, why aren't the errors corrected? А?
Copied suggested code completely. The error is the same as unresolved static variable 'CCanvas::m_default_colors' prob1.mq5 21 9
I don't have any errors. The build is the latest.
Copied the suggested code in full. The error is the same as the unresolved static variable 'CCanvas::m_default_colors' prob1.mq5 21 9