| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Need help/advice with array https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3904 |
Page 1 of 1 |
| Author: | gringoh [ Fri Oct 31, 2014 10:16 pm ] |
| Post subject: | Need help/advice with array |
Hi guys, I have a question which should be an easy one for good coders. In “MPTM is trading multiple pairs”, I am trying to add a filter to avoid trading a selected list of pairs. I think it is possible to manage that with an extern string and an array which should look like this: Code: Select all Code: Select all Any help would be appreciated, for “MPTM is trading multiple pairs”, and for me to understand how to build and use arrays. Thanks for your help. Cheers, Gringoh |
|
| Author: | SteveHopwood [ Fri Oct 31, 2014 11:16 pm ] |
| Post subject: | Need help/advice with array |
My method will not be the best one, but I evolved it many years ago and use it ever since. Look at SBB because this is typical. extern string PairsToTrade = "AUDCAD,AUDCHF,AUDNZD,AUDJPY,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURNZD,EURJPY,EURUSD,GBPCHF,GBPJPY,GBPUSD,NZDUSD,NZDJPY,USDCAD,USDCHF,USDJPY"; holds the pairs the multi-trader trades. In your case it will be your excluded pairs. I declare these three variables: string InputString;//Holds the contents PairsToTrade for tidying yp etc int NoOfPairs;// Holds the number of pairs passed by the user via the inputs screen string TradePair[]; //Array to hold the pairs traded by the user Then OnInit() contains the call to the function that sets up my trade pairs array: ExtractPairs(); ExtractPairs() contains calls to some more functions that clean up the strings, calculate the number of pairs to be traded then resize any associated arrays. It is not degree-standard code but it works and has done for years. Adapt it if nobody comes up with a better solution. |
|
| Author: | gringoh [ Sun Nov 02, 2014 4:15 pm ] |
| Post subject: | Need help/advice with array |
Thanks for your answer Steve. Before to ask this question, I checked your code and tried to adapt it without success I am going to try again and decompose your code step by step until I get it. Cheers, G |
|
| Author: | renexxxx [ Sun Nov 02, 2014 8:04 pm ] |
| Post subject: | Need help/advice with array |
Hi Gringoh, Using arrays can be quite fancy, but in your case this is much easier with a simple StringFind. I have attached some code to demonstrate. Have fun.! |
|
| Author: | gringoh [ Mon Nov 03, 2014 1:50 pm ] |
| Post subject: | Need help/advice with array |
Hi Rene, Many thanks for your help Your function with arrays is exactly what I was looking for and is working perfectly May I ask you some clarifications, just to understand exactly what this code is doing, I don’t want to stay stupid and use this code without understanding how it works. Code: Select all Code: Select all Code: Select all Code: Select all Many thanks again. Cheers, G |
|
| Author: | renexxxx [ Mon Nov 03, 2014 7:58 pm ] |
| Post subject: | Need help/advice with array |
Hi Gringoh, The first two parts of the code is just to clean up the input parameter 'ExcludedPairs'. If some idiot provides an input parameter such as: ",,,,EURUSD, , GBPUSD, , GBPCAD,,,,,", the StringSplit() function will not produce the right pairs. So, I was attempting to make the code idiot-proof. In fact, I should have gone a few steps further and remove consecutive ",,", make it case-insensitive, remove rubbish (such as '-%&#@') etc etc. Otherwise you can get posts like the following: Anyway, more specifically: Code: Select all Code: Select all Code: Select all Code: Select all Cheers, Rene |
|
| Author: | gringoh [ Mon Nov 03, 2014 10:01 pm ] |
| Post subject: | Need help/advice with array |
Many thanks Rene, All clear now |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|