Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 249

 

What kind of error is this, I take it from the DC's side, a bad workout?

2017.07.12 12:42:48.493 '1234885286': order #247632722 sell 0.02 EURAUD closing at 1.49721 failed [Trade timeout]
 
Vitaly Muzichenko:

What kind of error is this, I take it from the DC's side of bad debriefing?

128

ERR_TRADE_TIMEOUT

Timeout expired


Piece of the handler:

    case 128:
      str="Истек срок ожидания совершения сделки.";
      if(detailed) str=::StringConcatenate(str, "\n", "Прежде, чем производить повторную",
                 " попытку (не менее, чем через 1 минуту), необходимо убедиться,",
                 " что торговая операция действительно не прошла (новая позиция",
                 " не была открыта, либо существующий ордер не был изменён или",
                 " удалён, либо существующая позиция не была закрыта).");
      break;
 
Artyom Trishkin:

128

ERR_TRADE_TIMEOUT

Timeout expired for trade execution


Piece of the handler:

I have these error handlers in my code, but they never existed. Today I decided to check my program at demo of one popular brokerage company and faced with such bugs for the first time.

I understand correctly that this is a hardware problem at the brokerage company and not on my side?

 

Please tell me if this function is correct. The idea is to calculate if the price has broken through the average price during a certain amount of previous candles.

the function is not executed at all, the result should be: if it has not broken returnToMA ==1, if it has broken returnToMA ==0

maybe there is another solution to this problem?


returnToMA = MAtouch(TRADE_TF2,TRADE_TF2_MA,barscount)

int MAtouch(ENUM_TIMEFRAMES tfpricereturnafterbreak=PERIOD_H4, int tradema=10, int bars=100)

{

for(i=0;i<=bars;i++)

{

if(iLow(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)) {return(0);break;}

if (iHigh(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)) {return(0);break;}

else return(1);

}

 
forexpipsrunner:

Please tell me if this function is correct. The idea is to calculate if the price has broken through the average price during a certain amount of previous candles.

the function is not executed at all, the result should be: if it has not broken returnToMA ==1, if it has broken returnToMA ==0

Maybe there are other solutions to this problem?

Your function will always have zero because the maximum or minimum is always greater than/less than or equal to the MA.

The candlestick must be described by at least two parameters in your case:

1) Define where the candlestick opened - above or below the MA

2. Depending on 1, check whether the MA was touched.

 
-Aleks-:

You will always have zero in the function - as the maximum or minimum is always greater than/less than or equal to the MA.

The candlestick must be described by at least two parameters in your case:

1. determine where the candlestick opened - above or below the MA

2. Depending on 1, check if the MA was touched.

Thank you. I added the condition but it always returns 1. Can I change the brackets somewhere? Or break does not work and the function terminates by assigning 1 to the return value


int MAtouch(ENUM_TIMEFRAMES tfpricereturnafterbreak=PERIOD_H4, int tradema=10, int bars=100)

{

for(i=0;i<=bars;i++)

{

if( iLow(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)

&&iOpen(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i))

{return(0);break;}

if ( iHigh(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)

&&iOpen(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i))

{return(0);break;}

else return(1);

}

 
forexpipsrunner:

Thanks. I added the condition, but it always returns 1. Can I change the brackets somewhere? Or break does not work and the function terminates by assigning 1 to the return value


int MAtouch(ENUM_TIMEFRAMES tfpricereturnafterbreak=PERIOD_H4, int tradema=10, int bars=100)

{

for(i=0;i<=bars;i++)

{

if( iLow(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)

&&iOpen(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i))

{return(0);break;}

if ( iHigh(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)

&&iOpen(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i))

{return(0);break;}

else return(1);

}


Try it like this

int MAtouch(ENUM_TIMEFRAMES tfpricereturnafterbreak=PERIOD_H4,int tradema=10,int bars=100)
  {
   int x=0;
   for(int i=0;i<=bars;i++)
     {
      if(iLow(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)
         && iOpen(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i))
        {x=1;break;}

      if(iHigh(Symbol(),tfpricereturnafterbreak,i)>=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i)
         && iOpen(Symbol(),tfpricereturnafterbreak,i)<=iMA(Symbol(),tfpricereturnafterbreak,tradema,0,MODE_EMA,PRICE_WEIGHTED,i))
        {x=1;break;}
     }
   return(x);
  }

It will return 1 if the condition is met - there was an intersection - isn't that what we want?

 
-Aleks-:

Try this

It will return 1 if the condition is met - there was an intersection - isn't that what we want?

Thank you, it works like clockwork with your version of the code
 
forexpipsrunner:
Thank you, it works like clockwork with your version of the code

Glad to be of help.
 

Good afternoon!

Guys, can you tell me if you can programmatically display the indicator on the chart? Or only manually?

If so, what command is given?