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

 
Andrey Barinov:

This is how it compiles:


Thanks. I naively thought that fixing a dozen compilation errors would turn a working mql4 code into a mql5 indicator)

It doesn't want to show maximum, minimum of a day. How far is it from the goal?

 
bij:

Thanks. I naively thought that fixing a dozen compilation errors would make a working mql4 code turn into a mql5 indicator)

It doesn't want to show a minimum of a day. How far is it from the goal?

I don't know :)

Try to expand the arrays of buffers at the beginning of OnCalculate using ArraySetAsSeries

 
bij:

Thanks. I naively thought that fixing a dozen compilation errors would make a working mql4 code turn into a mql5 indicator)

It doesn't want to show maximum, minimum of a day. How far is it from the target?

There is such a huge amount of code lines just to show the high and low of the day?
 
Alexey Viktorov:
That's such a huge amount of lines of code just to show the highs and lows of the day?
Yes, there's also the close of the day, but it's in the history, not just the previous day. That is the difficulty.
 
bij:
Yes, also the closing of the day, but it's in the history, not just the previous day. That's the tricky part.

Is this your code? Or was it written to order?

Can you show me a snapshot of how it looks in MT4?

 
Alexey Viktorov:

Is this your code? Or was it written to order?

Can you show me a snapshot of how it looks in MT4?

The indicator is from the net. I don't have MT4 at hand, I'll tell you in words. Lines from start to end of each day, by High, Low and Close prices of the day. But, instead of a line atclose price of the day, I want to put a line at close price of the bar at 21:00

Maybe it really can be made easier than contrived.

 

I am closing 4 positions at once, how can I count them as one in a row in the loss-counting function?

They may close, because of slippage, not at the same price and the time may be different

Try:

int CountLOS()
  {
  double priceold=0;
  datetime datold;
   int count=0;
   for(int trade=OrdersHistoryTotal()-1;trade>=0; trade--)
     {
      OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY);
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            if(OrderMagicNumber()==_MagicNumber)
              {
               if(OrderProfit()<=0&&datold !=OrderCloseTime()) {count++; datold =OrderCloseTime();}
               //if(OrderProfit()<=0&&priceold !=OrderClosePrice()) {count++; priceold =OrderClosePrice();}
               else  break;
              }
           }
        }
     }
   return(count);
  }
 
lil_lil:

I am closing 4 positions at once, how can I count them as one in a row in the loss-counting function?

They may not close at the same price due to slippage, and the timing may be different

The price because of the slippage is different and so is the time; one has closed at the end of the second, while the other has closed at the beginning of the next second. Try to record the order tickers at the time of closing. You can record them in a file...

 
lil_lil:

I am closing 4 positions at once, how can I count them as one in a row in the loss-counting function?

They may close, because of slippage, not at the same price and the time may be different

Trial:

I cycle through the last closed ones. If the last closed one is negative, then I look at all closed ones for 120 seconds (2 minutes) and calculate the total profit

 
lil_lil:

I am closing 4 positions at once, how can I count them as one in a row in the loss-counting function?

They may close, because of slippage, not at the same price and the time may be different

I tried:

Something like this:

 datetime _oct=0,time=0,_pt=0;
 int _cnt=0;
  for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
   if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
    if(OrderSymbol()==symb && OrderMagicNumber()==mg) {
     int OrdersType=OrderType();
     // BUY && SELL
     if(OrdersType<=1) {
       CopyTime(OrderSymbol(),PERIOD_D1,0,1,itime);
       if((OrderCloseTime()>=itime[0] && OrderCloseTime()<itime[0]+86400)) {
         _Get.Hist.BS._ProfitDaily+=OrderProfit()+OrderCommission()+OrderSwap(); // Profit за сегодня
       }
       // 120 секунд разницы между закрытием первой и последней в сетке
       _oct=OrderCloseTime();
       if(_cnt==0 && _oct!=0) time=_oct;
        if(_oct+120>=time) {
          _Get.Hist.BS._ProfitOldClose+=OrderProfit()+OrderSwap()+OrderCommission(); // Profit последнего трейда
          _cnt++;
        }
     }
  }}}