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.
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
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.
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.
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.
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.
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.
You must be logged in to reply to this topic.