| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Programming question using Close[]
Hello all,
I’m trying the get the Close price of previous to current candle every min using Close[1] function. The first time through the loop I get the correct value and it will display the same value every time after This is my sample code flag =1; int currentTime=0; int initTime = 0; while (flag==1) { currentTime = CurTime(); if (initTime + 60 <= currentTime) { Alert (Close[1]); initTime = CurTime(); } } Now if the Close[1] value is 1.298 it will display it correctly the first time but each time after that it will display the same number and will not get updated with the correct value. Is something wrong with my code? Or Close[] can’t be update more than once through the program? Thanks |
|
|||
|
Thanks, I made some modification to the code. The problem I have is that the first time I get the correct close value of Close[1], However every min after that, I get the same value over and over again, even though the close price changes. How can I modify this code so I can get the new value of Close[1]?
So when you run this code, the first time you get a value 117.21 for USDJPY M1 (of course depends on the market price at the time you run the program). Which is the correct value. A min later the chart shows a new value something like 117.18. However the code below still display the same value as the first time which was 117.21 int start() { int flag =1; while (flag ==1) { if(NewBar())Alert(Close[1]); Sleep (60000); } return(0); } //+------------------------------------------------------------------+ bool NewBar() { static datetime dt = 0; if (CurTime() != dt) { dt = CurTime(); return(true); } return(false); } |
|
|||
|
Sorry I’m very new to this MQL lang.
Are you saying the start() function automatically gets called every time there is a new bar? I tried your code and only got one alert with the price of Close[1] and nothing after that based on M1 interval. The problem I have with Close[1] is, it always give me the correct first value after I execute the program, but it doesn’t give me the new values as they come. It always gives me the value I got when I first executed the program over and over again. The reason for flag = 1 is that I want to start a infinite loop (while flag ==1) and the sleep(60) sleep for 60 sec before look for a new value of Close[1]. One other thing that I do is I call the start from init() function Init() { Start(); Return (0); } Is this wrong way of doing it? Does start() gets call by itself? Thanks |
|
|||
|
The reason you aren't getting the updated prices is because you are running a continuous loop and the platform will not update the arrayconstants until you break the loop and the start() is finished processing or you use the RefreshRates().
Here is an effective alternative: PHP Code:
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Question... | omelette | General Discussion | 6 | 12-12-2006 02:29 AM |
| Question about programming AMA logic into an EA | zeroz | Metatrader 4 mql 4 - Development course | 4 | 12-09-2006 08:13 PM |
| Indicator Programming Question | cubesteak | Indicators - Metatrader 4 | 5 | 08-05-2006 09:25 AM |
| a question on mt4 programming | huaxia009 | Metatrader 4 | 3 | 05-31-2006 03:10 AM |