Indicator from mt5 to mt4

Morten Kruse
Morten Kruse  

I'm transfering an indicator from MT5 to MT4.

But the OnCalculate is based on data array.



The function is called in the indicators when the Calculate event occurs for processing price data changes. There are two function types. Only one of them can be used within a single indicator.

Calculation based on data array

int  OnCalculate(
   const int        rates_total,       // price[] array size
   const int        prev_calculated,   // number of handled bars at the previous call
   const int        begin,             // index number in the price[] array meaningful data starts from
   const double&    price[]            // array of values for calculation

Is this possible to do in mt4? And how?

Br Morten

Documentation on MQL5: MQL5 programs / Client Terminal Events
Documentation on MQL5: MQL5 programs / Client Terminal Events
Immediately after the client terminal loads a program (an Expert Advisor or custom indicator) and starts the process of initialization of global variables, the Init event will be sent, which will be processed by OnInit() event handler, if there is such. This event is also generated after a financial instrument and/or chart timeframe is changed...
William Roeder
William Roeder  
Morten Kruse: Is this possible to do in mt4?

Do you see that form in the MT4 documentation? Event Handling Functions - Functions - Language Basics - MQL4 Reference

Keith Watford
Keith Watford  
Comments that do not relate to this topic, have been moved to "Off Topic Posts".
Sergey Golubev
Sergey Golubev  

Forum on trading, automated trading systems and testing trading strategies

My account is FIFO when people try to subsribe they get a message that i do not follow FIFO rules Please HELP

William Roeder, 2020.01.26 20:41

In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
  1. For non-FIFO (non-US brokers), (or the EA only opens one order per symbol,) you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
              Loops and Closing or Deleting Orders - MQL4 programming forum
    For In First Out (FIFO rules-US brokers,) and you (potentially) process multiple orders per symbol, you must find the earliest order, close it, and on a successful operation, reprocess all remaining positions.
              CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
              MetaTrader 5 platform beta build 2155: #1 № 11 ACCOUNT_FIFO_CLOSE

  2. and check OrderSelect in case earlier positions were deleted.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask) or (be direction independent and use) OrderClosePrice().

Since 2009, hedging is not permitted for US traders.
          NFA Enforces FIFO Rule, Bans Forex Hedging in US Forex Accounts - Trading Heroes
          FAQ: FIFO in the Forex Market -