Don't trade if Volume 30 days average > X
Author: alsilva86
Creation Date: 9/10/2017 4:15 PM

#### alsilva86

#1
Hello!

I wanted you guys to show me what I'm possibly missing:

CODE:

Is this the best way to calculate the thirty days volume mean in shares?

This is something I got lost look at this snippet:

CODE:

This was the output produced

203,14 qtdMax
193150 mediaVolume
if mediaVolume is 193150 how can that be 203,14 when * 0.001?

And finally based on this validation I have this

... && Close[0] > 5 ...

I want to trade stocks that its close yesterday is higher than 5, is that the best way to if before sending orders? like this:
CODE:

#### Eugene

#2
Same gotcha:
CODE:

Fix your integer division as suggested here:

My script behaves unexpectedly

P.S.

#1

QUOTE:
Is this the best way to calculate the thirty days volume mean in shares?

Yes if you like to reinvent the wheel but it's already done ;)

CODE:

#2
QUOTE:
Close[0] > 5

Did you mean this?
CODE:

#### alsilva86

#3
I am trying to put this code snippet to run with several symbols, tried with a 10 stocks dataset worked perfectly but when I set it to my full dataset it takes ages and never leaves the screen status I sent attached.

Do you have any symbol numeric limitation ?

Here's full code in case I am doing something that is slowing the tests:

CODE:

#### Eugene

#4
QUOTE:
Do you have any symbol numeric limitation ?

Consider doing something about your multiple while loops inside the main (trading) loop. This is the bottleneck - and not some "limitation" in the software.

#### alsilva86

#5
I've thought and nothing came up so far, dont you have anything similar to the Volume statistics regarding the position size?
As the code shows, all I want is to limit exposition using while.

EDIT:

The snippet below is our badboy:

CODE:

I thought about dividing the financial per position per quantity to estimate how many orders I would shoot in hundreds
ie

financial/close = 400

that will be 4 orders of 100 but even in that case I would have to do a FOR using that variable, is that somehow better than my while ?

BR

EDIT 2:

With some patience it happens, test finished now. If you guys have any recommendation for me, let me know but for now I'm satisfied! Thanks for your help!

#### Eugene

#6
You're welcome.

P.S.
QUOTE:
that will be 4 orders of 100 but even in that case I would have to do a FOR using that variable, is that somehow better than my while ?

Tweaks like estimation of order count is usually a good idea to try but choice of loop (vs. while vs. for) generally shouldn't affect performance.

#### Cone

#7
QUOTE:
Is this the best way to calculate the thirty days volume mean in shares?
Use the SMA.Series() indicator to calculate an moving average over a series. Or you can use SMA.Value() if you only need to calculate it on an ad-hoc basis.

CODE:

#### alsilva86

#8
@Cone and @Eugene thanks again! I am working hard to make it better using your solution.

Can you please make your critics with this code below? I want to dilute financial on quantities so I want to have few quantities with more interesting risk/reward, check this code now that validates the financial I want to trade instead of for or while ing it.

What are your thoughts? Does this looks better?
CODE:

#### Eugene

#9
A little code cleanup for better readability:
CODE:

#### alsilva86

#10
Hello!

I just realized on my code that there are two different references for the same thing(I believe so):

CODE:

When I assign Close without []'s to lb what values goes to it ? What would be the difference if in Close[bar] I used lb[bar], instead?

BR

Andre

#### Eugene

#11
QUOTE:
When I assign Close without []'s to lb what values goes to it ? What would be the difference if in Close[bar] I used lb[bar], instead?

See the WealthScript Programming Guide > DataSeries - and Accessing a Single Value from a DataSeries in particular.