Creating EA to enter new trades ONLY
13 replies
Chorlton
9 years ago #112258
Hello All,
I’m new to MQL (hence my reason for using EA Wizard) and I want to create an EA that will enter new trades only as I will be planning to exit each open trade manually at a future point in time.
As each trade needs its own magic number, how would I do this? Assuming that my buy signal occurs multiple times per trading session then at the end of that trading session ideally there would be many different open trades.
Can this be done?
Thanks in advance,
Chorlton
Mark Fric
9 years ago #124904
Hello Chorlton,
do you want to open new trade at every signal? This is quite dangerous, you might end up with new trades opened on every bar or even every tick,if you don’t do it right.
But it is possible, you only need to make MagicNumber parameter dynamic.
Define a variable and name it for example MyMagicNumber, and increment it before every order.
Then use this variable for Magic Number in your order and it will open new order with new magic number
Mark
StrategyQuant architect
Pit
9 years ago #124915
Chorlton
9 years ago #124918
Hello Chorlton,
do you want to open new trade at every signal? This is quite dangerous, you might end up with new trades opened on every bar or even every tick,if you don’t do it right.
But it is possible, you only need to make MagicNumber parameter dynamic.
Define a variable and name it for example MyMagicNumber, and increment it before every order.
Then use this variable for Magic Number in your order and it will open new order with new magic number
Hi Mark,
Appreciate the reply.
My trigger signal would occur reasonably frequently and I would like to be able to control the maximum number of trades taken within a specific period (eg. No more than 3 on one currency pair within one 8hr trading session) but I guess that’s another question.
Going back to your comment I didn’t think this would be possible unless the EA tracks all previous trades entered . Surely this would get very complicated??? What happens if it is stopped and then restarted etc??
Mark Fric
9 years ago #124920
Hello,
yes, it will be little bit complicated, for order management that is this complex you would do better if you’ll learn MQL programming.
Mark
StrategyQuant architect
Chorlton
9 years ago #124921
Hi Mark,
Quick question. Does a magic number have to be supplied when trading with an EA? For example could I just open new trades with an EA without using Magic numbers to reference them and then choose to close them manually at a later date through my MT4 terminal?
Mark Fric
9 years ago #124925
yes, if you plan to close the trades manually then you don’t need to use magic number (or use always the same one).
in EA Wizard you have to use unique magic numbers because they are used to track the trades and manage SL/PT?Trailign stop, etc.
Mark
StrategyQuant architect
Chorlton
9 years ago #124936
yes, if you plan to close the trades manually then you don’t need to use magic number (or use always the same one).
in EA Wizard you have to use unique magic numbers because they are used to track the trades and manage SL/PT?Trailign stop, etc.
Hi Mark,
Firstly, thanks for helping me get my head around this. I purchased your software yesterday and intend to get into that once I get to grips with this.
Regarding magic numbers the thing that really confuses me is this:-
We need a magic number in order to identify the trade so that we can then manage stops which I totally understand. My understanding also is that the EA will assign the same magic number (which we have given it) each time we enter a new trade. But surely this is only sensible if the first trade entered is closed before the next trade is entered? Otherwise we can have 2 or more open trades all with the same magic number making this impossible to identify each of the open trades. If this happens how then do we manage the stops for each individual trade entered???
So in essence my question is how do traders manage multiple open trades (all with individual stop levels) on the same currency pair at the same time using an EA??
Below is the kind of strategy that I want to implement.:
For the currency pairs which I choose to trade, each time my signal trigger occurs I need to perform the following:
1) Create a market order to enter a trade (either long or short)
2) At the same time as the market order also create a stop order, say x number of pips below / above my entry price (depending on whether I am going long or short) in order to get me out of the trade at a defined loss should it immediately turn against me.
3) Should the price move in my favour then my stop order will get modified and moved to break-even.
Should another signal trigger occur on the same or different currency pair, repeat steps 1-3. [basically: enter trade -> enter Stop level -> move stop to breakeven -> move onto next trade )
All exits will be executed manually via my MT4 terminal.
Any help appreciated,
Chorlton
Mark Fric
9 years ago #124938
Hello,
you are right, trades should be opened with unique magic numbers.
The EA will not open new trade with the same magic number if active order already exists.
If you want to open multiple orders at the same time the best approach is to use multiple rules and use different magic number for each order.
You can see the samples, some of them open two stop orders at the same time with different magic number.
You can also check the Martingale sample here on the forum, I think it also opens multiple orders at the same time.
Mark
StrategyQuant architect
Chorlton
9 years ago #124941
Hello,
you are right, trades should be opened with unique magic numbers.
The EA will not open new trade with the same magic number if active order already exists.
If you want to open multiple orders at the same time the best approach is to use multiple rules and use different magic number for each order.
You can see the samples, some of them open two stop orders at the same time with different magic number.
You can also check the Martingale sample here on the forum, I think it also opens multiple orders at the same time.
Thanks Mark…. appreciate the reply.
One point that I need to clarify though as it may change the answer is that I’m not looking to open multiple positions at the same time. Instead, if I open one position (and then after a period of time it has then moved into profit) and then the same trigger signal appears again I want to enter a new trade whilst keeping the previous one still open. I may decide to do this many times on one currency pair so I now have multiple trades all entered at different times. This is a bit like pyramiding into a trade. eg. open one trade >- trade moves into profit >- open extra trade….repeat if required.
I would have thought this is something that many traders do so I’m surprised that this seems so hard to achieve. Maybe I am misunderstanding something but based on current understanding in order for the EA to allow me to enter the next trade I would have to close the previous trade first… this seems crazy 🙁
Mark Fric
9 years ago #124979
ok, it doesn’t matter that you are not trying to open the new positions at the same time, you want to open new position while position to the same direction already exists.
To do this you have to use unique magic number, otherwise you wouldn’t be able to control the trade.
If you want to open just 2-3 positions like this then it is relatively simple, just add a rule (tab) for each new position to EA Wizard.
If you want to open more of them it can get more complicated and the strategy starts to be difficult to understand an dmanage.
Mark
StrategyQuant architect
george kyriakides
7 years ago #137953
Hello Chorlton,
do you want to open new trade at every signal? This is quite dangerous, you might end up with new trades opened on every bar or even every tick,if you don’t do it right.
But it is possible, you only need to make MagicNumber parameter dynamic.
Define a variable and name it for example MyMagicNumber, and increment it before every order.
Then use this variable for Magic Number in your order and it will open new order with new magic number
Hi there Administrator.
please can you help me make magic number parameter dynamic. it doesn’t mater how many trades i open at all on my system i am busy with. as i will be using the close all function should total profits of all trades be an x amount.
some assistance would be greatly appreciated.
defining a varable i have no problem doing but were do i increment it before every order?
some help with an example will do wonders thanks
kind regards
George k
tomas262
7 years ago #137964
Hello,
maybe this could help to what you need https://strategyquant.com/forum/topic/4133-how-to-generate-random-automatic-magic-numbers/?hl=%2Bmagic+%2Brandom
george kyriakides
7 years ago #138003
Viewing 13 replies - 1 through 13 (of 13 total)