Lowest value of multiple moving averages
Author: CarmaAdvisory
Creation Date: 9/30/2016 2:16 PM
profile picture

CarmaAdvisory

#1
Hi all, supposing I have 3 moving averages with 3 different lenghts. Which is the most efficient way to create a date series that is the lowest value of these moving averages. I use a loop with if else statements but i think it isn't the better way.

Thank you for your help
profile picture

Eugene

#2
Hi,

Community.Indicators has two auxiliary DataSeries, Highest2 and Lowest2, which return the highest (lowest) of two series (respectively). Using them you can practically get a one-liner solution:
CODE:
Please log in to see this code.

Warning: these helpers are rudimentary as they don't expect in principle that the DataSeries you pass to it may have different bar counts. As they're not universal, no synchronization or bound checking is going on under the hood at all. Make sure you pass two DataSeries of equal length i.e. not based on several Bars objects with a different bar count.
profile picture

CarmaAdvisory

#3
Thank you very much Eugene
profile picture

CarmaAdvisory

#4
May I use more then 3 moving averages?

I tried to code this without success...
profile picture

Eugene

#5
Sure:
CODE:
Please log in to see this code.

Ideally you'd need a new universal procedure (independent of the Lowest2). It would accept a List of DataSeries and loop by their values at a given bar.
profile picture

Eugene

#6
Or give this a try:
CODE:
Please log in to see this code.


Not universal yet but much easier for you to extend:

CODE:
Please log in to see this code.
profile picture

CarmaAdvisory

#7
Thank you very much, I try this