Jump to content
Medved Trader Forums

# @Mike How do I use the StateFIFOQueue to track my paintbars performance (let's say, the winrate of a paintbar on a particular security?)

## Recommended Posts

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 by Thebattlefront
##### Share on other sites

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...

##### Share on other sites

Okay, I think I understand. I also found the medved help article on this so I probably should have looked there first.

Thanks Mike

##### Share on other sites

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 by Thebattlefront
##### Share on other sites

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)

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
×
• Create New...