Questions from Beginners MQL4 MT4 MetaTrader 4 - page 71

 
Vitalie Postolache:

Since when is a period a Double type?

That's what I'm saying, string+int is a mistake

But if you do it the way I wrote above, there will be no error.

 
Renat Akhtyamov:

That's what I'm saying: string+int is an error.

But if you do it the way I wrote above, there will be no error.


IntegerToString? Nope, haven't heard ;)
 
Vitalie Postolache:

IntegerToString? Nope, haven't heard ;)
Either way works fine, I don't see a problem
 

hi all

I am new to programming, but trying to learn)

I have a little problem with closing the order according to the indicator readings

i should tell straight away about opening and closing conditions: i open a position following the indicator readings and close it following the indicator readings but in the opposite direction without any stops and profit

if(r > 50 && p > m) //conditions for opening of a Buy order

{

ticketB = OrderSend(Symbol(),OP_BUY,0.1,Ask,5,0,0,",111,0,Green); //open Buy order

}

am I writing the order close condition correctly?

if(r < 50 && p < m) --- this is a Sell condition and a Close condition

{

OrderClose(ticketB,0.1,Bid,5,Red);

}

and prints possible use of uninitialized variable 'ticketB' and return value of 'OrderClose' should be checked

Can you guys tell me where I wrote it wrong?



 
funnyrain8:

hello all

I am new to programming, but trying to learn)

I have a little problem with closing the order according to the indicator readings

i should tell straight away about opening and closing conditions: i open a position following the indicator readings and close it following the indicator readings but in the opposite direction without any stops and profit

if(r > 50 && p > m) //conditions for opening of a Buy order

{

ticketB = OrderSend(Symbol(),OP_BUY,0.1,Ask,5,0,0,",111,0,Green); //open Buy order

}

am I writing the order close condition correctly?

if(r < 50 && p < m) --- this is a Sell condition and a Close condition

{

OrderClose(ticketB,0.1,Bid,5,Red);

}

and prints possible use of uninitialized variable 'ticketB' and return value of 'OrderClose' should be checked

Could you guys tell me where I wrote it wrong?



The ticketB variable isn't initialized, i.e. its type isn't known. In this case it is Int

The second error is that we have to check the result of closing the order for errors. Search "error handling function" in the forum

 
Renat Akhtyamov:

the ticketB variable is not initialised, i.e. the type is not known. In this case it is Int.

The second error is about checking the result of order closing for errors. Search "error handling function" in the forum

I can't quite figure out the logic or am dumbfounded), but how do I do it? At first I tried to do it using OrderSelect but it was wrong)

I need some info on this.

 
funnyrain8:

is it GetLastError? I can't understand the logic or I'm a bit dumb) but how to set it? at first I tried to do everything with OrderSelect, but it's not the same)

I need some info on this.

Yes.

Look through the codebase - plenty of examples of implementation.

 
Hello, I am a signal seller, I would like to know how you can promote your signals so that people will subscribe to them?
 
Vitalie Postolache:


Where is the logic? You set the maximum allowed lot for the first order and then increase it for each subsequent order. Don't you think this is, to put it mildly, not very sensible?

Further, you decrease the lot of the first order in the loop using some totally incomprehensible method, while the lots of the other orders that were "calculated" before remain unchanged, and these values do not go beyond the limits of this function. So, what do they do then?

Not to mention that the increment loop can't be a real number, it has to be a counter, an integer. But you set the lot value as a counter and subtract one from it each iteration. This is a major mistake, a very serious one.

Clarify the logic in your mind first and then try to implement it into your code.

The values which are not taken out in order to determine the final lot after multiplication, it should be the maximum possible lot to open, in fact, the orders with these lots might not open because the EA opens the orders in a small interval, but the probability is there and that is why I want to calculate the maximum possible initial lot. I listened to your advice and this is what I have got. What do you think about this function? I think I missed something or prescribed it incorrectly; the tester hangs a bit and obtains a small output lot.
//Функция расчета торгового лота
double GetLots()
{
 double lots = 0.0;
 double L9 = MarketInfo(Symbol(),MODE_MAXLOT);
 double L8 = L9 / Multipler;
 double L7 = L8 / Multipler;
 double L6 = L7 / Multipler;
 double L5 = L6 / Multipler;
 double L4 = L5 / Multipler;
 double L3 = L4 / Multipler;
 double L2 = L3 / Multipler;
 double cl = L2 / Multipler;
 double balance = AccountFreeMarginCheck(Symbol(),OP_BUY,L9);
 
 if(balance <= AccountFreeMargin())
 {
  for(int risk = 100;balance > 0 && risk > 0;risk--)
  {
   if(!IsStopped())
   {
    if(risk >= 1)
    {
     lots = (cl/100)*risk;
    }
    if(risk < 1)
    {
     for(int risk2 = 100;balance > 0 && risk2 >= 1;risk2--)
     {
      lots = (cl/100)*(risk2*0.01);
     }
    }
   }
  }
 }
 double clots = NormalizeDouble(MathMax(lots,MarketInfo(Symbol(),MODE_MINLOT)),2);
 return(clots);
}
 
Arseniy Barudkin:

What do you think about it?


I will say the same. You're not good at logic. What is the problem to immediately calculate the initial lot, based on available funds and the value of the risk (I think it was written about 3%)? Why do you have to do everything in one place?

Take the value of the free margin, multiply by the risk, divide by 100 and the value of the margin for 1 lot - here is the simplest formula for calculating the lot with a specified percentage of the free margin. Also, you need to take into account the step of lot change and prevent exceeding the min/max lot size permitted by brokerage companies:

input double risk = 3; //процент свободной маржи для расчёта лота
double GetLots()
{
  double margin = MarketInfo(Symbol(),MODE_MARGINREQUIRED);
  double lotstep = MarketInfo(Symbol(),MODE_LOTSTEP);
  double rsk = MathMin(100.0,risk);
  double lotmax = MarketInfo(Symbol(), MODE_MAXLOT);
  double lotmin = MarketInfo(Symbol(), MODE_MINLOT);

  double clots = NormalizeDouble(lotstep*MathRound(AccountFreeMargin()*rsk/100/margin/lotstep),2);
  if(clots < lotmin) clots = lotmin;
  if(clots > lotmax) clots = lotmax;

return(clots);
}
Reason: