Error Timing

To add comments, please log in or register
banlieu451
73
banlieu451  

Hello my friends how are you ?


I have a pb on MT4 ...

When i choose timefram : M1 

& Candlestick bullsih or bearish 


I don't see the new candle every minute > At 17.00.001 & 17.01.001 & 17.02.001,  i need look the new candle appear but sometime i need wait more 10 secondes for the new candle appear

So my friends, my question is please, how can i look every minutes the news candle appear ? 


I have EA an my EA open trade normaly at 17.00.00 but when i use MT4, ea can't open order because the new "POINT" on the timeframe don't appear exactly at 17.00.001 sometimes after 10 seconde or more 

I thinks the graphics is in TICKS & not in TIME ...

Look my connection ... maybe ?


You can look 2 Screenshot of my pb ...



Files:
Fernando Carreiro
4711
Fernando Carreiro  
banlieu451:

Hello my friends how are you ?


I have a pb on MT4 ...

When i choose timefram : M1 

& Candlestick bullsih or bearish

I don't see the new candle every minute > At 17.00.001 & 17.01.001 & 17.02.001,  i need look the new candle appear but sometime i need wait more 10 secondes for the new candle appear

So my friends, my question is please, how can i look every minutes the news candle appear ?

I have EA an my EA open trade normaly at 17.00.00 but when i use MT4, ea can't open order because the new "POINT" on the timeframe don't appear exactly at 17.00.001 sometimes after 10 seconde or more 

I thinks the graphics is in TICKS & not in TIME ...

Look my connection ... maybe ?

You can look 2 Screenshot of my pb ...

That is absolutely normal! If there is no trading activity taking place then obviously no M1 bar will be formed. Also, a trade can easily take place 30 sec into the minute or even 59 seconds into the minute. There is no "rule" that says that there HAS to be trading activity during every second of the day.

banlieu451
73
banlieu451  
Fernando Carreiro:

That is absolutely normal! If there is no trading activity taking place then obviously no M1 bar will be formed. Also, a trade can easily take place 30 sec into the minute or even 59 seconds into the minute. There is no "rule" that says that there HAS to be trading activity during every second of the day.

Thanks for reply !


Yes its normal but its sure there is a way to show new candle "if no activity" "if price don't change" the next candle need appear but don't move up or down but need appear ..


If someone always use IQ.OPTION in this plateform you can look the new candle appear every minutes & the bar appear despite pricing don't move 

Fernando Carreiro
4711
Fernando Carreiro  
banlieu451:

Thanks for reply !

Yes its normal but its sure there is a way to show new candle "if no activity" "if price don't change" the next candle need appear but don't move up or down but need appear ..

If someone always use IQ.OPTION in this plateform you can look the new candle appear every minutes & the bar appear despite pricing don't move 

How do you want a new bar to form if no new trade takes place and a no new tick comes in?

Such a new bar would be a "fake" bar. Why would you want that if nothing needs to happen?

banlieu451
73
banlieu451  
Fernando Carreiro:

How do you want a new bar to form if no new trade takes place and a no new tick comes in?

Such a new bar would be a "fake" bar. Why would you want that if nothing needs to happen?

Exactly that i want a "fake bar" but not really fake because price always exist but don't moove .. 


Because my trade duration is 1 minute and i don't want edging trade !

So if start at 17.00.01 its good because finish at 17.01.01


But if (candle & so trade) open at 17.00.22 next trade can't be open because not at the good time (finish at 17.01.22)

banlieu451
73
banlieu451  

So how input "fake" linear or bar like you want if somebody know ...

On mt4 for look a new linear or bar formed every minutes ...

Fernando Carreiro
4711
Fernando Carreiro  

banlieu451: Exactly that i want a "fake bar" but not really fake because price always exist but don't moove .. 

Because my trade duration is 1 minute and i don't want edging trade !

So if start at 17.00.01 its good because finish at 17.01.01

But if (candle & so trade) open at 17.00.22 next trade can't be open because not at the good time (finish at 17.01.22)

Then use the OnTimer() event handler, set to 1 minute intervals, so that you can place your order even when no new ticks arrive.

Event Handling Functions - Functions - Language Basics - MQL4 Reference
Event Handling Functions - Functions - Language Basics - MQL4 Reference
  • docs.mql4.com
The MQL4 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL4 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
banlieu451
73
banlieu451  
Fernando Carreiro:

Then use the OnTimer() event handler, set to 1 minute intervals, so that you can place your order even when no new ticks arrive.

OMG i try during 5 hours its so hard to do always error how just add please


Ontimer


at time 12h00m00s & repeat every minute ?


Sincerely

Fernando Carreiro
4711
Fernando Carreiro  
banlieu451: OMG i try during 5 hours its so hard to do always error how just add please Ontimer at time 12h00m00s & repeat every minute?
How do you expect us to know what you are doing wrong if you don't show your code?
banlieu451
73
banlieu451  
Fernando Carreiro:
How do you expect us to know what you are doing wrong if you don't show your code?

lol ^^


//+------------------------------------------------------------------+
//|                                                  Strategy: A.mq4 |
//|                                       Created with EABuilder.com |
//|                                             http://eabuilder.com |
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link      "http://eabuilder.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

int LotDigits; //initialized in OnInit
int MagicNumber = 565541;
extern double TradeSize = 0.1;
int MaxSlippage = 0; //adjusted in OnInit
int MaxOpenTrades = 1;
int MaxLongTrades = 1000;
int MaxShortTrades = 1000;
int MaxPendingOrders = 1000;
bool Hedging = false;
int OrderRetry = 5; //# of retries if sending order returns error
int OrderWait = 5; //# of seconds to wait if sending order returns error
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | A @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

int TradesCount(int type) //returns # of open trades for order type, current symbol and magic number
  {
   int result = 0;
   int total = OrdersTotal();
   for(int i = 0; i < total; i++)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) continue;
      if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue;
      result++;
     }
   return(result);
  }

int myOrderSend(int type, double price, double volume, string ordername) //send order, return ticket ("price" is irrelevant for market orders)
  {
   if(!IsTradeAllowed()) return(-1);
   int ticket = -1;
   int retries = 0;
   int err;
   int long_trades = TradesCount(OP_BUY);
   int short_trades = TradesCount(OP_SELL);
   int long_pending = TradesCount(OP_BUYLIMIT) + TradesCount(OP_BUYSTOP);
   int short_pending = TradesCount(OP_SELLLIMIT) + TradesCount(OP_SELLSTOP);
   string ordername_ = ordername;
   if(ordername != "")
      ordername_ = "("+ordername+")";
   //test Hedging
   if(!Hedging && ((type % 2 == 0 && short_trades + short_pending > 0) || (type % 2 == 1 && long_trades + long_pending > 0)))
     {
      myAlert("print", "Order"+ordername_+" not sent, hedging not allowed");
      return(-1);
     }
   //test maximum trades
   if((type % 2 == 0 && long_trades >= MaxLongTrades)
   || (type % 2 == 1 && short_trades >= MaxShortTrades)
   || (long_trades + short_trades >= MaxOpenTrades)
   || (type > 1 && long_pending + short_pending >= MaxPendingOrders))
     {
      myAlert("print", "Order"+ordername_+" not sent, maximum reached");
      return(-1);
     }
   //prepare to send order
   while(IsTradeContextBusy()) Sleep(100);
   RefreshRates();
   if(type == OP_BUY)
      price = Ask;
   else if(type == OP_SELL)
      price = Bid;
   else if(price < 0) //invalid price for pending order
     {
      myAlert("order", "Order"+ordername_+" not sent, invalid price for pending order");
          return(-1);
     }
   int clr = (type % 2 == 1) ? clrRed : clrBlue;
   while(ticket < 0 && retries < OrderRetry+1)
     {
      ticket = OrderSend(Symbol(), type, NormalizeDouble(volume, LotDigits), NormalizeDouble(price, Digits()), MaxSlippage, 0, 0, ordername, MagicNumber, 0, clr);
      if(ticket < 0)
        {
         err = GetLastError();
         myAlert("print", "OrderSend"+ordername_+" error #"+err+" "+ErrorDescription(err));
         Sleep(OrderWait*1000);
        }
      retries++;
     }
   if(ticket < 0)
     {
      myAlert("error", "OrderSend"+ordername_+" failed "+(OrderRetry+1)+" times; error #"+err+" "+ErrorDescription(err));
      return(-1);
     }
   string typestr[6] = {"Buy", "Sell", "Buy Limit", "Sell Limit", "Buy Stop", "Sell Stop"};
   myAlert("order", "Order sent"+ordername_+": "+typestr[type]+" "+Symbol()+" Magic #"+MagicNumber);
   return(ticket);
  }

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {   
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
      MaxSlippage *= 10;
     }
   //initialize LotDigits
   double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
   if(LotStep >= 1) LotDigits = 0;
   else if(LotStep >= 0.1) LotDigits = 1;
   else if(LotStep >= 0.01) LotDigits = 2;
   else LotDigits = 3;
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int ticket = -1;
   double price;   
   
   
   //Open Buy Order
   if(iOpen(NULL, PERIOD_M1, 9) > iClose(NULL, PERIOD_M1, 9) //Candlestick Open > Candlestick Close
   )
     {
      RefreshRates();
      price = Ask;   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_BUY, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
     }
   
   //Open Sell Order
   if(iOpen(NULL, PERIOD_M1, 9) < iClose(NULL, PERIOD_M1, 9) //Candlestick Open < Candlestick Close
   )
     {
      RefreshRates();
      price = Bid;   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_SELL, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
     }
  }

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
Fernando Carreiro
4711
Fernando Carreiro  
banlieu451: lol ^^

Well .. where is it?

How to do you expect it to work when the OnTimer() handler is empty and you don't even set the Event Timer anywhere in your code?

Did you even read the documentation for which I provided the link?

12
To add comments, please log in or register