Currency Info

Post Reply
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Currency Info

Post by gaheitman »

Often when someone starts to use a new EA, there are issues with particular brokers or pairs. Attached is a utility that will dump much of the useful MarketInfo() data for all/many/most/some of the pairs. I say that because I am using two methods to get the list of pairs for reporting. The default is just the majors, ripped indelicately from the Co-integration thread. The second method is from the ForexRobot thread, and reads the data of all pairs from the symbol file and just includes those that are currently in the market watch window.

Very little of the script is my own work, more of a Frankenstein. ;)

The information is displayed on screen and, if the user chooses, copied to the clipboard for pasting into your favourite spreadsheet.

The settings (you will be prompted when you drop the script on a chart):

Code: Select all

extern bool UseForexRobotMethod=false;
extern bool CopyResultsToClipboard=false;
The popup window:
pic_01 2011-12-31 12.22.gif
And the text from the clipboard (it uses tabs to separate columns, so won't look too pretty below):

Code: Select all

Symbol	LotSize	Digits	Bars	Point	MinLot	LotStep	MaxLot	TickVal	TickSize	Spread	StopLvl	Swap Long/Short	Margin	Tradeable
AUDCAD	100000	5	4813	0.00001	0.01	0.01	50.00	0.9818	0.00001	71	0	5.42 | -14.29	2045.64	Yes
AUDCHF	100000	5	4813	0.00001	0.01	0.01	50.00	1.0648	0.00001	83	0	8.15 | -17.93	2045.64	Yes
AUDJPY	100000	3	4813	0.001	0.01	0.01	50.00	1.2994	0.001	62	0	9.10 | -18.33	2045.64	Yes
AUDNZD	100000	5	4813	0.00001	0.01	0.01	50.00	0.7781	0.00001	91	0	1.56 | -8.58	2045.64	Yes
AUDUSD	100000	5	4813	0.00001	0.01	0.01	50.00	1.0000	0.00001	42	0	8.90 | -14.90	2046.06	Yes
CADJPY	100000	3	4813	0.001	0.01	0.01	50.00	1.2994	0.001	57	0	-1.28 | -7.95	1963.18	Yes
CHFJPY	100000	3	3204	0.001	0.01	0.01	50.00	1.2994	0.001	67	0	-4.13 | -4.52	2129.13	Yes
EURAUD	100000	5	4813	0.00001	0.01	0.01	50.00	1.0226	0.00001	82	0	-19.52 | 11.30	2588.37	Yes
EURCAD	100000	5	3766	0.00001	0.01	0.01	50.00	0.9818	0.00001	60	0	-6.90 | -0.99	2588.37	Yes
EURCHF	100000	5	4813	0.00001	0.01	0.01	50.00	1.0648	0.00001	82	0	-1.36 | -5.16	2588.37	Yes
EURDKK	100000	5	2048	0.00001	0.01	0.01	50.00	0.1741	0.00001	200	0	-2.31 | -5.02	2588.37	Yes
EURGBP	100000	5	3204	0.00001	0.01	0.01	50.00	1.5529	0.00001	36	0	-3.05 | -2.58	2588.37	Yes
EURJPY	100000	3	10000	0.001	0.01	0.01	50.00	1.2994	0.001	48	0	-1.60 | -5.06	2588.37	Yes
EURNZD	100000	5	4138	0.00001	0.01	0.01	50.00	0.7781	0.00001	104	0	-13.16 | 4.39	2588.37	Yes
EURUSD	100000	5	10000	0.00001	0.01	0.01	50.00	1.0000	0.00001	35	0	-1.30 | -4.40	2588.72	Yes
GBPAUD	100000	5	3204	0.00001	0.01	0.01	50.00	1.0226	0.00001	80	0	-20.16 | 13.23	3106.33	Yes
GBPCAD	100000	5	3204	0.00001	0.01	0.01	50.00	0.9818	0.00001	71	0	-6.90 | -1.97	3106.33	Yes
GBPCHF	100000	5	3204	0.00001	0.01	0.01	50.00	1.0648	0.00001	108	0	-0.82 | -5.71	3106.33	Yes
GBPJPY	100000	3	4813	0.001	0.01	0.01	50.00	1.2994	0.001	66	0	-1.60 | -6.09	3106.33	Yes
GBPNZD	100000	5	3204	0.00001	0.01	0.01	50.00	0.7781	0.00001	132	0	-14.59 | 4.76	3106.33	Yes
GBPUSD	100000	5	9358	0.00001	0.01	0.01	50.00	1.0000	0.00001	47	0	-2.00 | -4.00	3106.80	Yes
NZDCHF	100000	5	3204	0.00001	0.01	0.01	50.00	1.0648	0.00001	66	0	2.58 | -9.92	1556.75	Yes
NZDJPY	100000	3	3204	0.001	0.01	0.01	50.00	1.2994	0.001	66	0	0.64 | -12.18	1556.75	Yes
NZDUSD	100000	5	3204	0.00001	0.01	0.01	50.00	1.0000	0.00001	49	0	2.00 | -9.00	1557.24	Yes
USDCAD	100000	5	10000	0.00001	0.01	0.01	50.00	0.9818	0.00001	37	0	-5.42 | -0.49	2000.00	Yes
USDCHF	100000	5	3204	0.00001	0.01	0.01	50.00	1.0648	0.00001	44	0	-1.96 | -3.59	2000.00	Yes
USDCZK	100000	5	2048	0.00001	0.01	0.01	50.00	0.0507	0.00001	4950	0	-4.52 | -4.62	2000.00	Yes
USDDKK	100000	5	2048	0.00001	0.01	0.01	50.00	0.1741	0.00001	160	0	-2.44 | -4.07	2000.00	Yes
USDJPY	100000	3	3766	0.001	0.01	0.01	50.00	1.2994	0.001	29	0	-2.69 | -4.23	2000.00	Yes
USDMXN	100000	5	2048	0.00001	0.01	0.01	50.00	0.0716	0.00001	696	0	-14.55 | 2.87	2000.00	Yes
USDPLN	100000	5	2048	0.00001	0.01	0.01	50.00	0.2903	0.00001	1060	0	-16.28 | 4.72	2000.00	Yes
XAGUSD	500	2	2073	0.01	0.10	0.10	0.10	5.0000	0.01	8	1	-1.13 | -1.13	277.20	No
XAUUSD	10	2	2048	0.01	0.10	0.10	0.10	0.1000	0.01	89	1	-36.00 | -36.00	312.70	No

NOTE: Point values are not converted.
[/size]

UPDATE: I have added a test to verify that the tick values reported by the server are correct. If they differ from the calculated values by more than 5%, you will see the following warning message:
IMG_50.gif
Let me know what additional information would be useful.
You do not have the required permissions to view the files attached to this post.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Currency Info

Post by gaheitman »

For those of you curious about what happens when you open a new account and don't have any history, read on.

It seems (in my limited testing) that any chart that is open for a particular timeframe will get 2048 bars downloaded immediately. I then waited a bit and ran the CurrencyInfo utility to check the number of bars in the other currencies and saw that none of the other pairs were getting updates. Now for the fun part -- actually running the CurrencyInfo utility triggered a download of 2048 bars of data for each currency.

After further testing, it turns out the call to iBars() for each of the currencies is what triggered the downloads. It may be that any of the other i...() utilities (iHigh(), iLow, etc.) would trigger the same download.

Before (as you can see, my current chart is open to EURUSD):
pic_02 2012-01-02 13.06.gif
During:
pic_03 2012-01-02 13.06.gif
I won't bore you with after. It all happened in less than a minute.

So, it looks like if you want to make sure your EA has at least 2048 bars of data, call iBars(CurrencyToCheck,PeriodToCheck) and Empty4 will dutifully download the data.

Not sure where 2048 comes from, other than being a nice computer number. I also thought it was interesting that the downloads occurred in LIFO order, they must just push requests on a stack for another process to do the downloads. Now if I can just get it to download more than 2048 bars.... :)

George
You do not have the required permissions to view the files attached to this post.
Dozer
Trader
Posts: 25
Joined: Wed Nov 16, 2011 4:32 pm

Re: Currency Info

Post by Dozer »

Thanks for taking the time and effort to share this. :)

Dozer
AnotherBrian

Re: Currency Info

Post by AnotherBrian »

Thanks, I've used this more than once. :D
User avatar
SatchFan
Trader
Posts: 30
Joined: Mon May 28, 2012 12:31 am
Location: Flying in a Blue Dream or Surfing with an Alien

Re: Currency Info

Post by SatchFan »

Wait a minute... I'm not a coder so I was not aware that you could make Empty4 post data to the WINDOWS clipboard! This changes things. I downloaded the script and took a look at it. Again, I'm not a coder but I see it's calling a couple of dll's. My question is, could something similar be done in an indicator, any indicator basically and make it where it can replace the playsound() function and instead print user specified text to the clipboard instead of playing a sound? I have a text to speech program that has a feature that will read out loud the text that is copied to the windows clipboard. This would be a good way to get past the ridiculous problem of Empty4 interrupting itself with it's alerts etc. because the text to speech program (I think) can speak multiple voices at once. I'll have to find out for sure...

So basically whenever an indicator gets to the point where it is having an alert, and it usually plays a sound, it would be changed to "Print user specified text to windows clipboard". Is this possible?

Peace,
SatchFan
Screenshots provided by PickPick. A Must Read --> Phantom of the Pits
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Currency Info

Post by gaheitman »

SatchFan wrote:
So basically whenever an indicator gets to the point where it is having an alert, and it usually plays a sound, it would be changed to "Print user specified text to windows clipboard". Is this possible?

Peace,
SatchFan
Yes, you can add it to an indicator. I just did a test to make sure. The code to add to the indicator is:

Code: Select all

//clipboard functions borrowed from JC at http://www.mql4.com/users/jjc
#import "kernel32.dll"
   int GlobalAlloc(int Flags, int Size);
   int GlobalLock(int hMem);
   int GlobalUnlock(int hMem);
   int GlobalFree(int hMem);
   int lstrcpyA(int ptrhMem, string Text);
#import


#import "user32.dll"
   int OpenClipboard(int hOwnerWindow);
   int EmptyClipboard();
   int CloseClipboard();
   int SetClipboardData(int Format, int hMem);
#import

#define GMEM_MOVEABLE   2
#define CF_TEXT         1

// Copies the specified text to the clipboard, returning true if successful
bool CopyTextToClipboard(string Text)
{
   bool bReturnvalue = false;
   
   // Try grabbing ownership of the clipboard 
   if (OpenClipboard(0) != 0) {
      // Try emptying the clipboard
      if (EmptyClipboard() != 0) {
         // Try allocating a block of global memory to hold the text 
         int lnString = StringLen(Text);
         int hMem = GlobalAlloc(GMEM_MOVEABLE, lnString + 1);
         if (hMem != 0) {
            // Try locking the memory, so that we can copy into it
            int ptrMem = GlobalLock(hMem);
            if (ptrMem != 0) {
               // Copy the string into the global memory
               lstrcpyA(ptrMem, Text);            
               // Release ownership of the global memory (but don't discard it)
               GlobalUnlock(hMem);            

               // Try setting the clipboard contents using the global memory
               if (SetClipboardData(CF_TEXT, hMem) != 0) {
                  // Okay
                  bReturnvalue = true;   
               } else {
                  // Failed to set the clipboard using the global memory
                  GlobalFree(hMem);
               }
            } else {
               // Meemory allocated but not locked
               GlobalFree(hMem);
            }      
         } else {
            // Failed to allocate memory to hold string 
         }
      } else {
         // Failed to empty clipboard
      }
      // Always release the clipboard, even if the copy failed
      CloseClipboard();
   } else {
      // Failed to open clipboard
   }

   return (bReturnvalue);
}
Then you call CopyTextToClipboard("Text you want in the clipboard"); whenever you want to add something to the clipboard.

George
User avatar
SatchFan
Trader
Posts: 30
Joined: Mon May 28, 2012 12:31 am
Location: Flying in a Blue Dream or Surfing with an Alien

Re: Currency Info

Post by SatchFan »

Thank You for posting that gaheitman! :)
Screenshots provided by PickPick. A Must Read --> Phantom of the Pits
Post Reply

Return to “Utilities”