Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Trading Strategy Heads or Tails - MetaTrader 4 Expert - MT4/MT5 Resources

author blogger | 400 reads | 0 comments |

Trading strategy Heads or Tails - expert for MetaTrader 4

Trading strategy Heads or Tails - expert for MetaTrader 4

The Heads or Tails trading strategy falls into the category of high-risk short-term trading methods primarily used in the stock market and the Forex market. Its name comes from the randomness of the decision, similar to flipping a coin ("heads" - buying an asset, "tails" - selling). This strategy is based entirely on intuitive decisions or random signals and ignores fundamental market analysis factors.

Trading strategy Heads or Tails - expert for MetaTrader 4

The strategy is structured as follows:

This strategy does not require a deep understanding of market mechanics and analysis, but it also does not imply a serious approach to risk management.

This strategy is more suitable for novice traders who want to familiarize themselves with the principles of the trading platform and try trading without in-depth knowledge of technical analysis. However, this strategy is rarely used by professionals, who prefer a scientific approach that takes into account price action, trading volume, and fundamental company indicators.

For experienced investors, this strategy represents more of an experimental approach to testing hypotheses than a stable way to make money.

So, although this strategy is simple and suitable for every beginner, it carries huge risks and has virtually no chance of generating long-term sustainable income.

 if ((b + s) == 0 ) // if there is no active position

Here the condition is checked that there is no open position. Variable b represents the number of long ("buy") positions, variable s — the number of short ("sell") positions. If the sum of the two is zero (b + s = 0), it means that there is not a single open position.

 if (:: mathematical rand ()% 2 == 0 ) // Randomly select the direction of opening a position

Within the previously triggered conditional block, check for a random number. The ::MathRand() function generates a pseudo-random number from 0 to 32767 (inclusive). That number is then divided by 2 modulo (% 2) — if the remainder is 0, the next block is executed.

 //Send a buy order with specified parameters ticket = orderSend ( symbol (),OP_BUY,iStartLots,ask,iSlippage,
                  Query - iStopLoss * _View , // Stop loss price (current selling price minus stop loss distance) Query + iTakeProfit * _View , // Take profit price (current selling price plus take profit distance) "VR heads or tails" , // Order comments iMagicNumber, 0 , clear blue ); // MagicNumber, expiration time, blue arrow color 
// Determine whether the order is successful if (ticket < 0 )
Print ( "Order sending failed, error # occurred" , get the last error ()); // Error message and other print ( "OrderSend function has been successfully completed" ); // Success message
return ;

If the random number is an even number (the remainder after dividing by 2 is equal to 0), the trading robot will open a long position (buy) with a trading volume of iLots. After a position is successfully opened, function execution is interrupted by the return operator.

 //Send a sell order with specified parameters ticket = orderSend ( symbol (),OP_SELL,iStartLots,bid,iSlippage,
                  Bid + i Stop Loss* _View , // Stop loss price (current bid price plus stop loss distance) Bid - iTakeProfit * _View , // Take profit price (current bid price minus take profit distance) "VR heads or tails" , // order comments iMagicNumber, 0 , red blood cells ); // MagicNumber, expiration time, red arrow color 
// Determine whether the order is successful if (ticket < 0 )
Print ( "Order sending failed, error # occurred" , get the last error ()); // Error message and other print ( "OrderSend function has been successfully completed" ); // Success message
return ;

If the random number is odd (remainder after division by 2 is not zero), a position (sell) is opened with a volume of iLots and further execution of the function is terminated.

Therefore, this code is a simple example of an algorithm that randomly decides to open a market position.


Attachment download

📎 VR_Heads_or_Tails.mq4 (6.04 KB)

Source: MQL5 #68251

Refresh