Should I do this, or should I do that? With which probability?

 

Should I do this or should I not?..

If you are able to quantify the probability of a particular event you can rely on random numbers to take decisions. Here goes a coin toss example where you can decide the probability (from 0 to 100)  to get heads. You can add the following method to the class CBrain explained in the article Another MQL5 OOP class. Let's recall that CBrain may be the core of an object-oriented EA where you put things that determine its behavior.

Just an idea. Greetings!

//+--------------------------------------------------------------------------------+
//| Flips a coin, expecting to get the given result with the given probability.    |
//+--------------------------------------------------------------------------------+
   
int CBrain::FlipCoin(int result, int probability)
   {
      int head = 0;
      int tails = 1;      
      int coin, nonResult;
      int randomNumber = GetRandomNumber(0, 100);
      
      if(result == 0) nonResult = 1; else nonResult = 0;
           
      if(probability <= randomNumber) coin = result; else coin = nonResult;
               
      return coin;
   }
 
laplacianlab:

Should I do this or should I not?..

If you are able to quantify the probability of a particular event you can rely on random numbers to take decisions. Here goes a coin toss example where you can decide the probability (from 0 to 100)  to get heads. You can add the following method to the class CBrain explained in the article Another MQL5 OOP class. Let's recall that CBrain may be the core of an object-oriented EA where you put things that determine its behavior.

Just an idea. Greetings!

It would have been better to post this in the topic about your article, not ?
 
angevoyageur:
It would have been better to post this in the topic about your article, not ?

You're right, thanks for the tip. I'll do that next time .. 

Just make a quick note, better to work with short types instead of int types if this method is intended only to flip a coin, I mean f there are only two events (head or tails) then let's consume as less memory as we can. This way the computer consumes less memory.