• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 1:03pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 1:03pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

I Will Learn Coding in 1 Month - Give me the 80/20 of MT4 Coding 14 replies

Need Coding Help for MT4 Indicator 5 replies

Coding Help Needed: Please Add Email Alerts to MT4 Indicator 0 replies

Help! Assist coding SIROC indicator for MT4 0 replies

Need Help Coding an Indicator MT4 6 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 8
Attachments: MT4 coding help
Exit Attachments
Tags: MT4 coding help
Cancel

MT4 coding help

  • Last Post
  •  
  • Page 1 2
  • Page 1 2
  •  
  • Post #1
  • Quote
  • First Post: Jan 12, 2008 9:38pm Jan 12, 2008 9:38pm
  •  CFII
  • | Joined May 2006 | Status: Member | 47 Posts
Hello,

How would you get the open and close price for a given period of time? Is there a function in MT4 that does this?

For example, the open price at 1200 GMT and the close price at 1700 GMT. This info would then be used to calculate the the difference between the open and close price for that period of time.

thanks,

CFII
Attitude + Power = Performance
  • Post #2
  • Quote
  • Jan 12, 2008 9:59pm Jan 12, 2008 9:59pm
  •  luxinterior
  • | Joined Nov 2006 | Status: MT4 EA Coder Since 2006 | 300 Posts
Take a look at the MQL help file and the iOpen and iClose functions.

Lux
MT4 EA, Indicator and Alert Coder Since 2006
 
 
  • Post #3
  • Quote
  • Jan 13, 2008 8:32pm Jan 13, 2008 8:32pm
  •  CFII
  • | Joined May 2006 | Status: Member | 47 Posts
Quoting luxinterior
Disliked
Take a look at the MQL help file and the iOpen and iClose functions.

Lux
Ignored
I checked out the iOpen and iClose functions. From what I read it gives the Open or Close price for the bar set by the index parameter (index of 3 gives the price 3 bars ago).

Since a bar at specific time ie. 1200 is not always the same number of bars away from the current bar (0), I'm not sure how to code the function to give the open or close price for a bar at a given time.

I am very new to learning MQL so any help would be appreciated.

thanks,

CFII
Attitude + Power = Performance
 
 
  • Post #4
  • Quote
  • Jan 13, 2008 9:07pm Jan 13, 2008 9:07pm
  •  luxinterior
  • | Joined Nov 2006 | Status: MT4 EA Coder Since 2006 | 300 Posts
Take a look at a few source codes for any of the indicators you have and you'll get the idea. Also take a look at the Time[] array in the mql help file. It takes a little bit of time to study the code and check the help file but it's worth it and will help you become a better coder.

Good luck

Lux
MT4 EA, Indicator and Alert Coder Since 2006
 
 
  • Post #5
  • Quote
  • Jan 14, 2008 9:31am Jan 14, 2008 9:31am
  •  CFII
  • | Joined May 2006 | Status: Member | 47 Posts
Quoting luxinterior
Disliked
Take a look at a few source codes for any of the indicators you have and you'll get the idea. Also take a look at the Time[] array in the mql help file. It takes a little bit of time to study the code and check the help file but it's worth it and will help you become a better coder.

Good luck

Lux
Ignored
Would it be to much trouble to specify a particular indicator that uses the iOpen or iClose functions that I could look at? I checked all the indicators installed on my MT4 and didn't see any.
Attitude + Power = Performance
 
 
  • Post #6
  • Quote
  • Jan 14, 2008 4:16pm Jan 14, 2008 4:16pm
  •  nealc99
  • | Joined Jan 2008 | Status: Member | 292 Posts
MT4 Coding HELP!!!!

Pulling my hair out!!! (what little I have)

Trying to develop a routine that will determine what the top of the next hour is (in back testing).

EXAMPLE:

If a trade exits at 21:03 I want to trigger another trade to be entered at the top of the next hour (22:00).

The normal DateTime functions are of no value because they go by the CURRENT server time and is useless for back testing. Also tried iTime() but didn't have any luck with it as well.

PHP Code
 // if there are no current orders active
   
if(OrderSelect(0, SELECT_BY_POS)==false)
   {
// this is using the DateTime functions (which I know don't work)
// output of the routine will be a STRING formated as "HH:MM" (i.e. 22:00)
      
string a = TimeToStr(iTime(NULL,1,0));
      
string b = StringSubstr(a,0,2);
      
int c = StrToDouble(b)+1;
      
string d = DoubleToStr(c,0);
      
string e = d+":00";
      
StartTime = StrToTime(e);
     } 
Any suggestions would be welcome. Keep in mind this needs to work for BACK TESTING
 
 
  • Post #7
  • Quote
  • Jan 15, 2008 6:29am Jan 15, 2008 6:29am
  •  CFII
  • | Joined May 2006 | Status: Member | 47 Posts
Quoting nealc99
Disliked
MT4 Coding HELP!!!!

Pulling my hair out!!! (what little I have)

Trying to develop a routine that will determine what the top of the next hour is (in back testing).

EXAMPLE:

If a trade exits at 21:03 I want to trigger another trade to be entered at the top of the next hour (22:00).

The normal DateTime functions are of no value because they go by the CURRENT server time and is useless for back testing. Also tried iTime() but didn't have any luck with it as well.

PHP Code
 // if there are no current orders active
   
if(OrderSelect(0, SELECT_BY_POS)==false)
   {
// this is using the DateTime functions (which I know don't work)
// output of the routine will be a STRING formated as "HH:MM" (i.e. 22:00)
      
string a = TimeToStr(iTime(NULL,1,0));
      
string b = StringSubstr(a,0,2);
      
int c = StrToDouble(b)+1;
      
string d = DoubleToStr(c,0);
      
string e = d+":00";
      
StartTime = StrToTime(e);
     } 
Any suggestions would be welcome. Keep in mind this needs to work for BACK TESTING
Ignored
You may want to start a new thread for your question instead of posting in an existing thread that has nothing to do with your problem.

regards,

CFII
Attitude + Power = Performance
 
 
  • Post #8
  • Quote
  • Jan 15, 2008 8:07am Jan 15, 2008 8:07am
  •  magnumfreak
  • Joined Nov 2007 | Status: Trying manual mode again | 2,210 Posts
Quoting CFII
Disliked
Hello,

How would you get the open and close price for a given period of time? Is there a function in MT4 that does this?

For example, the open price at 1200 GMT and the close price at 1700 GMT. This info would then be used to calculate the the difference between the open and close price for that period of time.

thanks,

CFII
Ignored
you could write a loop that will go back and check the time for each candle.

TimeHour(Time[x]) will return the hour of the particular candle and
TimeMinute(Time[x]) will return the minute of the particular candle.

if the hour and minute meet your criteria then grab either the open or close for that value of x by using Open[x] or Close[x].

Hope this helps.
 
 
  • Post #9
  • Quote
  • Jan 15, 2008 8:11am Jan 15, 2008 8:11am
  •  magnumfreak
  • Joined Nov 2007 | Status: Trying manual mode again | 2,210 Posts
In my example above the TimeHour and TimeMinute functions will return an integer value that you can check against when the last trade closed. So by your example, if the trade closed at 21:03 you would check for the hour (21) and then wait for the current candle time to equal that value plus one and the minutes be at 00.

Make sense?



Quoting nealc99
Disliked
MT4 Coding HELP!!!!

Pulling my hair out!!! (what little I have)

Trying to develop a routine that will determine what the top of the next hour is (in back testing).

EXAMPLE:

If a trade exits at 21:03 I want to trigger another trade to be entered at the top of the next hour (22:00).

The normal DateTime functions are of no value because they go by the CURRENT server time and is useless for back testing. Also tried iTime() but didn't have any luck with it as well.

PHP Code
 // if there are no current orders active
   
if(OrderSelect(0, SELECT_BY_POS)==false)
   {
// this is using the DateTime functions (which I know don't work)
// output of the routine will be a STRING formated as "HH:MM" (i.e. 22:00)
      
string a = TimeToStr(iTime(NULL,1,0));
      
string b = StringSubstr(a,0,2);
      
int c = StrToDouble(b)+1;
      
string d = DoubleToStr(c,0);
      
string e = d+":00";
      
StartTime = StrToTime(e);
     } 
Any suggestions would be welcome. Keep in mind this needs to work for BACK TESTING
Ignored
 
 
  • Post #10
  • Quote
  • Jan 15, 2008 8:55am Jan 15, 2008 8:55am
  •  nealc99
  • | Joined Jan 2008 | Status: Member | 292 Posts
Quoting magnumfreak
Disliked
you could write a loop that will go back and check the time for each candle.

TimeHour(Time[x]) will return the hour of the particular candle and
TimeMinute(Time[x]) will return the minute of the particular candle.

if the hour and minute meet your criteria then grab either the open or close for that value of x by using Open[x] or Close[x].

Hope this helps.
Ignored
Looks like it might do what is needed - will give it a try.

Thanks a lot!
Neal
 
 
  • Post #11
  • Quote
  • Jan 16, 2008 8:38am Jan 16, 2008 8:38am
  •  CFII
  • | Joined May 2006 | Status: Member | 47 Posts
Quoting magnumfreak
Disliked
you could write a loop that will go back and check the time for each candle.

TimeHour(Time[x]) will return the hour of the particular candle and
TimeMinute(Time[x]) will return the minute of the particular candle.

if the hour and minute meet your criteria then grab either the open or close for that value of x by using Open[x] or Close[x].

Hope this helps.
Ignored
Thanks magnumfreak. I will give that a try.

CFII
Attitude + Power = Performance
 
 
  • Post #12
  • Quote
  • May 18, 2012 11:03am May 18, 2012 11:03am
  •  abma129
  • | Joined Jan 2010 | Status: abma129 | 6 Posts
Hello sir,
can you help me, with this indicator which i attached,
actually this indicator show 4 dicimal in data window, ist possible to change 5 dicimal

abma
Attached File(s)
File Type: mq4 Donchian Channels_middle_line.mq4   3 KB | 208 downloads
 
 
  • Post #13
  • Quote
  • Aug 6, 2014 1:31pm Aug 6, 2014 1:31pm
  •  Chistabo
  • | Joined Apr 2009 | Status: Member | 191 Posts
Coding help!

Hi, can one of you that is versed with mt4 coding please re-code attached script, since after MT4 (evil LOL) build 600 it does not work anymore! Plots data/vertical line, but they are somehow corrupted.
This script is supposed to read .csv file and plot vertical line on chart. Csv file should be in classical MT4 format:
yyyy.mm.dd hh:mm, text (any text to plot on vertical line)
I have also attached example .csv file.

Thank you for your cooperation,

Pips with you,

Simon
Attached File(s)
File Type: mq4 PlotVLineScriptChi Aspect.mq4   4 KB | 174 downloads
File Type: csv PlotDataChiAspects.csv   14 KB | 176 downloads
 
 
  • Post #14
  • Quote
  • Edited 5:14pm Aug 6, 2014 3:35pm | Edited 5:14pm
  •  marktaylorza
  • | Joined Aug 2014 | Status: Junior Member | 3 Posts
Good day,

I have an indicator that I am trying to convert from mq4 to mq5.
Can you assist with conversions from MetaTrader 4 to 5 or refer me to the correct forum.

Regards,

Mark
 
 
  • Post #15
  • Quote
  • Aug 6, 2014 7:30pm Aug 6, 2014 7:30pm
  •  Gumrai
  • Joined Oct 2012 | Status: Member | 1,959 Posts
Quoting Chistabo
Disliked
Coding help! Hi, can one of you that is versed with mt4 coding please re-code attached script, since after MT4 (evil LOL) build 600 it does not work anymore! Plots data/vertical line, but they are somehow corrupted. This script is supposed to read .csv file and plot vertical line on chart. Csv file should be in classical MT4 format: yyyy.mm.dd hh:mm, text (any text to plot on vertical line) I have also attached example .csv file. Thank you for your cooperation, Pips with you, Simon {file} {file}
Ignored

Hi Christabo,
I haven't examined the rest of the code, but FileOpen is expecting a string.
handle = FileOpen (PlotDataChiAspects.csv, FILE_CSV|FILE_READ, ',');
try adding quotation marks
handle = FileOpen ("PlotDataChiAspects.csv", FILE_CSV|FILE_READ, ',');
Please Do Not PM Me With Coding Enquiries
 
 
  • Post #16
  • Quote
  • Aug 6, 2014 10:53pm Aug 6, 2014 10:53pm
  •  Gumrai
  • Joined Oct 2012 | Status: Member | 1,959 Posts
Hi again Christabo,
I had a look at the code and it all seems ok.
Seems that the problem is with the file it is reading. Maybe it was written using quotation marks where none were needed?
I have modified and attached the file for you to try.
Note that unless you change the file name, you will need to change it in the code
handle = FileOpen ("ModifiedPlotDataChiAspects.csv", FILE_CSV|FILE_READ, ',');

I hope that this works for you
Attached File(s)
File Type: csv ModifiedPlotDataChiAspects.csv   13 KB | 181 downloads
Please Do Not PM Me With Coding Enquiries
 
 
  • Post #17
  • Quote
  • Aug 7, 2014 5:52pm Aug 7, 2014 5:52pm
  •  Chistabo
  • | Joined Apr 2009 | Status: Member | 191 Posts
Hi Gumrai, thank you for help.
There are no double quote characters in original .csv file - why they do appear on MT4 chart objects is a mystery to me! And a source of problem.
Yes, attached PlotVLine...mq4 is missing double quotes at
handle = FileOpen (PlotDataChiAspects.csv, FILE_CSV|FILE_READ, ',');
I guess I forgot to put those double quotes back after (&/%#!!Cf$") testing. LOL!

Your attached file "ModifiedPlotDataChiAspects.csv" did not resolve the problem - although data was put into 2 columns, when you save as .csv, it is actually 'put together', so to speak, and delimited with comma (comma separated value - csv).
I did my homework, asked uncle Google about the problem, can not resolve this. Arghhhh! LOL. Though on the go I added external user selectable inputs for line color, text color and line style (TO DO - get rid of double quotes, and user selectable timeframe).

Thanks again,

Best regards,

Simon
 
 
  • Post #18
  • Quote
  • Aug 7, 2014 9:07pm Aug 7, 2014 9:07pm
  •  Chistabo
  • | Joined Apr 2009 | Status: Member | 191 Posts
FYI, I opened original PlotDataChiAspects.csv with Notepad++, and there were indeed double quotes encapsulating each and every line. So, the problem seem to be Excel, saving .csv files with double quotes. In Notepad++, I did 'Search & Replace', removed all double quotes (") and run the script - voila, problem solved. Pffffffff! MS!

Gumrai, do you perhaps know how can I set external parameter for timeframes to use? That is, when I run the script, I want to be able to select timeframes that I want those vertical lines to be plotted on. I.e. - I want vertical lines to be plot on 1h, 4h, and daily.

Thank you for your cooperation,

Best regards,

Simon
 
 
  • Post #19
  • Quote
  • Aug 7, 2014 9:35pm Aug 7, 2014 9:35pm
  •  Gumrai
  • Joined Oct 2012 | Status: Member | 1,959 Posts
Quoting Chistabo
Disliked
Your attached file "ModifiedPlotDataChiAspects.csv" did not resolve the problem - although data was put into 2 columns, when you save as .csv, it is actually 'put together', so to speak, and delimited with comma (comma separated value - csv).
Ignored
The file works on my platform, maybe the problem is that you "saved as csv"

Quoting Chistabo
Disliked
In Notepad++, I did 'Search & Replace', removed all double quotes (") and run the script - voila, problem solved.
Ignored
That's exactly what I did, so the modified file that I attached would/should have worked if you made no adjustments.
Definitely wierd though.
Please Do Not PM Me With Coding Enquiries
 
 
  • Post #20
  • Quote
  • Aug 7, 2014 10:35pm Aug 7, 2014 10:35pm
  •  Chistabo
  • | Joined Apr 2009 | Status: Member | 191 Posts
Attached is upgraded script:
- you can select file to open/plot
- you can set name to all plotted data (vertical line & text), so it can be easily deleted later (CTRL+B, left-click on Name tab, select & delete)
- you can select color and style of vertical line
- you can select color of text
- you can choose to show or not the text

See 'About' tab if you are not familiar with line style code.

Now I need to figure out how to plot the data on selected timeframes.

Best regards,

Simon
Attached File(s)
File Type: mq4 PlotVLineScriptChi.mq4   5 KB | 156 downloads
 
 
  • Platform Tech
  • /
  • MT4 coding help
  • Reply to Thread
    • Page 1 2
    • Page 1 2
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023