Start time, end time

 

Hi guys,

I've had a problem. I've written EA, solved nearly all the problems. However I want it start trade from some hour to other:

<code removed, see below post>

It writes: 'return' - 'void' function returns a value.

I'm picking in it a week and don't have a clue what to do with it.

Could you help me?

 
safarmichal:

Hi guys,

I've had a problem. I've written EA, solved nearly all the problems. However I want it start trade from some hour to other:

...
Please edit your post and use SRC button when posting code.
 
void OnTick()
  {

 
   datetime tm=TimeCurrent();
   string str=TimeToString(tm,TIME_MINUTES);

   if(Start_time>str && str>End_time)  return(time=1);
    else return(time=0);
   
....
  }
Is that good now?
 
safarmichal:
Is that good now?

Unfortunately not. I asked you, politely, to EDIT your first post, not to add another one with the same content.

 

safarmichal:
Is that good now?

void OnTick()
  {

 
   datetime tm=TimeCurrent();
   string str=TimeToString(tm,TIME_MINUTES);

   if(Start_time>str && str>End_time)  return(time=1);
    else return(time=0);
   
.... 

  } 

The error message indicates that a "void" function (OnTick function has no return value) has some statements that "return" something (marked in the above code).

Where does the "time" variable come from and what is the purpose of the "return" statement?

If it is used to check the validity of time, you can write your code directly under the "if/else" statement and don't have to return some values. 

 
forex2start:

The error message indicates that a "void" function (OnTick function has no return value) has some statements that "return" something (marked in the above code).

Where does the "time" variable come from and what is the purpose of the "return" statement?

If it is used to check the validity of time, you can write your code directly under the "if/else" statement and don't have to return some values. 

//--- input parameters
#include <Trade\Trade.mqh>                                         //include the library for execution of trades
#include <Trade\PositionInfo.mqh>                                  //include the library for obtaining information on positions
#include <Trade\TimeSeries.mqh>                                    //include the library for obtaining information on bars

input double   Lot=0.1;
input double   Start_sell=0.0002;
input double   Start_buy=0.0002;
input double   Upper_shadow=0.001;
input double   Lower_shadow=0.001;
input datetime Start_time=D'3:00:00';
input datetime End_time=D'23:58:00';
input int      Stop_loss=0.002;
int            time;


CTrade            m_Trade;                                 //structure for execution of trades
CPositionInfo     m_Position;                              //structure for obtaining information of positions

....

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

 
   datetime tm=TimeCurrent();
   string str=TimeToString(tm,TIME_MINUTES);

   if(Start_time>str && str>End_time)  return(time=1);
    else return(time=0);
   
  
  if(time*(iHigh(0)-iOpen(0))>Upper_shadow && (iOpen(0)-iClose(0))>Start_sell);
     {
      if(m_Position.Select(_Symbol))
        {
         if(m_Position.PositionType()==POSITION_TYPE_BUY) return;
        }
      m_Trade.Sell(Lot,_Symbol);
     }

iHigh, iOpen, iClose, is set in Timeseries.mqh. The variable "time" is number. It should open positions after demanded time passes.

For example: The conditions for sell was met (there is upper_shadow more than 10pips and close price is lower than 2pips). However it is 2:00am - the time conditions wasn't met and the sell order can't be ordered.

If there is easier way to write it, tell me.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 
angevoyageur:

Unfortunately not. I asked you, politely, to EDIT your first post, not to add another one with the same content.

Sorry. I just didn't understand in what way to edit it.
 
safarmichal:
Sorry. I just didn't understand in what way to edit it.

It's probably too late now (old post can't be edited), not a big deal, you know it now.

You can edit your post by clicking Edit link placed on the bottom-right corner, when you move your mouse on your post.

 
safarmichal:

iHigh, iOpen, iClose, is set in Timeseries.mqh. The variable "time" is number. It should open positions after demanded time passes.

For example: The conditions for sell was met (there is upper_shadow more than 10pips and close price is lower than 2pips). However it is 2:00am - the time conditions wasn't met and the sell order can't be ordered.

If there is easier way to write it, tell me.

As already said by forex2start, you CAN NOT return a value in OnTick() event handler which is defined with void. Use this :

   if(Start_time>str && str>End_time) time=1;
   else time=0;

Anyway, I doubt this condition with strings will give you the expected result.

 
angevoyageur:

It's probably too late now (old post can't be edited), not a big deal, you know it now.

You can edit your post by clicking Edit link placed on the bottom-right corner, when you move your mouse on your post.

Like this . . .

 
RaptorUK:

Like this . . .

Thank you, I was too lazy to take a picture :-D
Reason: