Extrema DetectorDetermines local maximums and minimums points in the chart.
Parameters:
lookback : number of candlesticks to look.
extrema_finder_sensivity : If lower, more extreme points will be found (may over-find).
Brief algorithm description:
Computes a Simple Moving Average (length= extrema_finder_sensivity ), and searches for its local extremes.
Given some SMA extreme, it looks the previous extrema_finder_sensivity candlesticks to find the highest (or lowest value).
Notes:
Is a lagged indicator: determining if the current candlestick have reach a maximum can be delayed to, at most extrema_finder_sensivity -further candlesticks.
Maximum
Max Drawdown Calculating Functions (Optimized)Maximum Drawdown and Maximum Relative Drawdown% calculating functions.
I needed a way to calculate the maxDD% of a serie of datas from an array (the different values of my balance account). I didn't find any builtin pinescript way to do it, so here it is.
There are 2 algorithms to calculate maxDD and relative maxDD%, one non optimized needs n*(n - 1)/2 comparisons for a collection of n datas, the other one only needs n-1 comparisons.
In the example we calculate the maxDDs of the last 10 close values.
There a 2 functions : "maximum_relative_drawdown" and "maximum_dradown" (and "optimized_maximum_relative_drawdown" and "optimized_maximum_drawdown") with names speaking for themselves.
Input : an array of floats of arbitrary size (the values we want the DD of)
Output : an array of 4 values
I added the iteration number just for fun.
Basically my script is the implementation of these 2 algos I found on the net :
var peak = 0;
var n = prices.length
for (var i = 1; i < n; i++){
dif = prices - prices ;
peak = dif < 0 ? i : peak;
maxDrawdown = maxDrawdown > dif ? maxDrawdown : dif;
}
var n = prices.length
for (var i = 0; i < n; i++){
for (var j = i + 1; j < n; j++){
dif = prices - prices ;
maxDrawdown = maxDrawdown > dif ? maxDrawdown : dif;
}
}
Feel free to use it.
@version=4
MinMax(20,50,100, 200)Draws minimum and maximum prices as a line chart for four different time frames.
1) The last 21 bars (close price)
2) The last 50 bars (close price)
3) The last 100 bars (close price)
4) The last 200 bars (close price)
Min/ Max values usually provide important resistance/ support levels.
Classical Min and MaxClassical tool for detection of Minimum and Maximum. Definition is given in the code.
Session min/max pointsAn improved version for minimum and maximum in a day trading session. You can choose the session resolution, it ranges from 1 minute to 1 week.
It works well for stocks and non-extended sessions due to security() function limitations.
Any suggestions, please leave a comment.
Happy trading.
Session min/max pointsMinimum and maximum points in a day trading session. It may help you spot the range which min and max occur in a session.
In day trading, for example, at securities like GBPNZD, minimum happens between 02:00-05:00 ET and maximum between 08:00-14:00 ET. This indicator can help you test this hypothesis.
Happy trading!
Min/Max Value Multiple Series FunctionTrying different solutions to find the minimum/maximum value in a set of predefined series