| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| case code https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4274 |
Page 1 of 1 |
| Author: | censura10 [ Thu May 28, 2015 8:12 am ] |
| Post subject: | case code |
Hi everyone, hope you are all well can someone quickly check this and see if i have it set correctly. I am counting losing trades which uses variable LossCountCount each loss increases the LossCountCount by 1 Then with this i am using the case function to return a different value see below. I wanted for example if LossCountCount was 5 that it returns a value 4 and this is then passed to LossCount variable. My concern is that having now returned 4 via case function LossCountCount is now 4 not 5 which is the correct count of the lossing trades. If this the case can i for example return the case value directly to the LossCount variable and not affect the LossCountCount value. Hope it makes sense and you can help. Kind regards Code: Select all |
|
| Author: | renexxxx [ Thu May 28, 2015 10:27 am ] |
| Post subject: | case code |
Just create a function that maps the integer value of LossCountCount to a new integer value, eg: Code: Select all Code: Select all Note that I have opted to do away with the multiple return() statements inside the switch, as it is bad coding practice to have multiple returns from a function (i.e. a function should be exited at only one place). But technically, you can use the multiple returns. Cheers ... |
|
| Author: | censura10 [ Thu May 28, 2015 10:35 am ] |
| Post subject: | case code |
Hi and thank you for your help, i applied the code and got this error 'fnLossCountCount' - function can be declared only in the global scope thank you |
|
| Author: | renexxxx [ Thu May 28, 2015 10:50 am ] |
| Post subject: | case code |
Yes, that's right. Don't declare the fnLossCountCount function inside another function, but in the global scope. |
|
| Author: | censura10 [ Thu May 28, 2015 11:52 am ] |
| Post subject: | case code |
Hi sorry for being a bit of a nob but only started back trying to code an ea and even when i did it a couple of years ago it was a bit of trial and error I tried to move the whole block out and call it but it would not allow switch statement in global, i then tried to just move the function but said has to have body? so i know you must wish you had not replied but if you can great if not I thank you for your time Kind regards Code: Select all |
|
| Author: | renexxxx [ Thu May 28, 2015 12:05 pm ] |
| Post subject: | case code |
You have declared the fnLossCountCount function inside the CalculateDailyResult function. In MQL4 functions must be declared at the global scope (you can define class methods inside a class, but that is another story). In order for your code to work, you must have the global variables int LossTrades; int LossCount; int WinTrades; double OverallProfit; and int MagicNumber; somewhere else declared. The following code is compilable: Code: Select all |
|
| Author: | censura10 [ Thu May 28, 2015 1:45 pm ] |
| Post subject: | case code |
Hi thank you I am really grateful for your help, corrected my code with yours and testing. Thank you again |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|