Thebattlefront Posted October 17, 2022 Report Share Posted October 17, 2022 (edited) I am aware of using the GetHighLow function to track the yearly high and yearly low at a particular bar using the StateFifoQueue, aka: HighLow.Add(High); HighLow.Add(Low); double High52, Low52; HighLow.GetHighLow(out High52, out Low52); I was wondering, though, how do I create a variable that tracks, let's say, the average percent gain per bar of a security (m_dGainPercentAveragePerBarPerSecurity), or maybe something like the Average winrate of a paintbar (m_dAverageWinrate), or some other arbitrarily defined variable? You mentioned in another thread i could use Statefifoqueue to take averages over a smaller space rather than averages over the entire space, and I assume this relates to calculation of these values in some way. Edited October 17, 2022 by Thebattlefront Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted October 17, 2022 Report Share Posted October 17, 2022 It's the same way. You define a new StateFIFOQueue(n) - where n is the period. You use the state function to save state/restore state for that queue. Every maincalc you .Add whatever it is to the queue. The Queue's Average property will hold the average. It also has StDev, WeightedAverage etc... Quote Link to comment Share on other sites More sharing options...
Thebattlefront Posted October 18, 2022 Author Report Share Posted October 18, 2022 Okay, I think I understand. I also found the medved help article on this so I probably should have looked there first. Thanks Mike Quote Link to comment Share on other sites More sharing options...
Thebattlefront Posted October 20, 2022 Author Report Share Posted October 20, 2022 (edited) One more thing - what's the syntax difference between using Q.WeightedAverage and Q.Average? Since the fifoqueue Q only holds a single set of real values (let's say, for example, Q = {1, 2, 3, 4, 5}), how do I apply a weight to Q? The reason I ask is because, it would appear that I can use Q.WeightedAverage or Q.Average on the same line and it returns no errors. But where are the weights coming from exactly in the program when I set a variable equal to Q.WeightedAverage? Does it just apply a weight of 1 to each value if I don't specify a new set P that contains the weights for Q? Edited October 20, 2022 by Thebattlefront Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted October 22, 2022 Report Share Posted October 22, 2022 The weight is a 1-based position in the queue from start to end. So for your example it is (1*1+2*2+3*3+4*4+5*5)/(1+2+3+4+5) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.