Questions from a "dummy" - page 81

 
tol64:

Can you tell me in which cases the value of a tick may differ depending on whether the position is currently in profit or loss?

SYMBOL_TRADE_TICK_VALUE_PROFIT

SYMBOL_TRADE_TICK_VALUE_LOSS

Do a search on the forum. Something similar has been discussed before.
 

Need to get the result of the last transaction. What am I doing wrong? :

   i = HistoryDealsTotal(); 
   
   if (i > 1)  {
   	HistorySelect(0,TimeCurrent());
   	 ticket = HistoryDealGetTicket(i);
   	 profit = HistoryDealGetDouble(ticket,DEAL_PROFIT);
   }
 
infera:

Need to get the result of the last transaction. What am I doing wrong? :

I think it goes like this

   HistorySelect(0,TimeCurrent());

   i = HistoryDealsTotal(); 
   
   if (i > 1)  {
        
        ticket = HistoryDealGetTicket(i-1);
        profit = HistoryDealGetDouble(ticket,DEAL_PROFIT);
   }
 
sergey1294:

I think it goes like this

Thank you, it's working.
 

I'm experimenting with deleting unwanted handles. In a simple example, without the IndicatorRelease(ma_handle); lines, everything works fine and fast.

But it almost hangs the system in OHLC mode.

double ma2[];int ma2_handle;double ma[];int ma_handle;

int OnInit()
 {  
  return(0);
 }

void OnTick() 
{ 
    ma_handle  = iMA(_Symbol,_Period,10, 0,MODE_SMA, PRICE_CLOSE);
    ma2_handle = iMA(_Symbol,_Period,100, 0,MODE_SMA, PRICE_CLOSE);
   IndicatorRelease(ma_handle);
   IndicatorRelease(ma2_handle);
}
 
Karlson:

I'm experimenting with deleting unwanted handles. In a simple example, without the IndicatorRelease(ma_handle); lines, everything works fine and fast.

But it almost hangs the system in OHLC mode.

To create and delete indicator handles at every tick is wrong. It's like stopping and starting your car at every traffic light and before every pedestrian crossing.
Документация по MQL5: Доступ к таймсериям и индикаторам / IndicatorRelease
Документация по MQL5: Доступ к таймсериям и индикаторам / IndicatorRelease
  • www.mql5.com
Доступ к таймсериям и индикаторам / IndicatorRelease - Документация по MQL5
 
Rosh:
Creating and deleting indicator handles on every tick is not right. It's like stopping and starting your car at every traffic light and before every zebra crossing.

And I want to be more specific about the handles.

If the handles were not removed during deinitialization (IndicatorRelease) and the program was removed from the chart at the same time, are the handles automatically removed?

One more thing. The reference says it saves memory. By how much? If I could give you some figures on how much resources are consumed by indicator handles.

 
tol64:

And I want to clarify about handles.

If the handles were not deleted (IndicatorRelease) during deinitialization, but the program was deleted from the chart, are the handles automatically deleted?

Yes, if the terminal runtime system detects a derelict handle that is not claimed by anyone, it will be deleted automatically. I cannot tell you the lifetime of such a handle right now.
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
tol64:

One more thing. The reference says it saves memory. By how much? If you can give figures, how much resources are consumed by indicator handles.

If the same indicator is requested from 10 charts, then the economy is 10 times. If so, calculate the number of bars on which the indicator is calculated and multiply by the number of indicator buffers, multiply by the size of double and don't forget the memory of colour buffers, if there are any.
Усреднение ценовых рядов без дополнительных буферов для промежуточных расчетов
Усреднение ценовых рядов без дополнительных буферов для промежуточных расчетов
  • 2010.10.25
  • Nikolay Kositsin
  • www.mql5.com
Статья о традиционных и не совсем традиционных алгоритмах усреднения, упакованных в максимально простые и достаточно однотипные классы. Они задумывались для универсального использования в практических разработках индикаторов. Надеюсь, что предложенные классы в определенных ситуациях могут оказаться достаточно актуальной альтернативой громоздким, в некотором смысле, вызовам пользовательских и технических индикаторов.
 
Rosh:
Creating and removing indicators handles at every tick is wrong. It's like turning your car off and on at every traffic light and before every zebra crossing.

It was a model. In Expert Advisor the function is executed on a new weekly bar, new indicators are created and mathematics is done. Then it has to be cleaned up... So, when activating IndicatorRelease line it almost freezes... It is enough to remove it, and everything flies in spite of all rubbish.

double ma[];int ma_handle;datetime time[],lastbar;

int OnInit()
 {  
  return(0);
 }

void OnTick() 
{  
   if(CopyTime(_Symbol,PERIOD_W1,0,1,time)<=0) {Print("Error: ",GetLastError());return;}
   if (lastbar!=time[0]) {Optim();}
}


int Optim()
{
   ma_handle  = iMA(_Symbol,PERIOD_M15,20, 0,MODE_SMA, PRICE_CLOSE);
 ------------------

 ------------------
   IndicatorRelease(ma_handle);

   return (0);
}
Reason: