Support Board
Date/Time: Tue, 22 Apr 2025 21:05:47 +0000
[Programming Help] - Is there a Moving Average - Time Period ASCIL function or similar?
View Count: 181
[2025-01-04 22:11:44] |
ATEX - Posts: 25 |
Hi, I find the study "Moving Average - Time Period" to be very neat and it would be very useful for me to have it as an ASCIL function. Is there any such ASCIL function, or a similar one? I can not find it. Best, A Date Time Of Last Edit: 2025-01-04 22:12:13
|
[2025-01-05 02:53:42] |
cmet - Posts: 690 |
No, but you can create one, // Function to calculate Moving Average Time Period
void CalculateMATPFunction( SCFloatArrayRef InputArray, SCFloatArrayRef OutputArray, SCDateTimeArrayRef DateTimeArray, SCDateTime TimePeriodLength, int StartIndex, int EndIndex, SCStudyInterfaceRef sc) { int LookbackStartIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber, (DateTimeArray[StartIndex] - TimePeriodLength).GetAsDouble()); for (int BarIndex = StartIndex; BarIndex < EndIndex; BarIndex++) { float Sum = 0; int Count = 0; for (int LookbackIndex = LookbackStartIndex; LookbackIndex <= BarIndex; LookbackIndex++) { if (InputArray[LookbackIndex] == 0.0f) continue; Sum += InputArray[LookbackIndex]; Count++; } if (Count > 0) OutputArray[BarIndex] = Sum / Count; else OutputArray[BarIndex] = 0; if (BarIndex < EndIndex - 1) { SCDateTime NewLookbackStartDateTime = DateTimeArray[BarIndex + 1] - TimePeriodLength; while (true) { SCDateTime CurrentAbsoluteTimeDifference = SCDateTime(DateTimeArray[LookbackStartIndex] - NewLookbackStartDateTime).GetAbsoluteValue(); SCDateTime NextAbsoluteTimeDifference = SCDateTime(DateTimeArray[LookbackStartIndex + 1] - NewLookbackStartDateTime).GetAbsoluteValue(); if (NextAbsoluteTimeDifference > CurrentAbsoluteTimeDifference) break; LookbackStartIndex++; } } } } |
[2025-01-05 18:19:58] |
ATEX - Posts: 25 |
Thank you so much for this!
|
To post a message in this thread, you need to log in with your Sierra Chart account: