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

 
Maxim Kuznetsov:
It feels like the original text comes from a parallel universe, was translated twice by google-translate and then retold by Alice :-)

Okay. There is a function that can be used to find the last lot. It's calledFindLastLots. But I want to make a function that doesn't just search for the last lot, but with the help of which you can change Lots. That is, if extern lots = 0.01; I want to change lots = 0.01, say, to 0.04 usingthis function. And here I need help to understand how it can be implemented in general.

double FindLastLots()
  {
   double oldlots=0;
   int oldticket;
   int ticket=0;

   for(int i=OrdersHistoryTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            oldticket=OrderTicket();
            if(oldticket>ticket)
              {
               oldlots= OrderLots();
               ticket = oldticket;
              }
           }
        }
     }
   return(oldlots);
  }
Общие принципы - Торговые операции - Справка по MetaTrader 5
Общие принципы - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Перед тем как приступить к изучению торговых функций платформы, необходимо создать четкое представление об основных терминах: ордер, сделка и позиция. — это распоряжение брокерской компании купить или продать финансовый инструмент. Различают два основных типа ордеров: рыночный и отложенный. Помимо них существуют специальные ордера Тейк Профит...
 
Corvin85:

...

change lots = 0.01, say to 0.04. Without using multiplication.

...

Well... if multiplication is a problem, you can get the desired result by addition.

 
Alexey Viktorov:

Well... if multiplication is a problem, you can get the result you want by adding.

-:)

without saying
 
Can I add a while loop to this function, so that I can go through the external variable one by one in the selected orders? But how can I then pull out the "return value" and use it?
 
Alexey Viktorov:

Well... if there are problems with multiplication, you can get the desired result by addition.

I understand your sarcasm, but that in multiplication or calculation cases, there should be as many multipliers as there are external variables Lots. That's not a way out of the situation. Although I'll be honest, I've thought about it...

 
Hello!!! I am making an EA based on an M5 timeframe.... but the signals are triggered (for example at 9:33, 12:11) etc..... can you tell me how to open an order on a new candle if the signal was on the current one?
 
Corvin85:

I understand your sarcasm, but that in multiplication or calculation cases, there should be as many multipliers as there are external variables Lots. That's not a way out of the situation. Although I'll be honest, I've thought about it.

I can't remember the details right now, but I was ordered something complicated in calculating Lots. As a result, a formula was found by which the calculation was made.

Perhaps you would be better off stating the order in detail? Then someone can suggest this formula.

 
Alexey Viktorov:

I can't remember the details now, but I was ordered to do something elaborate in calculating the lot. The result was a formula that was used to calculate it.

Perhaps you would be better off stating the order in detail? Then someone can suggest this formula.

#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern double Lot  = 0.01;
extern double Lot2  = 0.02;
extern double Lot3  = 0.05;
extern double Lot3  = 0.07;
//----------- И так далее-------//

There are several external variables of Lot. If an order is closed by Stop Loss, a new order is opened with the new lot that is specified in the external variable. (Maybe, this is how we should have originally written it). I just don't know how to write it correctly in code. And as I wrote above, no multiplication or calculation, no external multiplier will help. We need to somehow go through the data of closed orders...

 
Corvin85:

There are several external variables Lot. If an order is closed by StopLoss, then a new order opens with a new lot, which is specified in the external variable. (Maybe, this should have been originally written in this way) And here is the hitch. I just don't know how to write it correctly in code. And as I wrote above, no multiplication or calculation, no external multiplier will help. We need to somehow retrieve data from closed orders ...

When opening an order, write the number of the rule/variable in the comment.

then when you check the history - fetch this number, add 1 to it and get a new rule number

 
Corvin85:

There are several external variables Lot. If an order is closed by StopLoss, then a new order opens with a new lot, which is specified in the external variable. (Maybe, this should have been originally written in this way) And here is the hitch. I just don't know how to write it correctly in code. And as I wrote above, no multiplication or calculation, no external multiplier will help. We have to go through the data of closed orders somehow.

Experiment with this code, maybe this is what you need

#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property strict

input double Lot_01  = 0.1;
input double Lot_02  = 0.2;
input double Lot_03  = 0.3;
input double Lot_04  = 0.4;
input double Lot_05  = 0.5;
input double Lot_06  = 0.6;
input double Lot_07  = 0.7;

double GetNextLot(const double last_lot)
{
   if(last_lot>=Lot_07) return(Lot_07);
   if(last_lot>=Lot_06) return(Lot_07);
   if(last_lot>=Lot_05) return(Lot_06);
   if(last_lot>=Lot_04) return(Lot_05);
   if(last_lot>=Lot_03) return(Lot_04);
   if(last_lot>=Lot_02) return(Lot_03);
   if(last_lot>=Lot_01) return(Lot_02);
   return(Lot_01);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   Print(Lot_01," ---> ",GetNextLot(Lot_01));
   Print(Lot_02," ---> ",GetNextLot(Lot_02));
   Print(Lot_03," ---> ",GetNextLot(Lot_03));
   Print(Lot_04," ---> ",GetNextLot(Lot_04));
   Print(Lot_05," ---> ",GetNextLot(Lot_05));
   Print(Lot_06," ---> ",GetNextLot(Lot_06));
   Print(Lot_07," ---> ",GetNextLot(Lot_07));
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
void OnTick()
  {

   
  }
//+------------------------------------------------------------------+

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.7 ---> 0.7

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.6 ---> 0.7

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.5 ---> 0.6

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.4 ---> 0.5

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.3 ---> 0.4

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.2 ---> 0.3

2019.11.28 22:31:26.409 tst EURUSD,H1: 0.1 ---> 0.2

In my function GetNextLot() you feed the volume of the last closed order, and it will return the next value of the Lot_XX setting

the only limitation in this code is that lots settings should be in ascending order - I think the code is simple and straightforward, you can modify it to suit your needs

Reason: