Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1055

 
Igor Makanu:

this is all clear, but how do you calculate the difference of 2 prices in whole points correctly?

This is where rounding can be applied. It's up to you to decide which way, or just to a whole number.

int pips_profit = (int)MathFloor(OrderOpenPrice()-OrderClosePrice())/_Point);
 
Igor Makanu:

And this is correct? In the order loop, would SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT); be recalculated each time, becauseOrderSymbol() will be different each time?

The problem there is slightly different - the total profit in pips for all symbols.

 
Konstantin Nikitin:

This is where rounding can be applied. It's up to you to decide which way, or just to a whole number.


well yes, forgot such constructions, in Kim's lot calculation functions there was correct rounding
fxsaber:

So the task there is slightly different - the total profit in points for all symbols.

OK, but why const - how the compiler behaves if the loop will change const ?

PS: code is readable, but need to check, never used this

 
Igor Makanu:

OK, but why const - how does the compiler behave if const is changed in the loop ?

PS: code is readable, but need to check, never used this

At each step a variable will be created. const - at this step it is not planned to change anywhere.

 
fxsaber:

Each step will create a variable. const - there are no plans to change anywhere in this step.

is the step an iteration of the loop?

It is still not clear how such a construction will behave, we need a script to check

 
fxsaber:

So the objective is slightly different there - total profit in pips across all symbols.

Well, then it's like this

short pipsProfitOrder = (short)MathFloor( ( OrderProfit()+OrderSwap()+OrderCommission() ) / (SymbolInfoDouble(_OrderSymbol(), SYMBOL_TRADE_TICK_VALUE)*OrderLots()) );

I calculate profits in pips of one position, but I think it won't be a problem to apply it to myself

 
Igor Makanu:

a step is an iteration of a cycle?

Yes.

it's still not clear how such a construction will behave, we need a script to check

Here is an example of a convenient use of the life of a variable

Forum on trading, automated trading systems and strategy testing

Discussion on "LifeHack for trader: mixing ForEach on defines (#define)"

fxsaber, 2018.02.14 10:54

Performance measurement

#define  BENCH(A)                                                              \
{                                                                             \
  const ulong StartTime = GetMicrosecondCount();                              \
  A;                                                                          \
  Print("Time[" + #A + "] = " + (string)(GetMicrosecondCount() - StartTime)); \
}

double GetAsk()
{
  static MqlTick tick = {0};
  
  return(SymbolInfoTick(Symbol(),tick) ? tick.ask : 0);
}

#define  AMOUNT 1 e6

void OnStart()
{
  double Sum = 0;
  
  BENCH(for (int i = 0; i < AMOUNT; i++) Sum += GetAsk())
  BENCH(for (int i = 0; i < AMOUNT; i++) Sum += SymbolInfoDouble(_Symbol, SYMBOL_ASK))
  
  Print(Sum);
}


Result

Time[for(inti=0;i<AMOUNT;i++)Sum+=GetAsk()] = 78952
Time[for(inti=0;i<AMOUNT;i++)Sum+=SymbolInfoDouble(_Symbol,SYMBOL_ASK)] = 162606
 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Konstantin Nikitin, 2019.06.04 19:58

Well then

short pipsProfitOrder = (short)MathFloor( ( OrderProfit()+OrderSwap()+OrderCommission() ) / (SymbolInfoDouble(_OrderSymbol(), SYMBOL_TRADE_TICK_VALUE)*OrderLots()) );

I calculate profits in pips of one position but I think I have no problem applying it to myself

This is called conversion of profit with costs into TRUE (not at close) pips.

 
fxsaber:

This is called a cost profit transfer into CURRENT (not at the time of closing) points.

This is how he needs to translate the profit into points. When calculating the closed ones, you still need to take the point value as a basis. The profit in pips does not have to be equal to the difference in pips between the open and close prices. and closing prices.

 
Konstantin Nikitin:

So he needs to translate the profit into points.

Sometimes they think that profit = OrderProfit().

When calculating a closed symbol, you should still use the pip value as a basis. The pip value of the profit does not have to be equal to the difference in pips between the open and close price.

The point value at close is not equal to the point value at the time of calculation. Moreover, at the time of calculation the symbol might simply not be in the Market Watch.

That is why both values of points and their value at the moment of closing are calculated.

Reason: