Volume peaks strategy - rules set correctly?
Author: detim
Creation Date: 2/17/2018 11:36 AM
profile picture

detim

#1
Hi all,

I´m confused... I want to backtest a strategy based on volume. I´m looking for tradevolume 150% higher than 60 day average. With a long entry next bar using a Limit order on the high or to go short on a low. Then exit after a couple of days.

Additional I only trade stocks between 20 and 100 $, but that´s not relevant for my Problem. I copied the code which I created by the set of rules.

CODE:
Please log in to see this code.


When evaluating the results, the entry is not correct and I also receive trades for stocks higher than 100 $. I attached a Screen shot. This trade should have never been executed.

What is wrong?

Thank you for your help.

Best regards

Dennis
profile picture

Eugene

#2
Hi Dennis,

The undesirable result is caused by using Multi-Condition Groups. This advanced feature is sort of fuzzy logic i.e. not all the conditions in the group are required to have been true during a lookback period. Based on your description there is no need to apply it in your case. Let's water down your generated code to a more readable form then:

CODE:
Please log in to see this code.
profile picture

detim

#3
Hi Eugene,

thank you for your help. I copied your code and received some better results, but still not what I want to backtest. I attached a screenshort. The Intention is to simulate a short, when the price falls below the bar with high volume. In this case (attachment), there shouldn´t be any order execution, since there was an inside bar. But the system simulated a long order, which was closed with a loss.

How can I code this?

Thank you!

Regards, Dennis
profile picture

Eugene

#4
Dennis,

There should be a buy order execution despite that you're currently thinking the opposite. You do not know there's an inside bar yet to be. That's because the limit order is set on the previous bar. Was the open of the inside bar lower than the Limit price i.e. High[bar]? Yes. Hence the order. This happens because the buy side is given priority in my code by placing it first:

CODE:
Please log in to see this code.


You could simply reverse the order if you like and this short order wouldn't be taken. However, there'll always be a risk of an OHLC bar with the opposite scenario.

CODE:
Please log in to see this code.

profile picture

detim

#5
Hi Eugene,

thank you very much for your next answer. This is very interesting. Let me ask: Is there any possibility with WL, to simulate my idea:

Long order, if price raises above high of the high volume bar OR
short order, if price falls below low of the high volume bar?

Thank you so much for helping me.

Best regards

Dennis
profile picture

Eugene

#6
There's almost always a possibility but please make sure to have read this FAQ first:

I want to test a strategy that buys and sells with stop/limit orders on the same bar.

Feel free to correct me but I think this may apply to your question.
profile picture

detim

#7
Hi Eugene,

thank you, that´s again very helpful. Unfortunately I do not have any programming skills so far. Seems that I´ll have to teach myself. But until I´ll have a basic knowledge, can you maybe help me where to insert this code into my code?

Best regards

Dennis
profile picture

Eugene

#8
Hi Dennis,

As long as you avoid SetTimeOfDayPriority which requires intraday data, you could use IntradayFillPriorityEstimate like this:

CODE:
Please log in to see this code.


Note, however, that this isn't the silver bullet. It only applies to trade selection in a portfolio backtest when there are multiple trade candidates to pick from and not enough capital to satisfy all trades. In my opinion you've had the most appropriate solution as of post #4 because it's your trading idea expressed in post #1 that lead to ambiguous results.

Having re-read your post #5, I think you need to replace Limit orders with Stop orders. Consequently:

CODE:
Please log in to see this code.


Problem solved?
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).