Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Views:
1273
Rating:
(17)
Published:
2025.04.04 10:53
MA Trend 2.mq5 (78.03 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Development of the first version of MA Trend - added Type traiding restriction parameter:

  • Only BUY - allowed to open only BUY
  • Only SELL - it is allowed to open only SELL
  • BUY and SELL - it is allowed to open both BUY and SELL.

The Expert Advisor works according to the iMA (Moving Average, MA) indicator. It has many settings:

  • Only one positions -only one position can be held in the market
  • Reverse - reverse (flip) trading signals
  • Close opposite - forced closing of opposite positions when a trading signal is received.

Formation of trading signals when all parameters are set by default:

Current ASK price is higher than the indicator value on bar #1 -> signal to open BUY position

Current BID price is less than the indicator value on bar #1 -> signal to open a SELL position.

and how it looks like in MQL5 code:

      if(m_symbol.Ask()>ma[1])
         m_need_open_buy=true;
      else if(m_symbol.Bid()<ma[1])
         m_need_open_sell=true;


Example of operation when Only one positions parameters are false and true:

MA Trend


The following example Only one positions - true, Reverse - false and Close opposite - true: a BUY position was opened, after some time a signal to open SELL position was received. Since Close opposite is true, the BUY position was closed first (because it is opposite to the signal) and only then the SELL position was opened.

MA Trend


Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/23632

Back kick Back kick

Algorithm cycle: when there are no open positions, open two opposite positions. Wait for both positions to close.

New Candle or Bar formation. New Candle or Bar formation.

This Bot detects the open of a new candle on any set timeframe, thereby making it easier to run a one-time code, place trades and call other functions. The code is written in the OnTick() function.

Pan PrizMA No leverage 72 Pan PrizMA No leverage 72

Construct a moving line with a polynomial of 4 degrees. Extrapolates the sinusoidal and its axial. The constructed lines remove one value at each bar and a sliding line of extrapolated values is constructed which is not redrawn.

MultiTester MultiTester

Multiple runs/optimisations in Tester.