Secure my Trades for Crazy Ticks

 

  Hi Pros,

With futures I have extreme spreads at the end of the trading day and at the start of the trading day.

Crazy ticks - spreads of 50 points and more.

So i have learned that i can manage my EA to work at different times...

But how can i secure existing orders (stop los, limit orders) not to execute.

I have good spreads the whole day. I just don‘t want to get the Ticks in the last trading minute and in the first trading minute of the day.

I want to block them completely. Is there a easy setting?

 
Ulrich1983:

  Hi Pros,

With futures I have extreme spreads at the end of the trading day and at the start of the trading day.

Crazy ticks - spreads of 50 points and more.

So i have learned that i can manage my EA to work at different times...

But how can i secure existing orders (stop los, limit orders) not to execute.

I have good spreads the whole day. I just don‘t want to get the Ticks in the last trading minute and in the first trading minute of the day.

I want to block them completely. Is there a easy setting?

others could have different approach..but this is practical to me.


input int                   _SecondsBeforeTradeOpen             = 900;
input int                   _SecondsBeforeTradeClose            = 3600;
input bool                  _EnableScheduledTrade               = true;

int                         _SafeTradeOpenHour                  = 0;
int                         _SafeTradeOpenMinute                = 0;
int                         _SafeTradeCloseHour                 = 0;
int                         _SafeTradeCloseMinute               = 0;
int                         _StartTradeAfter                    = 0;
int                         _EndTradeBefore                     = 0;
bool                        _SafeTradeTime                      = false;
void _InSafeTradeTime()
{
    datetime _LastD1Open                     = iTime(_Symbol,PERIOD_D1,1) + _SecondsBeforeTradeOpen;
    
    MqlDateTime _D1Open;
    TimeToStruct(_LastD1Open,_D1Open);
    //--- assuming 1 hour before we should avoid open any position and close position
    datetime _LastD1Close                    = _LastD1Open - _SecondsBeforeTradeClose;   
    MqlDateTime _D1Close;
    TimeToStruct(_LastD1Close,_D1Close);
   
    _SafeTradeOpenHour              = _D1Open.hour;
    _SafeTradeOpenMinute            = _D1Open.min;
    _SafeTradeCloseHour             = _D1Close.hour;
    _SafeTradeCloseMinute           = _D1Close.min;
    _StartTradeAfter                = int(_SafeTradeOpenHour*3600)+int(_SafeTradeOpenMinute*60);
    _EndTradeBefore                 = int(_SafeTradeCloseHour*3600)+int(_SafeTradeCloseMinute*60);
    datetime _TimeOfDay             = TimeCurrent(); 
    MqlDateTime _NowTime;
    TimeToStruct(_TimeOfDay,_NowTime);
    int _CurrrentHour           = int(_NowTime.hour * 3600);
    int _CurrentMinute          = int(_NowTime.min * 60);
        int _RunningSeconds         = _CurrrentHour+_CurrentMinute;

        if (_RunningSeconds>=_StartTradeAfter&&_RunningSeconds<_EndTradeBefore) 
        { 
            if (!_EnableScheduledTrade)
            {
                _SafeTradeTime      = false;
                return;
            }
            _SafeTradeTime          = true;
            return;
        }
        _SafeTradeTime              = false;          
        return;
}


by the way, there's no way to stop limit/stop orders from being executed when the spread is high what you could do is to delete lmit/stop orders when it reaches the end of your safe trading time
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 
Ulrich1983:

With futures I have extreme spreads at the end of the trading day and at the start of the trading day.

Crazy ticks - spreads of 50 points and more.

But how can i secure existing orders (stop los, limit orders) not to execute.

I want to block them completely. Is there a easy setting?

  1. You can't block them because they are real. There are no settings, it's the market. Learn to deal with it.
  2. On FX most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.
  3. With my indicator I maintain my own maximum spread using a power mean.
              Can I find out the biggest spread at the past in MT4? - MQL4 programming forum - Page 2 #14 20.04.15
 

Thanks for your replies.

Then it is, as i thought.

Probably i go to delete and renew the same order after all conditions are green.

Reason: