How do I to automatically refresh or update the Expert Advisor attached on chart? (like F7 and Enter)

 

Hi,

I have an expert advisor running on an instance of Metatrader 4, and I want to refresh EA automatically (like F7 and Enter) on my time (like 1 hours or 2 hours)?

Any body have good idea? like Script or code to add to the EA?

Thank you all.


All the best,

Ali

 
Ali Malekli:

Hi,

I have an expert advisor running on an instance of Metatrader 4, and I want to refresh EA automatically (like F7 and Enter) on my time (like 1 hours or 2 hours)?

Any body have good idea? like Script or code to add to the EA?

Thank you all.


All the best,

Ali

Simply: I want to reinitialize expert every 1 hour.

I look for code to add to my expert

 
Ali Malekli:

Simply: I want to reinitialize expert every 1 hour.

I look for code to add to my expert

its possible


//+------------------------------------------------------------------+
//|                                                     60Mnutes.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
datetime prevtime;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    if(iTime(Symbol(),60,0)!= prevtime) 
     {
      prevtime = iTime(Symbol(),60,0);
      // Your Expert Code..
      
   }
  }
//+------------------------------------------------------------------+
 

Hello I know it's an old post, but maybe someone can help. what function would I need to enter so that instead of every 60 minutes, the EA would reload only when there are no open positions or after closing all positions and before opening a new one?

 
swiezak #: the EA would reload only when there are no open positions or after closing all positions
  1. There are no positions in MT4, only orders (opened or pending).

  2. Until you can state your requirements in concrete terms, it can not be coded. Do you really mean all orders, or orders on the current chart's symbol?

  3. Show us your code where you count orders, and I will show you how to test for zero.