# How to get last momentum

373

I want it to go short when 'last momentum > now momentum'. But how can i get the last momentum?

The momentum documentation:

Momentum is calculated as a ratio of today’s price to the price n periods ago:

MOMENTUM = CLOSE (i) / CLOSE (i - n) * 100

Where:

CLOSE (i) — close price of the current bar;

CLOSE (i - n) — close price n bars ago.

So i thought in my case:

```// Code

int MOMENTUM_now = CLOSE (symbol[i], 0 ) / CLOSE (symbol[i] - 1, 0) * 100 // it gets error: '-' - illegal operation

int MOMENTUM_last = CLOSE (symbol[i] - 1, 0) / CLOSE (symbol[i] - 2, 0) * 100

if( MOMENTUM_last > MOMENTUM_now){

OpenFromMarket(symbol[i],ORDER_TYPE_SELL,GetLot(symbol[i]),Stop,Take);

Sleep(3000);

}

double Close(string symb,int bar)

{

double cl[1]={0};

CopyClose(symb,Time_Frame,bar,1,cl);

return(cl[0]);

} ```

Can someone help me in the right direction?

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
• www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
39276

```int n=1;  // Any other value >=1, indicating how many bars back the second price is.
double MOMENTUM_now = Close (symbol[i], 0 ) / Close (symbol[i] , n) * 100 // it gets error: '-' - illegal operation

double MOMENTUM_last = Close (symbol[i] , 1) / Close (symbol[i] , 1+n) * 100

if( MOMENTUM_last > MOMENTUM_now){

OpenFromMarket(symbol[i],ORDER_TYPE_SELL,GetLot(symbol[i]),Stop,Take);

Sleep(3000);

}

double Close(string symb,int bar)

{

double cl[1]={0};

CopyClose(symb,Time_Frame,bar,1,cl);

return(cl[0]);

} ```

373

Thanks for the explanation. With the extra ';' it is working now.

Last edit:

This works best for me. It is with the sum from the momentum indicator:

```        int n_moment= 14;  // Any other value >=1, indicating how many bars back the second price is, (this is the period value of from the momentum indicator)
double MOMENTUM_last = Close(symbol[i], 1)*100 / Close (symbol[i], n_moment);
double MOMENTUM_now = Close(symbol[i], 0 )*100 / Close(symbol[i], n_moment-1);```