# Scan last 100 candles

Hello, I want to build a function to determine if we are currently trending or moving in a range. My idea is to compare the close price of the last 100 candles to an EMA Value of the close time. Is the close of the last candle higher or lower than the EMA value of the same sift value? Compare Close Shift 5 to EMA shift 5.... I hope you understand. The Goal is to get a percentage of how many of the last 100 candles where higher than the EMA and how many where lower. If its like 50/50 than we are in a range, if its 80/20 we are trending.  Do you have a good idea on how to do this?

Vincent Goette Do you have a good idea on how to do this?
1. ***
2. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
No free help (2017)

General rules and best pratices of the Forum.
• 2019.03.05
• www.mql5.com
General rules, enforced by moderators : ‌...

William Roeder # :
1. ***
2. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button ) and state the nature of your difficulty.
No free help (20 17 )

You are on the MQL5 forum. You write in the main MQL5 thread. Remember that the MQL5 style implies one-time creation of the indicator handle in OnInit and receiving data (using CopyBuffer) in OnTIck.

Vincent Goette :
Hello, I want to build a function to determine if we are currently trending or moving in a range. My idea is to compare the close price of the last 100 candles to an EMA Value of the close time. Is the close of the last candle higher or lower than the EMA value of the same sift value? Compare Close Shift 5 to EMA shift 5.... I hope you understand. The Goal is to get a percentage of how many of the last 100 candles where higher than the EMA and how many where lower. If its like 50/50 than we are in a range, if its 80/20 we are trending.  Do you have a good idea on how to do this?

You can make a panel and visualize the percentage of 'Close' prices and iMA values... We need to think about how to do it in the easiest and most beautiful way...

Percentage of CLose and iMA prices
• www.mql5.com
The indicator shows the percentage of the 'Close' price above and below the 'iMA' indicator

Vladimir Karputov #: You are on the MQL5 forum. You write in the main MQL5 thread. Remember …

Excuse me? I wrote no code. “get EMA(iBar)” is not code, it describes in English what OP needs to do, not how to do it.

Reason: