I use current month+ current day+account number as a seed for MathSrand() to generate a pseudo-random magic number each day. I would want to be able to look at trade history and create a report of all trades that hit SL (for example), so I would want to get a new seed for each day in history to be able to find all trades created by this EA. Would something like this work?
I didn't compile it, sorry if there is error. Just want to give an idea to you of how many times I would want to reseed (if reseeding if possible) to find the predictable pseudorandom magic numbers from historic dates when calling rand(). FindOurOrders() would only be called from a CHARTEVENT_OBJECT_CLICK, so it would run very infrequently.
Seed once.
srand(_RandomSeed);
and also limit the range of your magic numbers using the modulus operator
int magic = rand() % 10000 + 1;
Seed once.
and also limit the range of your magic numbers using the modulus operator
I seed once at the start, when assigning magic numbers in OnInit. But I'm asking if I am able to seed repeatedly to find what the magic numbers were from previous days, so that I can compare my order history.
I don't want truly random for my magic numbers, I want predictably pseudo-random, so that if EA is restarted midday, it assigns the same number from rand().
You don't want random numbers at all! You want one, so you can identify the EAs trades from other EAs and manual trading. PERIOD!
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
I seed once at the start, when assigning magic numbers in OnInit. But I'm asking if I am able to seed repeatedly to find what the magic numbers were from previous days, so that I can compare my order history.
I don't want truly random for my magic numbers, I want predictably pseudo-random, so that if EA is restarted midday, it assigns the same number from rand().
Like Mr. whroeder says, that is a dead end strategy (wrong use of magic numbers). Just talking about random numbers, however, you only seed once and call rand for a random number.
My EA trades all pairs from single chart (where chart symbol and TF are irrelevant because it checks indicators from specified pairs/timeframes). All trades are opened and closed within the same (server) calendar day. And with all due respect, it is my prerogative to decide how I want to assign magic numbers, whether others believe it to be best practice or not. Alas, I'm only straying further away from my original question, now.
So, if anyone could help me to answer my original question: Can I reseed with MathSrand() repeatedly as I explained above, or will this somehow cause problems with the predictability of rand() for specific seeds?
EDIT:Solved. Thank you
Correct me when I am wrong, but I think you do need unique numbers instead of random numbers.
Why not use 20180212 for todays magic, and tomorrow 20180213 ?
My EA trades all pairs from single chart (where chart symbol and TF are irrelevant because it checks indicators from specified pairs/timeframes). All trades are opened and closed within the same (server) calendar day. And with all due respect, it is my prerogative to decide how I want to assign magic numbers, whether others believe it to be best practice or not. Alas, I'm only straying further away from my original question, now.
So, if anyone could help me to answer my original question: Can I reseed with MathSrand() repeatedly as I explained above, or will this somehow cause problems with the predictability of rand() for specific seeds?
EDIT:Solved. Thank you
You want an answer but you are not ready to explain why you need it, and once your problem is solved you don't even say how ?
I am afraid you will not have much help in the future with such attitude.
if you seed with the same seed then the sequence of pseudo generated numbers will be identical.
as you know in cyberspace nothing is truly random; it does not exist.
You want an answer but you are not ready to explain why you need it, and once your problem is solved you don't even say how ?
I am afraid you will not have much help in the future with such attitude.
Sorry. I didn't mean to come across as being rude. I was a little agitated because I felt the discussion was changing directions away from what my true issue was, and I see that affected my response.
The reason for my question was because if I'm making an EA I plan to share, I know some people that use it will have concerns about brokers tracking their trades, and wanted to provide as many options as possible for users to tailor their usage of the EA to their own personal needs. I know it may seem like a petty concern, but I'm just trying to be as comprehensive as possible and give options to everyone for their preference. I was trying to create a way where every day would give a new pseudo-random number for a magic number. But I also wanted to provide the option for a report printing of previous X days trading, and to do that I know I would need to include some functions for the EA to replicate the magic number from those previous days.
Embarrassingly enough, I solved the issue myself by writing a test EA. This idea didn't come to me at first, because my habits were to read as much as I could before actually trying something. I left the short answer "Solved thank you" because my face was a little flush and I wanted to just kinda make the thread go away. I hope anyone that I offended can forgive me, and I appreciate that you were all willing to come to this thread to address my question.
Sincerest regards.
For sake of posterity, here is the code I used to find my answer:
int OnInit() { //--- MakeNumbers(); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void MakeNumbers() { int day_count=15; for(int k=0;k<day_count;k++) { datetime day_history=TimeCurrent()-(86400*k); Tester(day_history); } } //+------------------------------------------------------------------+ void Tester(datetime day) { int d=TimeDay(day), m=TimeMonth(day), a=(int)AccountInfoInteger(ACCOUNT_LOGIN); srand(d+m+a); int random1=rand(); int random2=rand(); int random3=rand(); Print(day," ",random1," ",random2," ",random3); } //+------------------------------------------------------------------+
That is because you refused to answer the question "why do you think you need a random number." That answer is your true issue. I answered your question (#3) that you do not want random MNs (which you ignored,) and others also asked (which you refuse to answer, and insist on your way.)
If you use any random sequence, then on a terminal restart, you will have a new MN and loose connection with any open orders. #6 is wrong the moment you hold an order overnight . All you've done is alienate those trying to help you and your "solution" will cost you.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I use current month+ current day+account number as a seed for MathSrand() to generate a pseudo-random magic number each day. I would want to be able to look at trade history and create a report of all trades that hit SL (for example), so I would want to get a new seed for each day in history to be able to find all trades created by this EA. Would something like this work?
I didn't compile it, sorry if there is error. Just want to give an idea to you of how many times I would want to reseed (if reseeding if possible) to find the predictable pseudorandom magic numbers from historic dates when calling rand(). FindOurOrders() would only be called from a CHARTEVENT_OBJECT_CLICK, so it would run very infrequently.