
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
Hello legends of mql. I cooked up the pseudo code for you during my lunch hour at work. Here it is. let me know what's missing and i'l add it on.
N&P Pseudo Code
With this strategy we want to have 1 code, be able to attach it to any chart, and it would run on 5 currencies, entering both short and long positions on each one if the rules meet.
---EURUSD---
If ema7>ema14>sma50 and PriceNow is < TopFilterLevel (eg:1.3080 for eurusd. This I will adjust on a daily basis) then:
Buy EURUSD Lots(lots to be external variable, eg 0.01). Else: (ie. conditions not met) don't buy.
If ema7<ema14<sma50 and PriceNow is > BottomFilterLevel (eg: 1.1508 for eurusd) then:
Short EURUSD Lots (agian, external variable). Else (ie. conditions not met don't short).
If BUY position reaches 20 pips from point of entry then: TAKEPROFIT on EURUSD.
If SHORT position reaches 20 pips from point of entry then: TAKEPROFIT on EURUSD.
If 20 pips are not reached (either buy or sell) then keep being in the market until the position is closed
manually. (ideall we put this into OrderSend function to keep code shorter).
----GBPUSD---
exactly the same code as above.
----USDJPY---
SAME AS ABOVE
---USDCHF---
SAME AS ABOVE
---AUDUSD---
SAME AS ABOVE
**Code specifics
both buy and short trades can be executed simultaneously for any given currency if the criteria stated above meet
***no stoploss is needed for this code
**no money management code for this one
So how does this look?
Hello legends of mql. I cooked up the pseudo code for you during my lunch hour at work. Here it is. let me know what's missing and i'l add it on.
N&P Pseudo Code
With this strategy we want to have 1 code, be able to attach it to any chart, and it would run on 5 currencies, entering both short and long positions on each one if the rules meet.
---EURUSD---
If ema7>ema14>sma50 and PriceNow is < TopFilterLevel (eg:1.3080 for eurusd. This I will adjust on a daily basis) then:
Buy EURUSD Lots(lots to be external variable, eg 0.01). Else: (ie. conditions not met) don't buy.
If ema7<ema14<sma50 and PriceNow is > BottomFilterLevel (eg: 1.1508 for eurusd) then:
Short EURUSD Lots (agian, external variable). Else (ie. conditions not met don't short).
If BUY position reaches 20 pips from point of entry then: TAKEPROFIT on EURUSD.
If SHORT position reaches 20 pips from point of entry then: TAKEPROFIT on EURUSD.
If 20 pips are not reached (either buy or sell) then keep being in the market until the position is closed
manually. (ideall we put this into OrderSend function to keep code shorter).
----GBPUSD---
exactly the same code as above.
----USDJPY---
SAME AS ABOVE
---USDCHF---
SAME AS ABOVE
---AUDUSD---
SAME AS ABOVE
**Code specifics
both buy and short trades can be executed simultaneously for any given currency if the criteria stated above meet
***no stoploss is needed for this code
**no money management code for this one
So how does this look?
Hey guys, the basic tutorial on coding really helped to get my head around this (although the detailed coding part is lacking). To show you I have been busy, I attached the code below. The idea i think is there but it still returns lots of errors. You will see everything is under one big bracket in Start() the reason I did that is because mql kept coming back with error that variable can't be declared globally, and when i made it all in 1 bracket it seemed to have stopped that error (although lots of other errors persisted). I used notepad++ to check the brackets align. So did am I at least going the right way with this?
this is the latest version of the code. syntatically everthing seems to be ok, but when i run it through strategy tester it returns no trades. something is wrong with logic. need help. I'm becoming quite familiar with code now, well the structure of program side of it.Hello legends of mql. I cooked up the pseudo code for you during my lunch hour at work. Here it is. let me know what's missing and i'l add it on.
N&P Pseudo Code
With this strategy we want to have 1 code, be able to attach it to any chart, and it would run on 5 currencies, entering both short and long positions on each one if the rules meet.
---EURUSD---
If ema7>ema14>sma50 and PriceNow is < TopFilterLevel (eg:1.3080 for eurusd. This I will adjust on a daily basis) then:
Buy EURUSD Lots(lots to be external variable, eg 0.01). Else: (ie. conditions not met) don't buy.
If ema7<ema14<sma50 and PriceNow is > BottomFilterLevel (eg: 1.1508 for eurusd) then:
Short EURUSD Lots (agian, external variable). Else (ie. conditions not met don't short).
If BUY position reaches 20 pips from point of entry then: TAKEPROFIT on EURUSD.
If SHORT position reaches 20 pips from point of entry then: TAKEPROFIT on EURUSD.
If 20 pips are not reached (either buy or sell) then keep being in the market until the position is closed
manually. (ideall we put this into OrderSend function to keep code shorter).
----GBPUSD---
exactly the same code as above.
----USDJPY---
SAME AS ABOVE
---USDCHF---
SAME AS ABOVE
---AUDUSD---
SAME AS ABOVE
**Code specifics
both buy and short trades can be executed simultaneously for any given currency if the criteria stated above meet
***no stoploss is needed for this code
**no money management code for this one
So how does this look?
Hi Niko
Your pseudo code looks pretty good for a first attempt.
I would however like to see it a bit more structured and there are a couple of questions that it raises for me.
I was able to easily and quickly put it into the sort of format that I would typically use myself. It is attached here as a text file for you to have a look at. You will need to save this file and open it in notepad or a similar editor to see the formatting.
Note that at this stage we are not writing in any specific computer language . We are just trying to specify clearly and unambiguously what we are trying to do.
You may notice that the pseudo code is quite specific and "legalistic". This is how we have to talk to computers. We need to spell out very clearly what it is we want them to do. Otherwise they have a tendency to generate garbage.
You will also notice the use of "Blocks" to arrange things into logical groups. These may be useful later on to help us structure the code properly. As someone pointed out earlier in this discussion, we dont do this just for fun. We do it to make the code more readible, more understandable, more maintainable and ultimately more reliable and bug free. The later is extremely important in software that is going to be used for live trading inless of course you have buckets of money that you are willing to throw away :) . Seriously, trading is difficult enough without also having to deal with buggy software.
Please have a look at what I have sent you and feel free to make any changes that you think are necessary. There are a couple of important points missing from my pseudo code. Can you spot them?
You may also like to deal with the two questions that I have raised in the pseudo code. A number of other questions come to mind but these can be better left until the actual coding phase.
If you have not already done so you might want to try out the the Notepad++ editor that FXtrader2008 mentioned earlier in this discussion. Use any tools that you can find that make life a bit easier. Please post your revised pseudo code back to me as a text file attachment. I find trying to write structured code, pseudo or otherwise, in this HTML editor a bit tedious and messy.
Regards
Tim
Hi Niko
Your pseudo code looks pretty good for a first attempt.
I would however like to see it a bit more structured and there are a couple of questions that it raises for me.
I was able to easily and quickly put it into the sort of format that I would typically use myself. It is attached here as a text file for you to have a look at. You will need to save this file and open it in notepad or a similar editor to see the formatting.
Note that at this stage we are not writing in any specific computer language . We are just trying to specify clearly and unambiguously what we are trying to do.
You may notice that the pseudo code is quite specific and "legalistic". This is how we have to talk to computers. We need to spell out very clearly what it is we want them to do. Otherwise they have a tendency to generate garbage.
You will also notice the use of "Blocks" to arrange things into logical groups. These may be useful later on to help us structure the code properly. As someone pointed out earlier in this discussion, we dont do this just for fun. We do it to make the code more readible, more understandable, more maintainable and ultimately more reliable and bug free. The later is extremely important in software that is going to be used for live trading inless of course you have buckets of money that you are willing to throw away :) . Seriously, trading is difficult enough without also having to deal with buggy software.
Please have a look at what I have sent you and feel free to make any changes that you think are necessary. There are a couple of important points missing from my pseudo code. Can you spot them?
You may also like to deal with the two questions that I have raised in the pseudo code. A number of other questions come to mind but these can be better left until the actual coding phase.
If you have not already done so you might want to try out the the Notepad++ editor that FXtrader2008 mentioned earlier in this discussion. Use any tools that you can find that make life a bit easier. Please post your revised pseudo code back to me as a text file attachment. I find trying to write structured code, pseudo or otherwise, in this HTML editor a bit tedious and messy.
Regards
Tim
Hey TSW. Thank you for this. I can see you put quite a bit of time into this so I really appreciate it. I attached the updated pseudo code, but in case it didn't attach, here it is below. I tried to see what you missed out, but couldn't quite figure it out, a few things I added but they were just clarifications of things.
Where do we go from here? Whilst we are creating this 'proper' code, I am still trying to solve the puzzle of the code above. It doesn't follow our pseudo code as it is an old patched up code, but I am still quite puzzled with it as it should work, at least for 1 currency. Key thing is building it in this unorganised haphazard way is teaching me the actual coding elements (like how brackets affect the script, where to declare variables, etc). Any ideas on why that code doesn't work as it is now?
Hey guys, the basic tutorial on coding really helped to get my head around this (although the detailed coding part is lacking). To show you I have been busy, I attached the code below. The idea i think is there but it still returns lots of errors. You will see everything is under one big bracket in Start() the reason I did that is because mql kept coming back with error that variable can't be declared globally, and when i made it all in 1 bracket it seemed to have stopped that error (although lots of other errors persisted). I used notepad++ to check the brackets align. So did am I at least going the right way with this?
this is the latest version of the code. syntatically everthing seems to be ok, but when i run it through strategy tester it returns no trades. something is wrong with logic. need help. I'm becoming quite familiar with code now, well the structure of program side of it.Hey guys/gals, any help with the above bit of code (not the pseudo code but the code code) while i'm learning how to do it the proper way.
I had a brainstorm today, I think maybe the error is there is one function counting the orders, and instead maybe I need 2 functions separately, one counts the buys and another sells. I programmed the code below (changed a few things to account for this), you can see below. But still it was all messed up as I am still a complete beginner. Any ideas on this one?
Hey guys/gals, any help with the above bit of code (not the pseudo code but the code code) while i'm learning how to do it the proper way.
I had a brainstorm today, I think maybe the error is there is one function counting the orders, and instead maybe I need 2 functions separately, one counts the buys and another sells. I programmed the code below (changed a few things to account for this), you can see below. But still it was all messed up as I am still a complete beginner. Any ideas on this one?
Hi Niko
With reference to the pseudo code
From the code:
*** Question ***
What time periods do you want to use for your moving averages? Are the periods Minutes, Hours, Days, Weeks, Months or do they need to be variable?
***Answer *** Excellent question. It will be 5 minute periods for all moving averages, they do not need to be variable.
Then I would suggest adding to the pseudo code in the configuration parameters area a statement something like
"Use 5 Minute Time Frame for Indicators"
You said:
***I was unclear on this before, my apologies. There should be no block as this in the code.
I will exit positions manually when needed through the trade/terminal window
(I assume that’s possible and won’t mess up the EA execution, right).
So actually I don’t know if we need to code this flexibility or not? What do you think
I then suggest that you just delete this block from the pseudo code.
There should be no problem coding the EA so that you can use the terminal to close a position manually without messing anything up.
You added these lines:
ELSE If there is already 1 open BUY position for this currency pair DO NOT OPEN BUY Position for this currency pair.
ELSE If there is already 1 sell position open for this currency pair Do not open SELL Positions for this currency pair
*** Question *** Why do you need to specifically state what you DONT want the program to do after the previous lines have just
stated what you DO want the program to do. In my opinion the pseudo code is the place to carefully think through your logic. Otherwise you are likely to
get into a mess when you start actual coding.
You said:
PS: I will often use just 1 direction on a currency pair (eg: just short, for eurusd for 2 days for instance). How could we build this into the code. My assumption is I could just put ‘//’ infront of the parts of the code I don’t want to use (Eg: infront of buy or sell orders within each currency pair) and then remove them when I need to use that part of code next time. Will this work with a code structured in this way?
Commenting out code as you suggest is not a very elegant way to go. Further more, i f you comment out say the "LONG" section of the code you would comment out the function for opening long positions for all currency pairs, unless you produce code with a lot of duplication. This is also not a very elegant way to go and easily leads to errors.
Over a given period you may want to be long EURUSD, short GBPUSD and not trade USDCHF at all. This is quite easily accomplished but I'd like to see you have a go at trying to work out to how to describe it yourself in the pseudo code.
Here are a couple of hints as to one possible way of going about it.
1. have a look at how your levels are set up and employed
2. The levels are represented as decimal numbers. For go/no go situations is is a common practice to use another type of representation known as a boolean or flag. Would it be possible to use flags to accomplish what you want to do?
You said:
**I can’t really think of anything you left out on purpose, to be honest. Unless it’s to check if there are sufficient funds for the trade, but that’s not necessary yet.
Maybe in future versions of the strategy.
No its not about checking for sufficient funds. You specifically said no money management except of course for specifiying lot size. It is something much more fundamental.
What items of information do you need to place an order? Where and how are each of these items described and handled in the psuedo code?
You said:
Where do we go from here? Whilst we are creating this 'proper' code, I am still trying to solve the puzzle of the code above. It doesn't follow our pseudo code as it is an old patched up code, but I am still quite puzzled with it as it should work, at least for 1 currency. Key thing is building it in this unorganised haphazard way is teaching me the actual coding elements (like how brackets affect the script, where to declare variables, etc). Any ideas on why that code doesn't work as it is now?
I appreciate your frustration. I had a very quick look at the old code but frankly what you are trying to do doesn't make much sense logiically. I could rewrite this piece of code in about 15 minutes and it would do what you want it to, but that is not the point is it?. You said you wanted to learn to write code. I am endeavouring to instruct you how to do it for yourself.
Nico, I dont think you are too far away from starting to write some (new) proper code but it is important to get as much of the "what you want to do" accurately nailed down in the pseudo code first.
It will make the coding "sooo much easier" as you will soon see.
Keep up the good work
Cheers
Tim
Hey Tim,
As always I really appreciate your time with me. I will go ahead and modify the pseudo code so it reflects your comments. About real code, no worries, let's do it properly (i'm just a bit impatient at times :), as learning is more powerful than anything.
Hey Tim,
I went through the pseudo code again and did as much as my newbie brain could figure out at this point. Please find it attached, I look forward to your comments!
Hey Tim,
I went through the pseudo code again and did as much as my newbie brain could figure out at this point. Please find it attached, I look forward to your comments!
Hi Nick
That is all looking good.
I went through your latest psuedo code and answered some questions etc.
I think we are just about ready to start coding.
As a very rough rule of thumb they say 1/3 rd of programming time should be spent on specification, 1/3rd on coding and 1/3rd on debugging and testing.
So we can say that we are now roughly 1/3 of the way through this little project!
Now lets talk about the MT4 language.
All computer languages have specific ways ( a format) in which the language must be written so that the computer can understand what you are trying to instruct it to do. You find out about this and other language specific information from the documentation. The documentation for MT4 ia available on line on this forum. If you have not already done so I would suggest you spend some time having a look at the sort of information that is availaible in the documentation. Then when you need information about some specific topic or function you will know where to look for it.
To make life a bit easier, many modern compter languages including MT4 use templates which set up a basic program layout for you. These template programs are often refered to as "wizards". You will find the EA wizard under the "New" menu item in the MetatEditor with the green cross on it.
If you open this you will find a template for "Expert Advisor". Select this and you will be prompted for an EA name, author details etc and parameters. The parameters can be added or changed later but at this stage you might want to enter the parameters from the configuration block.
You will be required to give each parameter a name, a type and an intial value
Parameter names should always be descriptive of what they are
for example EURUSD_TopFilterLevel is a meaningful name ex1 IS NOT. The use of meaningful data names make the program much easier to understand debug or modify later on. Note that in MT4, data names are case sensitive. LOTSize is not the same as LotSize. You need to be careful and consistent with data names.
You will also be required to specify a data type (type) for each parameter. MT4 uses just 4 data types Integer Number (int), Decimal Number (double), Text (string) and True / False or Flag (bool) .
Again we need to be careful with data types and to not mix them up unknowingly or we can introduce subtle bugs.
Once you have created your template with the wizard I would suggest you start "structuring" you program . The basic unit of structure in MT4 is the FUNCTION.
The simplest basic function,which as it is written here, actually does nothing is -
The template generated by the metatrader wizard already has three empty functions in it.
The init function is called every time the EA starts when you drag it onto a chart and click the Expert advisor button ON
The deinit function is called every time the EA stops when you drag it off a chart or click the Expert advisor button OFF
The start function is called on EVERY NEW TICK received by the chart that it is attached to. This means it can be called several times or more a minute depending on how busy the market is. This is where we will do most of our work from.
For the time being I suggest that you put all the pseudo code from the main block into the start function and then comment out the pseudo code with // on each line.
Then create a new function of your own for the entry rules block and comment out the pseudo code in it the same way.
Leave the init and deint functions empty and as they are for the time being.
You should be able to compile this code without errors but of course at this stage it will do nothing.
Keep up the good work!
Regards
Tim
(PS we can talk on skype if needs be but lets just see how we go with the forum for the time being)
Hey Tim,
As always your help and time is highly invaluable! As a gesture of thanks I would like you to send you a very nice bottle of champaigne once we finished with the coding process.
Yep, I been through the mql book quite a few times, the difficulty was putting the theory into practice. I also printed out about 10 or so EA's posted on this website, to see hwo things are coded and put together, to try and understand them. And I spend a lot of time in simulator trader on MT4 (ie backtesting and learning already existing EA's).
I'l start the coding process, and make blocks very clear and separate to help both of us see what's going on. And send them to you via forum.
1 Question: You said brokerages put in things to stop aggressive pipping. 1. What do you define aggressive pipping? 2. What things do they put in place?
I used to manually scalp eurusd on 1min timeframes (with a spreadbetting method), this was going really well until the brockerage clicked in and started to put delays for execution (entry and exit). So now there's no point at all doing this with this brokerage, even though it's illegal, delays will still happen and mess up the whole day (like if you typically scalp just for 1 hour, 2 delays and you lost the valuable time). I got all money back for delayed trades after aggressive threatening of court action.
2 Question: Do you use different brokers? What brokers would you recommend? (if you are allowed to mention names here)
thanks,
nick