resting the expert after got stoploss

 

hey guys happy new year

i had reads a lot of topics about something like pause or rest or skip or etc.

for expert when it takes stoploss expert don't work or don't trade for a time that we want

so i tried to code something like datetime function

but i don't know i code it wrong or it didn't worked for me!!!!

then i want choose sleep() function but i find out this function doesn't work in strategy tester

my question is can i trust this function ???? when my expert got loss sleep for 10 minute ???

other way i can say it will skip candles for trading



best regards

 

Hi,


Sure, you can, in fact it is very simple to do. I'm not sure if you are using mql5 or mql4, but, in mql5, Sleep() does work in backtest, here are the documentaions:

Mql5: https://www.mql5.com/pt/docs/common/sleep

Mql4: https://docs.mql4.com/common/sleep


You can see that on the mql4 link, there is a note " Sleep() function does not suspend execution of the Expert Advisor in the Strategy Tester."

You also asked if you could trust Sleep() function, in the documentation linked above, you will see in the description that if you use this function that means that your code is entirely stoped for the specified time in seconds. Although , note that the SL an TP are on the server so, if the price hit any of them, even your code being stopped, they will be triggered .


With these details in mind, if you are using mql4, you can do it by checking the time with TimeCurrent(). All you need to do is to code it in a way that verify if it has already passed 10 minutes.


Hope I could help :-)



Documentação sobre MQL5: Funções Comuns / Sleep
Documentação sobre MQL5: Funções Comuns / Sleep
  • www.mql5.com
Sleep - Funções Comuns - Referência MQL5 - Referência sobre algorítimo/automatização de negociação na linguagem para MetaTrader 5
 
You can use 
iTime()

Record the bar open time of the M1 bar when you open the trade, then when the trade is closed you monitor as much M1 bars as you need for a pause.

Of course you can also use larger bars like H1 for 1 Hour pause and etc.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Marco vd Heijden:
You can use 

Record the bar open time of the M1 bar when you open the trade, then when the trade is closed you monitor as much M1 bars as you need for a pause.

Of course you can also use larger bars like H1 for 1 Hour pause and etc.

thank you dear marco

please tell me more about this function

when i started to learn mql datetime function was Unkown for me cuz i cant understand it very well 

 
bhjks_:

Hi,


Sure, you can, in fact it is very simple to do. I'm not sure if you are using mql5 or mql4, but, in mql5, Sleep() does work in backtest, here are the documentaions:

Mql5: https://www.mql5.com/pt/docs/common/sleep

Mql4: https://docs.mql4.com/common/sleep


You can see that on the mql4 link, there is a note " Sleep() function does not suspend execution of the Expert Advisor in the Strategy Tester."

You also asked if you could trust Sleep() function, in the documentation linked above, you will see in the description that if you use this function that means that your code is entirely stoped for the specified time in seconds. Although , note that the SL an TP are on the server so, if the price hit any of them, even your code being stopped, they will be triggered .


With these details in mind, if you are using mql4, you can do it by checking the time with TimeCurrent(). All you need to do is to code it in a way that verify if it has already passed 10 minutes.


Hope I could help :-)



thanks dear bhjks

sorry if i forgot to say im using mql4

and i used this codes by the many ways but i dont know why it didnt worked

CloseOrderTime() , TimeCurrent() , ETC....

here is one of the way i tried to use

datetime pause  = TimeMinute(OrderCloseTime())+Pasuing*60;
datetime now    = TimeMinute(TimeCurrent());



void OnTick()

{

if(now>pause)

if(Close[1]>Close[2])


OrderSend()..........


but this date time code didnt worked


so is there any way to get time as a int number ????

like timetostr and turned into int by strtoint ?????




unfortunately i dont know what should i do to solve this problem :<

 

zogholme: sorry if i forgot to say im using mql4

datetime pause  = TimeMinute(OrderCloseTime())+Pasuing*60;
datetime now    = TimeMinute(TimeCurrent());

void OnTick(){
  if(now>pause)

so is there any way to get time as a int number ????

  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. TimeMinute returns an int not a datetime.

  4. Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

      Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  5. Time is an int (a datetime). Time plus constant is an int (a datetime). Simply compare the times.

    if(TimeCurrent() - OrderCloseTime()) >= Pasuing*60) …
    
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
 
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  3. TimeMinute returns an int not a datetime.

  4. Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and

      Don't try to use any price or server related functions in OnInit (or on load), as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  5. Time is an int (a datetime). Time plus constant is an int (a datetime). Simply compare the times.

sorry i didnt know that

what i have to do now

i learned mql4 recently and my knowlege of mql its too low

i have to delete this topic or will automatically delete ???

 
zogholme:

i have to delete this topic or will automatically delete ???

Keith Watford:
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.

I have already moved this topic.

Reason: