need help with using the sleep function

 

Hello coders,

I need some advice on how to create a 60min gap between my trades only if the last trade ended with my stop loss being activated.

I tried two things, here is the first one................

for (int j=0; j<OrdersTotal(); j++)

{if (OrderSelect(i,SELECT_BY_POS,MODE_TIME)==true)

{if (OrderType()==OP_BUY && OrderClosePrice()<OrderOpenPrice() || OrderType()==OP_SELL && OrderClosePrice()>OrderOpenPrice())

Sleep(3600000); } }

And here is the second thing.................

static int ab = 10000; int ab1; ab1 = AccountBalance(); if (ab1<ab) ab=ab1; Sleep(3600000);

None of the above two pieces of code seem to be having any effect on the function of EA when i backtest it.

If any coder has used similar logic or has some idea on how to do it,( having a set time gap in case of a losing trade) i will really appreciate your help.

Regards, newbie

 

I need some advice on how to create a 60min gap between my trades only if the last trade ended with my stop loss being activated.

Try asking if OrderClosePrice==OrderStopLoss.

MODE_TIME This is not a real mode. You really should learn how to code and not guess your way through it.

 

sentinelx:

for (int j=0; j<OrdersTotal(); j++)

{if (OrderSelect(i,SELECT_BY_POS,MODE_TIME)==true)

{if (OrderType()==OP_BUY && OrderClosePrice()<OrderOpenPrice() || OrderType()==OP_SELL && OrderClosePrice()>OrderOpenPrice())

Sleep(3600000); } }

And here is the second thing.................

static int ab = 10000; int ab1; ab1 = AccountBalance(); if (ab1<ab) ab=ab1; Sleep(3600000);

None of the above two pieces of code seem to be having any effect on the function of EA when i backtest it.


  1. If the order is closed you must look at the history, not open trades. You must refreshRates after sleeping.
    int start(){
        static datetime noOpens; if (TimeCurrent() < noOpens) return;
        for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)  // Only orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        &&  OrderType()         <= OP_SELL // Avoid cr/bal https://www.mql5.com/en/forum/126192
        ){
            if (OrderProfit() < 0){ // No opens for 1 hour
                noOpens = OrderCloseTime() + 3600; return;
            }
        }

  2. static int ab = 10000; int ab1; ab1 = AccountBalance(); if (ab1<ab) ab=ab1; Sleep(3600000); 
    The sleep ALWAYS occurs since it isn't attached to the if with brackets.
  3. if (OrderSelect(i,SELECT_BY_POS,MODE_TIME)==true)
    You wouldn't ever say if ((x>y) == true) would you? if (x>y) is sufficient. So if (bool == true) is redundant. if (bool)
[Excluído]  

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.

This website uses cookies. Learn more about our Cookies Policy.