Support Board
Date/Time: Sun, 09 Feb 2025 04:21:00 +0000
Post From: Moving Average Value at Start of Bar
[2020-08-04 00:55:18] |
rahul - Posts: 167 |
Hello, without replaying a chart I want to find the moving average value at the start of a new bar. For example a 5 period moving average fluctuates a lot from the time a bar opens till it closes. Looking at a static chart, its easy to determine the value of the moving average (which is always the value at the close of the bar), but how do you know the value when the bar was opened? I tried the following code, but it doesn't work in this respect. int& PriorArraySize = sc.GetPersistentInt(1); float& MovAvgValue = sc.GetPersistentFloat(1); sc.SimpleMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 5); if (sc.Index == 0) { PriorArraySize = sc.ArraySize; } // If there are new bars added if (PriorArraySize < sc.ArraySize) { MovAvgValue = sc.Subgraph[0][sc.Index]; } PriorArraySize = sc.ArraySize; |