Does someone could explain difference between eachtick and complete bar ?

 

Hi,

Does someone could explain the difference between EachTick and Complete bar ? My ea entrance is always too late .

Here the part of the code when I enter long :

previous close > SMA 20 & RSI(25)>70

double EnterLong1_1 = iClose(NULL, 0, Current + 0);
double EnterLong1_2 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
double EnterLong2_1 = iRSI(NULL, 0, 25, PRICE_CLOSE, Current + 0);
double EnterLong2_2 = 70;

//+------------------------------------------------------------------+
//| Enter Long Signal |
//+------------------------------------------------------------------+

if (EnterLong1_1 > EnterLong1_2 && EnterLong2_1 > EnterLong2_2 ) Order = SIGNAL_BUY;

if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);

Thanks for your help

Joe


 

Looks like EachTick and Complete Bar are parameters in the above EA. But in general :
The latest Completed Bar is Bar indexed 1. The current Unfinished Bar is Bar indexed 0.
if you check your signal condition at shift/index 0; then it will keep getting checked while the bar has not closed.
Checking only once at bar close (new bar open) is more efficient/reasonable.
hth.

 

Hi Cameofx,

Thanks for your fast answer !

How to check only once at bar close ?

Do you think it is better to formulate enter long signal in the following way ?

//+------------------------------------------------------------------+
//| Enter Long Signal |
//+------------------------------------------------------------------+

if (close[1] > EnterLong1_2 && EnterLong2_1 > EnterLong2_2 ) Order = SIGNAL_BUY;

Thanks

 
joebaatan wrote >>

Hi Cameofx,

Thanks for your fast answer !

How to check only once at bar close ?

Do you think it is better to formulate enter long signal in the following way ?

//+------------------------------------------------------------------+
//| Enter Long Signal |
//+------------------------------------------------------------------+

if (close[1] > EnterLong1_2 && EnterLong2_1 > EnterLong2_2 ) Order = SIGNAL_BUY;

Thanks


That should work as
Close[1];
is for the recent completed bar.
 

Joe, Checking for new bar has been asked many times. Next time search & learn from posts before you ask...

// previous close > SMA 20 & RSI(25)>70

double EnterLong1_1 = iClose(NULL, 0, 1);
double EnterLong1_2 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 1); // all shifts parameter are at Bar 1
double EnterLong2_1 = iRSI(NULL, 0, 25, PRICE_CLOSE, 1);
double EnterLong2_2 = 70;
static datetime last_Time; // declared at global level

bool Is_New_Bar() // func to check for new bar arrival
{
  if(last_Time != Time[0]) {last_Time = Time[0]; return(true); }
}

//+------------------------------------------------------------------+
//| Enter Long Signal |
//+------------------------------------------------------------------+

if( Is_New_Bar() ) // only checking once at close of bar
{
  Alert (" Closing of previous ", TimeToStr(Time[1])," Bar ! Checking if Order criteria is met ");
  if (EnterLong1_1 > EnterLong1_2 && EnterLong2_1 > EnterLong2_2 ) Order = SIGNAL_BUY;
}
 
cameofx wrote >>

Joe, Checking for new bar has been asked many times. Next time search & learn from posts before you ask...


Hi again,

Next time I will do it, promise.

Many thanks for your contribution, I test and I let you know.

Thanks again !!

Joe

 

Hi again,

I tried to implement it but there is the following message :

Thanks for your help.

Joe

 
Your problem is somewhere before this function. Please post all of your code (either using the SRC button or by attaching the mq4 file).
 
joebaatan wrote >>

Hi again,

I tried to implement it but there is the following message :

Thanks for your help.

Joe


Here is the complete ea program I started to implement

define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 0.5;
extern int Slippage = 0;
extern bool UseStopLoss = False;
extern int StopLoss = 30;
extern bool UseTakeProfit = False;
extern int TakeProfit = 60;
extern bool UseTrailingStop = False;
extern int TrailingStop = 30;

static datetime last_Time; // declared at global level

int BarCount;
int Current;
bool TickCheck = False;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;

if (EachTickMode) Current = 0; else Current = 1;

return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()

//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+

double Var1 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 1);// all shifts parameter are at Bar 1
double Var2 = iRSI(NULL, 0, 25, PRICE_CLOSE, 1);
double Var3 = iClose(NULL, 0, 1);

double Buy1_1 = Var3 ;
double Buy1_2 = Var1 ;
double Buy2_1 = Var2 ;
double Buy2_2 = 70;
double Sell1_1 = Var3 ;
double Sell1_2 = Var1 ;
double Sell2_1 = Var2 ;
double Sell2_2 =70;
double CloseBuy1_1 = Var3 ;
double CloseBuy1_2 = Var1 ;
double CloseSell1_1 = Var3 ;
double CloseSell1_2 = Var1 ;

static datetime last_Time; // declared at global level

bool Is_New_Bar() // func to check for new bar arrival
{
if(last_Time != Time[0]) {last_Time = Time[0]; return(true); }
}


//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+

//Check position
bool IsTrade = False;

for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close

//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+

if (CloseBuy1_1 < CloseBuy1_2) Order = SIGNAL_CLOSEBUY;


//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+

if (CloseSell1_1 > CloseSell1_2) Order = SIGNAL_CLOSESELL;

//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+

if( Is_New_Bar() ) // only checking once at close of bar
{
Alert (" Closing of previous ", TimeToStr(Time[1])," Bar ! Checking if Order criteria is met ");


if (Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;

if (Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;

 
gordon:
Your problem is somewhere before this function. Please post all of your code (either using the SRC button or by attaching the mq4 file).
Joe, please do the above. In this case, since the code is relatively long, please attach it as a mq4 file.
 
gordon wrote >>
Joe, please do the above. In this case, since the code is relatively long, please attach it as a mq4 file.

Here is the file.
Files:
mql4xfile.mq4  5 kb
Reason: