my code does not work...please help

 
my code works in strategy tester but does not work in live...Please assist



//+------------------------------------------------------------------+
//|                                                     t2018_21.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
bool New_Bar=false;
double Ask;
int lastBar;

string time_curr_s;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   lastBar= Bars(_Symbol,_Period);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
      Fun_New_Bar();
          if (New_Bar==false)
             return;
  }
//+------------------------------------------------------------------+

//=TimeCurrent();
//string str1="Date and time with minutes: "+TimeToString(tm);

void Fun_New_Bar()
{
New_Bar=false;
 if (Bars(_Symbol,_Period) >lastBar)
      {
      New_Bar=true;
      time_curr_s=TimeToString(TimeCurrent());
      lastBar=Bars(_Symbol,_Period);
      Alert ("New bar");
      Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      ObjectCreate(0,"Label1",OBJ_LABEL,0,0,0);
      ObjectSetString(0,"Label1",OBJPROP_FONT,"Arial");
      ObjectSetInteger(0,"Label1",OBJPROP_FONTSIZE,24);
      ObjectSetString(0,"Label1",OBJPROP_TEXT,0,"Ask Price : "+DoubleToString(Ask,8)+" " + time_curr_s);
      ObjectSetInteger(0,"Label1",OBJPROP_XDISTANCE,5);
      ObjectSetInteger(0,"Label1",OBJPROP_YDISTANCE,10);
      }     
      
      
}
 
Bars is not a reliable way to detect new bar. It has been stated a zillion times on the forum, please do some search before posting.
 
Alain Verleyen:
Bars is not a reliable way to detect new bar. It has been stated a zillion times on the forum, please do some search before posting.
what is a better way...please advise
 
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          New candle - MQL4 and MetaTrader 4 - MQL4 programming forum
 
This code works in real time
//+------------------------------------------------------------------+
//|                                                     t2018_21.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
datetime New_Time=0;
bool New_Bar=false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
      Fun_New_Bar();
          if (New_Bar==false)
             return;
  }
//+------------------------------------------------------------------+

void Fun_New_Bar()
{
New_Bar=false;
datetime ThisBar = (datetime)SeriesInfoInteger(_Symbol,PERIOD_CURRENT,SERIES_LASTBAR_DATE);
 if (New_Time !=ThisBar)
      {
      New_Bar=true;
          Alert ("New bar");
      New_Time = ThisBar;
    
      }     
      
      
}
 
Hi can anyone flash with the EA code, so before opening a trade he was waiting for a confirmation for opening an order and when the situation sent a push notification ...
 
farhat1986: can anyone flash with the EA code
  1. Don't hijack other threads with your off topic posts.

  2. Don't double post!
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  3. farhat1986: i can anyone flash with the EA code,...
    dThe Flash?

    1. Search for it,
    2. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
    3. Beg at Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum or Need help with coding - General - MQL5 programming forum or Free MQL4 To MQL5 Converter - General - MQL5 programming forum or Requests & Ideas (MQL5 only!),
    4. or pay (Freelance) someone to code it.
    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help
              urgent help.
Reason: