info ACCOUNT_PROFIT only every new bar

 

Hello,

I use ACCOUNT_PROFIT to close the positions, I would like the info ACCOUNT_PROFIT to give the result only after the opening of a new candle m1 and not at each tick.


Here is the code I use:

double Profit=AccountInfoDouble(ACCOUNT_PROFIT);

if  (
      Profit >=TP_Money
                        )
      CloseALL();

Does anyone have the solution ?

 

Example: indicator LifeHack Balance Equity 2

Displays the lines of Balance and Equity only at the time of the birth of a new bar:

LifeHack Balance Equity 2

LifeHack Balance Equity 2
LifeHack Balance Equity 2
  • www.mql5.com
Особенно полезен данный индикатор при использовании в тестере стратегий — получается визуальное отображение баланса и эквити: Для применения индикатора в Тестере нужно записать его в шаблон тестера "tester.tpl". Делается это так: откройте любой график очистите график от лишних индикаторов, объектов и советников (желательно ото всех) возьмите...
 
TradingStan2020:

Hello,

I use ACCOUNT_PROFIT to close the positions, I would like the info ACCOUNT_PROFIT to give the result only after the opening of a new candle m1 and not at each tick.


Here is the code I use:

Does anyone have the solution ?

Hi

static datetime NewBar = 0;

if(NewBar != iTime(Symbol(),PERIOD_M1,0)
{
 double Profit = AccountInfoDouble(ACCOUNT_PROFIT);
 
 if(Profit >= TP_Money) CloseALL();
 
 NewBar = iTime(Symbol(),PERIOD_M1,0);
}
 

Thanks Vladimir & Seyed for your help, it works.

What I do not understand is that I do not have the same results with an Price Open and every tick backtest, while the calculation of the strategy at entry and exit is based only on the opening/closing of the candle m1. Do you have any idea why so much difference ?


Backtest Price Open:

Price open backtest

Backtest Every Tick:

every tick backtest

 
TradingStan2020 :

Thanks Vladimir & Seyed for your help, it works.

What I do not understand is that I do not have the same results with an Price Open and every tick backtest, while the calculation of the strategy at entry and exit is based only on the opening/closing of the candle m1. Do you have any idea why so much difference ?


Backtest Price Open:

Backtest Every Tick:

If you do not understand what the difference is, then I highly recommend using the tick mode " Every Tick "

Help: Real and Generated Ticks

Real and Generated Ticks - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
Real and Generated Ticks - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
  • www.metatrader5.com
Ticks are required for testing and optimizing Expert Advisors, because they use tick data for operation. Testing can be performed on real ticks provided by a broker or on ticks generated by the strategy and based on minute data. Real Ticks # Testing and optimization on real ticks are as close to real conditions as possible. Instead of generated...
 
TradingStan2020:

Thanks Vladimir & Seyed for your help, it works.

What I do not understand is that I do not have the same results with an Price Open and every tick backtest, while the calculation of the strategy at entry and exit is based only on the opening/closing of the candle m1. Do you have any idea why so much difference ?


Backtest Price Open:

Backtest Every Tick:

If you are sure that strategy only uses prices and informations of latest closed candle and you are not using functions that are tick-influenced (like trailing stop, break even... anything else that uses Ask/Bid for calculations) you will obtain exactly same results.

Probably you get less trades becuase you have less historical data of Ticks instead of 1 minute HOLC. 

 
Fabio Cavalloni:

If you are sure that strategy only uses prices and informations of latest closed candle and you are not using functions that are tick-influenced (like trailing stop, break even... anything else that uses Ask/Bid for calculations) you will obtain exactly same results.

Probably you get less trades becuase you have less historical data of Ticks instead of 1 minute HOLC. 

I just backtested in 1 minute HOLC and I get exactly the same result in every tick ;)

Thanks to you all for your help

Reason: