The trading strategy “Head or Tail” belongs to the category of high-risk short-term trading approaches, primarily used on the stock market and Forex. Its name is due to the randomness of decision-making, similar to flipping a coin (“heads” — buy an asset, “tails” — sell). This strategy is based solely on intuitive decisions or random signals and ignores fundamental market analysis factors.

The strategy operates as follows:
This strategy does not require a deep understanding of market mechanisms and analytics, but it also does not involve a serious approach to risk management.
This strategy is more suitable for beginners who want to familiarize themselves with the principles of exchange platforms and try trading without deep knowledge of technical analysis. However, professionals rarely use this strategy, preferring scientifically based approaches that take into account price behavior, trading volume, and fundamental company indicators.
For experienced investors, this strategy represents more of an experimental method for testing hypotheses rather than a stable way to earn money.
Thus, although the strategy is simple and accessible to every beginner, it carries significant risks and has almost no chance of providing stable income in the long term.
if((b + s) == 0) // If there are no active positions
Here, the condition checks for the absence of open positions. Variable b represents the number of long ("buy") positions, and variable s represents the number of short ("sell") positions. If the sum of both is zero (b + s = 0), it means there are no open positions.
if(::MathRand() % 2 == 0) // Randomly choosing the direction of opening a position
Inside the previous block, a random number is checked. The function ::MathRand() generates a pseudo-random number from 0 to 32767 inclusive. This number is then divided by 2 (% 2) — if the remainder is 0, the next block is executed.
{ if(trade.Buy(lt)) // Opening a long position (BUY) return; // Terminating function execution }
If the random number is even (remainder of division by 2 is 0), the trading robot opens a long position (purchase) with a volume of iLots. After successfully opening the position, the function execution is interrupted by the return operator.
else // Otherwise... if(trade.Sell(lt)) // Opening a short position (SELL) return; // Terminating function execution
If the random number was odd (remainder of division by 2 is not zero), a short position (sale) with a volume of iLots is opened, and further execution of the function is also terminated.
Thus, this code represents the simplest example of an algorithm that makes a decision to open a position on the market randomly.
For a detailed line-by-line analysis of the code, you can visit the blog post: /en/blogs/post/766912
Translated from Russian by MetaQuotes Ltd.
Original code: /ru/code/11637
RiskSizer Panel Lite MT5 - Risk Percent Lot Calculator With One Click Buy Sell
RiskSizer Panel Lite is a simple MT5 trading panel that calculates an estimated lot size based on your risk percent. Drag two chart lines to set SL/TP, then use one-click BUY/SELL for fast manual execution.
Log
Multi-Mode Logarithmic Transform Indicator.
SuperTrend Quant Pro Elite: Adaptive Statistical Trend Engine
An advanced, institutional-grade trend-following engine using Z-Score adaptive volatility, smart money volume filters, and a real-time MTF dashboard.
Position Size Pro Lite: Interactive Risk Calculator Panel
A professional on-chart panel for instant lot size and risk calculation. Essential for manual traders using strict risk management.