Watch how to download trading robots for free
Find us on Twitter!
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:
7850
Rating:
(23)
Published:
2012.02.13 07:53
Updated:
2016.11.22 07:32
\MQL5\Include\
isnewbar.mqh (1.41 KB) view
\MQL5\Experts\
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

СIsNewBar class is necessary for the efficient work of the Expert Advisors that make calculations at the moment the new bar appears.

Usually IsNewBar() function is used for such things instead of a class. But such a function contains a static variable, and therefore we cannot use several calls of this function. To be able to reuse such function repeatedly in Expert Advisor's code, it would be much easier to make it a class member. In this case that has been accomplished using IsNewBar.mqh.

The library code should be included in the file content on the global level using #include directive:

#include <IsNewBar.mqh>

Then, the required number of СIsNewBar class variables must be declared in OnTick() block of the Expert Advisor:

static CIsNewBar NB1,NB2;

After that we can make calls to IsNewBar() functions

bool IsNewBar(string symbol,            // currency symbol
              ENUM_TIMEFRAMES timeframe)// calculation chart timeframe

in the Expert Advisor code:

if(NB1.IsNewBar(Symbol(),PERIOD_D1)) // checking for a new bar
     {
      /* Here is a trading signal 1 receiving block code */
     }

Here is the possible example of the code that includes СIsNewBar class inside OnTick() function:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//----

   double iClose1[1],iClose2[1];
//---- declaration of static variables
   static bool Recount1=true,Recount2=true;
   static CIsNewBar NB1,NB2;

//+----------------------------------------------+
//| Detecting market entry signals               |
//+----------------------------------------------+
   if(NB1.IsNewBar(Symbol(),PERIOD_D1) || Recount1) // checking for a new bar
     {
      Recount1=false;
      
      //---- copy newly appeared data in the arrays
      if(CopyClose(Symbol(),PERIOD_D1,1,1,iClose1)<=0) {Recount1=true; return;}
      
      /* Here is a trading signal 1 receiving block code */
      
     }
     
   if(NB2.IsNewBar(Symbol(),PERIOD_H4) || Recount2) // checking for a new bar
     {
      Recount2=false;
      
      //---- copy newly appeared data in the arrays
      if(CopyClose(Symbol(),PERIOD_H4,1,1,iClose2)<=0) {Recount2=true; return;}
      
      /* Here is a trading signal 2 receiving block code */
      
     }

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

i-Fractals-sig i-Fractals-sig

The indicator of the market entry signals using fractals.

Forecast Oscillator Forecast Oscillator

Normalized oscillator provided by the signal line and colored dots for making deals.

TrendTriggerMod TrendTriggerMod

The indicator displays trend power and direction.

Fx10 Fx10

The semaphore signal indicator with the values based on five technical indicators: LWMA, SMA, RSI, Stochastic, MACD.