JavaScript Function that calculates SMI Ergodic Indicator

Job ID: 35171994

Budget: $10 – $30 USD

I need a JavaScript function that takes in an array of stock price data and some SMI parameters and outputs an object containing information about the current values of the SMI indicator and whether it crossed above or below the signal line at the last price data point provided. I would like there to be a console.log() of the arguments received by the function and the object to be returned at the end of the function. You will likely need to do some research on how to calculate the SMI Ergodic Indicator. It is not the SMI Ergodic Oscillator, it's the SMI Ergodic Indicator.

The function should take in:
-An array of n price data points
-The three SMI Ergodic parameters: Long Length, Short Length, and Signal Line Length -- as an array containing these three values.

The function should return an object, like this:
{
validInput: [true or false],
smiCrossedAboveSignalLine: [true or false],
smiCrossedBelowSignalLine: [true or false],
}
validInput: this should be true if the SMI with the given parameters was able to be calculated with the amount of data points given, and there was an extra point of SMI able to be calculated to determine if the most recent data point caused the SMI to cross above or below the signal line.
smiCrossedAboveSignalLine: this should be true if the last calculated SMI data point showed that the most recently calculated SMI value is above the signal line value, with the previous calculated SMI value having been below the signal line value.
smiCrossedBelowSignalLine: this should be true if the last calculated SMI data point showed that the most recently calculated SMI value is below the signal line value, with the previous calculated SMI value having been above the signal line value.

Other function requirements:
If enough price point data is provided as arguments to construct more than 2 periods (data) of the SMI Ergodic, then only calculate the most recent two. For example, if you need only 10 data points to calculate the SMI for a given input, you would need 11 data points to make 2 SMI calculations. If more than 11 data points are provided, just use the last 11 data points.

Required:
Please check your work using the following test with AAPL stock data:

Input:
[138.38, 142.41, 143.75, 143.86, 143.39, 147.27, 149.45, 152.34, 149.35, 144.80, 155.74], [10, 5, 5]
Answer:
{
validInput: true,
smiCrossedAboveSignalLine: true,
smiCrossedBelowSignalLine: false,
}

I will perform a few more tests while looking over your function submission.
Related categories: JavaScript Mathematics Charts