I have a code task? help please :)

 

Hi all pro coders,

Im Phong & a newbie  to MQL4. Im learning :)

The problem is that Im trying to code a simple horizontal line on mainwindow & It gets value from Input properties, when the tick comes the code will check if I move the line to new position & obtain new value. So when i change timframe the horizontal line will not be set as input value anymore, it should be kept at new value.

Could anyone show me the ideas to do that! or Functions to research/ codes ...???

Simple lines of code im trying...:/


I would be very grateful :)

Thanks all

Phong,

Sharing is Caring!

 

In OnInit:

if(ObjectFind(the line)<0) ObjectCreate(the line);

In OnDeinit:

if(reason==REASON_REMOVE || reason==REASON_TEMPLATE) ObjectDelete(the line);
 
kypa:

In OnInit:

In OnDeinit:

Great! Thanks a lot Kypa :))

have a good day!

 
kypa:

In OnInit:

In OnDeinit:

Hey KyPa! how are you?

seems like I hit a brick wall! :/ Could you please help me!
I notice that the global variable i declared (below is "lastalert") cant store data throughout the operating. Whenever I change chart timeframe, It is set as default again so I cant use the previous data that i stored in the variable "lastalert".

Is there any way to store data throughtout operating & the data will not be reset as default untill removing the indicator???

Here are the codes describing the problem:

------------------------------
#property strict
#property indicator_chart_window
extern bool Indicator_On = true;
extern double mlevel;
datetime lastalert;

int OnInit()
{
return(INIT_SUCCEEDED);
}
int start()
{
if ((Bid > mlevel) && (mlevel>0)) 
{
if ((TimeCurrent()-lastalert)>= 10*60 )// next alert at >= 10 min from the previous one.

PlaySound("alert.wav");
lastalert = TimeCurrent();
Comment ("Last Alert at " + (string)lastalert + " -- Price is above the level "+(string)mlevel);
}

return(0);
}

 

You can use this (the proper way):

https://www.mql5.com/en/docs/globals

Or some arrow object whose name is your variable (workaround) and is not deleted until expert remove (the code from last problem).

Also this:

https://www.mql5.com/en/docs/files

but it would probably be too much disk reads and writes.

I'm not sure of disk usage of GVCT, arrow workaround works mostly in ram.

Documentation on MQL5: Global Variables of the Terminal
Documentation on MQL5: Global Variables of the Terminal
  • www.mql5.com
Global variables are kept in the client terminal for 4 weeks since the last access, then they will be deleted automatically. An access to a global variable is not only setting of a new value, but reading of the global variable value, as well.
 
  1. @aphong Please don't post image of code. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your posts.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. if ((TimeCurrent()-lastalert)>= 10*60 )// next alert at >= 60 min from the previous one.
    600 is not 60 min.


 
kypa:

You can use this (the proper way):

https://www.mql5.com/en/docs/globals

Or some arrow object whose name is your variable (workaround) and is not deleted until expert remove (the code from last problem).

Also this:

https://www.mql5.com/en/docs/files

but it would probably be too much disk reads and writes.

I'm not sure of disk usage of GVCT, arrow workaround works mostly in ram.

Thanks Kypa,

I got it! :)

Good weekends.

 
whroeder1:
  1. @aphong Please don't post image of code. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your posts.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. 600 is not 60 min.


Thanks a lot Whroder1,

I guess you/someone else will give me  amazing tips on mql5 site :)

Thank you so much!

Have a good weekend!

Reason: