Not logged in
Viewing 10 posts - 1 through 10 (of 10 total)
  • #113889 |
    Customer
    87 Posts

    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

     

     

     

    #131130
    Moderator
    1559 Posts

    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

    #131131
    Customer
    87 Posts

    Thanks tomas262. That will help a lot with a system I’m working on. 

     

    Regards,

     

    James

    #131210
    Customer
    87 Posts

    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

    #131234
    Moderator
    1559 Posts

    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.

    #131240
    Customer
    72 Posts

    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

    #131267
    Customer
    87 Posts

    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

    #133092
    Customer
    8 Posts

    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

    #133114
    Customer
    87 Posts

    Thanks luk85

     

    I’ll take a look at what you are suggesting. Thanks for your input. 

     

    Regards,

    James

    #139467
    Customer
    87 Posts

    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 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.