Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 619

 
001:
There is a function to close a position by time.

Position closes, but gives OrderClose error 138 for each position

11:44:49 2000.01.10 07:00 Time+iLowest_old EURUSD,H1: open #1 sell 0.10 EURUSD at 1.02940 ok
11:44:49 2000.01.10 14:00 Time+iLowest_old EURUSD,H1: OrderClose error 138
11:44:49 2000.01.10 14:00 Time+iLowest_old EURUSD,H1: close #1 sell 0.10 EURUSD at 1.02940 at price 1.02230
11:44:49 2000.01.11 07:00 Time+iLowest_old EURUSD,H1: open #2 sell 0.10 EURUSD at 1.02660 ok
11:44:49 2000.01.11 14:00 Time+iLowest_old EURUSD,H1: OrderClose error 138
11:44:49 2000.01.11 14:00 Time+iLowest_old EURUSD,H1: close #2 sell 0.10 EURUSD at 1.02660 at price 1.02890
11:44:49 2000.01.13 07:00 Time+iLowest_old EURUSD,H1: open #3 sell 0.10 EURUSD at 1.02860 ok

11:44:49 2000.01.13 14:00 Time+iLowest_old EURUSD,H1: OrderClose error 138 ,

What may it be? The most interesting thing is that everything works in another EA.

You do not have processing of trade server return codes. In other words, you don't process requotes and slippage is only 3 points missing:

int f=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),3,Red);

Oh, and the little things:

Close in a reverse loop (otherwise it will miss):

for(int i=OrdersTotal()-1; i>=0; i--)

Checking should be done on the order type, otherwise it will try to close the pending orders as well:

if(OrderType()>1) continue;
 
pu6ka:

There is a function called SetIndexDrawBegin(). But it has a special feature - it counts from left to right. Anyway, in Init, set yourself line SetIndexDrawBegin(0, Bars-p), and see if this is what you need.
The indicator reads the last no. of bars, it has no problems. I need to make a window of the number of bars in which these movements would be counted and with each bar the window would move, excluding the last bar in the last calculation, adding a new one. Something like "iMAOnArray" smoothing, but smoothing is not suitable because it outputs the average, and I need the sum.
 
artmedia70:

You have no processing of the trade server's return codes. I.e. you don't process the requote, and the slippage of just 3 points is missing:

Oh, and the little things:

Close in a reverse loop (otherwise it will miss):

Checking should be done on order type, otherwise it will try to close the pending orders as well:



Thank you very much! I will try it now. One more question. Is the requote in the tester relevant? in my tester it doesn't close.
 
001:

Thank you very much! I'll give it a try now. One more question. Is the requota in the tester relevant? in my tester it does not close.
Then pay attention to the price in the trade order. It will be closed at Bid price and sold at Ask price. You have no check for order type there and, therefore, no price choice - either Ask or Bid
 

Hello! I have downloaded several almost identical multi-timeframe RSI indicators. They all have the same problem. I set the indicator on a lower timeframe chart with the value of some older timeframe. In the Strategy Tester it is rendered fine on already loaded data, but if I start testing it stops drawing. In addition, the signal is drawn on the real chart, but on each bar of the real chart the values of the indicator line are different. I.e. the already loaded data rendering is staircase, but the rendering is different for the loaded data in the real time mode. Please advise which changes need to be made for the indicator to draw the same staircase both on the real chart in real time mode and in the tester.

The code of the indicator is in the attached file.

I have a very good Expert Advisor for this indicator and I would like to thank you for it.

Files:
mtf_rsi.mq4  3 kb
 
Hello, the EA gives error 1 "No error but no result known" when modifying.Error 1
void ControlBuylimit(){
  for(int i=OrdersTotal(); i>=0; i--){
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
      if(OrderMagicNumber()==Magic){
        if(OrderSymbol()==Symbol()){
          if(OrderType()==OP_BUYLIMIT){
            if(OrderComment()=="MA_1"){
              if(OrderOpenPrice()!=ma1){
                int cnt=0;
                bool res;
                while(cnt<=5){
                  res=OrderModify(OrderTicket(),NormalizeDouble(ma1,Digits),NormalizeDouble(ma1,Digits)-StopLoss*Point,NormalizeDouble(ma1,Digits)+TakeProfit*Point,0,clrNONE);
                  if(!res){
                    int answ=0;
                    answ=ERRORS(GetLastError(),OrderTicket());
                    if(answ==1){continue; cnt++;}
                    if(answ==2)break;
                  }
                  if(res)break;
                }
              }
            }
            if(OrderComment()=="MA_2"){
              if(OrderOpenPrice()!=ma2){
                int cnt=0;
                bool res;
                while(cnt<=5){
                  res=OrderModify(OrderTicket(),NormalizeDouble(ma2,Digits),NormalizeDouble(ma2,Digits)-StopLoss*Point,NormalizeDouble(ma2,Digits)+TakeProfit*Point,0,clrNONE);
                  if(!res){
                    int answ=0;
                    answ=ERRORS(GetLastError(),OrderTicket());
                    if(answ==1){continue; cnt++;}
                    if(answ==2)break;
                  }
                  if(res)break;
                }
              }
            }
          }
        }
      }
      
    }
  }
}
 
Forexman77:
There is no problem to make the indicator read the last no. of bars. I need to make a window of number of bars in which these movements would be counted and with each bar the window would move, excluding the last bar in the last calculation, adding a new one. Something like "iMAOnArray" smoothing, but smoothing is not suitable because it outputs the average, and I need the sum.

Throw this indicator on M1, as new bars appear, the alligator lines on the left "get wiped out". Need it?

Files:
 
Example2:
Hello, the EA gives error 1 "No error but no result known" when modifying.

Most likely you are modifying with the old price that is already prescribed in the order.
 
pu6ka:

Most likely modify the old price that is already prescribed in the warrant.


But there is a checkif(OrderOpenPrice()!=ma2)

 
Example2:


But there is a checkif(OrderOpenPrice()!=ma2)


What isma2 ?
Reason: