hii friends, suppose i have a text file with some rabdom numbers only, only one number in each line.
10
500
350
457
1385
57
3987
4532
something like above. I want to copy the second last number. In this case 7th number. Remember we don't know which numbers are there and how many numbers are there. I just want to find the second last number. Any help please...
- Working with Storage - Projects and MQL5 Storage
- Merging changes - Projects and MQL5 Storage
- Moving Average - Trend Indicators - Indicators - Charts - MetaTrader 5 for Android
- If there are a reasonable number of lines (under millions) you can read each line and add to an array and you can access any element.
- Otherwise, just remember the last two.
int last, prev; ⋮ while(…){ prev = last; last = FileReadNumber(h); }
- Or the last n:
int iLast=0, array[]; ArrayResize(array,n); ⋮ while(…) array[--last % n] = FileReadNumber(h); #define prev(i) array[ (last+i) % n ] // last=prev(0)
William Roeder:
- If there are a reasonable number of lines (under millions) you can read each line and add to an array and you can access any element.
- Otherwise, just remember the last two.
- Or the last n:
ok. Now I am just trying to read all the numbers( 1660 numbers) from a csv file and print. But it only printing the last 205 numbers only. what is wrong with me?
//+------------------------------------------------------------------+ //| test1.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //#property strict #property script_show_inputs //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { int FH=FileOpen("file.csv",FILE_CSV|FILE_WRITE|FILE_READ|FILE_SHARE_READ); while(!FileIsEnding(FH)) { double num =FileReadNumber(FH); PrintFormat(num); } FileClose(FH); } //+------------------------------------------------------------------+
Clement Chand C S:
ok. Now I am just trying to read all the numbers( 1660 numbers) from a csv file and print. But it only printing the last 205 numbers only. what is wrong with me?
Please ignore the above post. When I opened log file, all numbers are there. Don't know why most of the numbers are not showing in the experts tab!!.
Anyway thanks for your help friend....
Keith Watford:
ha ha yes dear i just found it.
Check the log for the prints, not just the tab.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register