Magic Numbers
9 replies
ssdex
8 years ago #113889
Hello,
Does anyone know if there is a way to create a variable that produces a random number every time it is triggered? Then we can set the variable as the magic number in the strategy parameters. If possible, this would fix the issue if you have multiple trades on a single currency pair.
Thanks for any feedback.
Regards,
James
tomas262
8 years ago #131130
Hello,
1) define ‘RandNumber’ variable type INT in EA Wizard
2) choose trigger to when you want to generate random value for this varible. It can be trading signal condition itself as well.
3) add ‘Custom Action’ and type this command: ‘RandNumber = MathRand();
This way anytime the condition is met, RandNumber will be assigned with a pseudorandom integer within the range of 0 to 32767.
Hope that helps
ssdex
8 years ago #131131
ssdex
8 years ago #131210
Hey Tomas262,
I’ve been messing around with the ‘RandNumber’. I’m having a problem trying to figure out how to reference the current trades SL and Entry Price because I don’t understand how to reference the random magic number.
Example:
There is currently a Buy in the market and I want to place a pending order to Sell at the Buy’s SL and the SL of the Pending Sell order at the Entry of the current Buy trade.
Do you know of a way to reference the ‘RandNumber’ for managing risk and possible setting pending orders?
Thanks for any help.
Regards,
James
tomas262
8 years ago #131234
Have many concurrent trades there can be for the same pair?
Do you use the same stop-loss distance for other positions or how is SL calculated?
Generally you have to create variables and store values like the magic number of opened trade you mention. You can then use “Order Average Price (Magic Number)” function and knowing your stop-loss size I would calculate price for that pending order and stop-loss price would be the “Order Average Price” ….
But considering I don’t know exactly how your strategy works I cannot tell this is what you need.
JS17
8 years ago #131240
ssdx,
The only problem you will have when using that method of setting magic numbers is that every time you reset your EA or restart MT4, you will have a different set of magic numbers so you will not be able to touch your EA or MT4 or your EA will loose track of your trades
ssdex
8 years ago #131267
Thanks everyone for your replies. At the moment it seems easier to stick to the magic number system I have going. All the replies have spurred some ideas that might help. Thanks again.
Regards,
James
luk85
8 years ago #133092
I think I have found solution. You need to use variable with magic number and put it in your rules with + operation. So long will be “magic+1”, short : “magic+2”, long2: “magic+3”, short2: “magic+4”. Then depends on how many opening position rules you have, when you add EA to another instrument you incrise “magic” variable respectively. When you have 2 long and 2 short rules your EA use 4 different numbers. For example: EA working on EUR/USD. Magic is 10. EA use numbers 11,12,13,14. Then you put EA on USD/JPY with magic number 20. EA use numbers 21,22,23,24 etc. With this method you dont have to generate random numbers and your EA don’t lost “connection” with opened trades.
Hope this help.
Best Regards
ssdex
8 years ago #133114
ssdex
7 years ago #139467
Good evening Luk85.
I’m back looking for options to eliminate magic number for a grid system I want to try and code. It has been a while since this thread has been active but I thought I’d ask again.
I didn’t quite understand what you explained in the above post. I would really appreciate if you could expand on that a little (or lot). 🙂
it looks like i might need around 10-20 trades per side (buy/sell).
Thank you for any of your time in helping with understanding this possibility.
Regards,
James
Viewing 9 replies - 1 through 9 (of 9 total)