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

 
Mihail Matkovskij:

So a profit is only added up if it is positive. If it is negative, it is a loss. If we want to know the total profit, all profits, including negative ones, are summed up. And this function tries to find out the profit of the last order, it does it incorrectly and is called lastloss. Don't you get it? Oh, dear... I'm exhausted...

I'm not talking about the correctness of his function ... the man doesn't know how to use the search...

But about the swap, I'll put it another way...

It searches for the last losing trade and sums up OrderProfit, but if the swap was positive, the loss is smaller?

 
MakarFX:

not there in void OnTick

      if(!RefreshRates())
         return;
      TimeBar=time_0;
      my_TP = m_symbol.Ask() + ExtTakeProfit*Point();
      my_SL = m_symbol.Ask() - ExtStopLoss*Point();
      my_lot = Lots;
   if (PositionsTotal()<=2)
     {
      OPENORDER("Buy");
     }
      CLOSEORDER("Sell");
         }  
 }
   bool   condition3 = (close1 < EMA_TREND[0]);
   bool   condition4 = (isCrossed==2);
   
      if(condition3 && condition4 && pos_total==0 )
         {
      if(!RefreshRates())
         return;
      TimeBar=time_0;
      my_TP  = m_symbol.Bid() - ExtTakeProfit*Point();
      my_SL  = m_symbol.Bid() + ExtStopLoss*Point();

      my_lot= Lots;
   if (PositionsTotal()<=2)
     {
      OPENORDER("Sell");
     }
      CLOSEORDER("Buy");


right? no change there either

 
Valeriy Yastremskiy:
"And why are you adding swap and commission to profits? And when you do.

can also be negative...

And what kind of total profit are we talking about if you only process 1 or a few matching orders, but not all?"


Something really confused each other. It was all right in the remark, not about adding and subtracting negative numbers)

I don't like answers either Seek, it's there)

I'm glad we understand each other)
 
Eugen8519:


like this? that's also the same.

Also fix this in the OnTick at the very end

   if (PositionsTotal()<=2)
     {
      TrailingOrder();
     }
   Trailing();
//---
   return;
    }
 }
 
MakarFX:

also fix it in the OnTick at the very end


changed it, no change, it's crazy, I've been working on this function for a couple of days now, nothing works.

 
Eugen8519:


I changed it, no change, it's crazy, I've been working on this function for a couple of days now, nothing works.

You should upload the whole code or attach a file, I'll look at it tomorrow.

i am not good at mql5 but i will try to help)

 
MakarFX:

Post the whole code or attach a file, I'll look at it tomorrow.

i am not good at mql5, but i will try to help)

i would like to take a look at it. the function seems to be simple, but something prevents it from doing so.

I think there is something wrong with void TrailingOrder()

Files:
EA.mq5  36 kb
 
Eugen8519:

Please check this function, it seems to be simple, but something prevents it

I think there is something wrong with void TrailingOrder()

Try it in the tester.

Сделки
Время   Сделка  Символ  Тип     Направление     Объем   Цена    Ордер   Комиссия        Своп    Прибыль         Баланс  Комментарий
2021.07.01 00:00:00     1               balance                                 0.00    0.00    10 000.00       10 000.00       
2021.07.01 23:45:00     2       EURUSD  sell    in      1       1.18478 2       0.00    0.00    0.00    10 000.00       
2021.07.02 10:00:40     3       EURUSD  buy     out     1       1.18328 3       0.00    -1.00   150.00  10 149.00       tp 1.18328
2021.07.02 21:00:00     4       EURUSD  buy     in      1       1.18675 4       0.00    0.00    0.00    10 149.00       
2021.07.02 22:22:00     5       EURUSD  sell    out     1       1.18681 5       0.00    0.00    6.00    10 155.00       
2021.07.06 08:15:00     6       EURUSD  buy     in      1       1.18778 6       0.00    0.00    0.00    10 155.00       
2021.07.06 09:08:40     7       EURUSD  sell    out     1       1.18928 7       0.00    0.00    150.00  10 305.00       tp 1.18928
2021.07.06 15:00:00     8       EURUSD  sell    in      1       1.18403 8       0.00    0.00    0.00    10 305.00       
2021.07.06 15:31:40     9       EURUSD  buy     out     1       1.18453 9       0.00    0.00    -50.00  10 255.00       sl 1.18453
2021.07.07 16:00:00     10      EURUSD  sell    in      1       1.18159 10      0.00    0.00    0.00    10 255.00       
2021.07.07 16:42:40     11      EURUSD  buy     out     1       1.18009 11      0.00    0.00    150.00  10 405.00       tp 1.18009
2021.07.08 12:45:00     12      EURUSD  buy     in      1       1.18278 12      0.00    0.00    0.00    10 405.00       
2021.07.08 14:00:20     13      EURUSD  sell    out     1       1.18428 13      0.00    0.00    150.00  10 555.00       tp 1.18428
2021.07.09 15:30:00     14      EURUSD  buy     in      1       1.18611 14      0.00    0.00    0.00    10 555.00       
2021.07.09 18:30:40     15      EURUSD  sell    out     1       1.18561 15      0.00    0.00    -50.00  10 505.00       sl 1.18561
2021.07.13 04:30:00     16      EURUSD  buy     in      1       1.18637 16      0.00    0.00    0.00    10 505.00       
2021.07.13 08:57:20     17      EURUSD  sell    out     1       1.18587 17      0.00    0.00    -50.00  10 455.00       sl 1.18587
2021.07.13 13:00:00     18      EURUSD  sell    in      1       1.18426 18      0.00    0.00    0.00    10 455.00       
2021.07.13 13:53:40     19      EURUSD  buy     out     1       1.18476 19      0.00    0.00    -50.00  10 405.00       sl 1.18476
2021.07.15 17:00:00     20      EURUSD  sell    in      1       1.18165 20      0.00    0.00    0.00    10 405.00       
2021.07.15 17:05:40     21      EURUSD  buy     out     1       1.18215 21      0.00    0.00    -50.00  10 355.00       sl 1.18215
2021.07.19 05:30:00     22      EURUSD  sell    in      1       1.18014 22      0.00    0.00    0.00    10 355.00       
2021.07.19 07:11:40     23      EURUSD  buy     out     1       1.18064 23      0.00    0.00    -50.00  10 305.00       sl 1.18064
2021.07.20 05:00:00     24      EURUSD  sell    in      1       1.17972 24      0.00    0.00    0.00    10 305.00       
2021.07.20 05:31:20     25      EURUSD  buy     out     1       1.18022 25      0.00    0.00    -50.00  10 255.00       sl 1.18022
2021.07.21 07:30:00     26      EURUSD  sell    in      1       1.17727 26      0.00    0.00    0.00    10 255.00       
2021.07.21 10:09:40     27      EURUSD  buy     out     1       1.17577 27      0.00    0.00    150.00  10 405.00       tp 1.17577
2021.07.21 18:45:00     28      EURUSD  buy     in      1       1.17990 28      0.00    0.00    0.00    10 405.00       
2021.07.21 19:09:40     29      EURUSD  sell    out     1       1.17940 29      0.00    0.00    -50.00  10 355.00       sl 1.17940
2021.07.22 17:15:00     30      EURUSD  buy     in      1       1.17929 30      0.00    0.00    0.00    10 355.00       
2021.07.22 17:40:40     31      EURUSD  sell    out     1       1.17879 31      0.00    0.00    -50.00  10 305.00       sl 1.17879
2021.07.22 19:45:00     32      EURUSD  sell    in      1       1.17594 32      0.00    0.00    0.00    10 305.00       
2021.07.22 20:01:40     33      EURUSD  buy     out     1       1.17644 33      0.00    0.00    -50.00  10 255.00       sl 1.17644
2021.07.27 11:00:00     34      EURUSD  sell    in      1       1.17829 34      0.00    0.00    0.00    10 255.00       
2021.07.27 13:39:40     35      EURUSD  buy     out     1       1.17879 35      0.00    0.00    -50.00  10 205.00       sl 1.17879
2021.07.27 19:00:00     36      EURUSD  buy     in      1       1.18304 36      0.00    0.00    0.00    10 205.00       
2021.07.27 21:52:40     37      EURUSD  sell    out     1       1.18254 37      0.00    0.00    -50.00  10 155.00       sl 1.18254
2021.07.29 01:00:00     38      EURUSD  buy     in      1       1.18443 38      0.00    0.00    0.00    10 155.00       
2021.07.29 08:42:40     39      EURUSD  sell    out     1       1.18593 39      0.00    0.00    150.00  10 305.00       tp 1.18593
2021.07.30 13:15:00     40      EURUSD  buy     in      1       1.18859 40      0.00    0.00    0.00    10 305.00       
2021.07.30 13:50:40     41      EURUSD  sell    out     1       1.19009 41      0.00    0.00    150.00  10 455.00       tp 1.19009
2021.07.30 19:45:00     42      EURUSD  sell    in      1       1.18607 42      0.00    0.00    0.00    10 455.00       
2021.07.30 22:22:00     43      EURUSD  buy     out     1       1.18576 43      0.00    0.00    31.00   10 486.00       
                                                                                0.00    -1.00   487.00  10 486.00       
Files:
EA.mq5  36 kb
 
MakarFX:

I won't say anything about the correctness of his function...the man doesn't know how to use the search engine

But about the swap, let me put it another way...

it looks for the last losing trade and sums up OrderProfit, but if the swap was positive, the loss is smaller?

Well, of course it gets smaller and the profit gets bigger. :) Do you even hear yourself? What positive swap? Where have you seen such a thing?!

 
Mihail Matkovskij:

Of course, it's getting smaller and the profits are bigger. :) Do you even hear yourself? What positive swap? Where did you see that?!

I have. More than once. I even wanted to build on the changes in such swaps