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

alsilva86

#1
Hello!

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

CODE:
Please log in to see this 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:
Please log in to see this 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:
Please log in to see this code.
profile picture

Eugene

#2
Same gotcha:
CODE:
Please log in to see this 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:
Please log in to see this code.


#2
QUOTE:
Close[0] > 5


Did you mean this?
CODE:
Please log in to see this code.
profile picture

alsilva86

#3
Very helpful! Thanks a lot!
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:
Please log in to see this code.
profile picture

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

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:
Please log in to see this 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!
profile picture

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

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:
Please log in to see this code.

profile picture

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:
Please log in to see this code.
profile picture

Eugene

#9
A little code cleanup for better readability:
CODE:
Please log in to see this code.
profile picture

alsilva86

#10
Hello!

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


CODE:
Please log in to see this 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
profile picture

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.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).