Limiting Trading Frequency
Author: ronc
Creation Date: 9/8/2015 11:15 PM
profile picture

ronc

#1
I want to prevent my strategy from trading too frequently, by imposing a minimum number of bars between trades. I have done this:

CODE:
Please log in to see this code.

This does not work, I suspect because my trades work on the next bar, e.g.
CODE:
Please log in to see this code.

Therefore, if I set up a trade at bar N, it is planned to execute at bar N+1, and when the code loops through bar N+1 apparently that trade has not executed so the above code does not detect it as the most recent trade. Is there a workaround, or hopefully some simpler way to accomplish this (this meaning limit trading frequency to more then every X bars)?

I considered setting an integer value for the latest trade bar very time my code does (or plans) a trade, but I think that is an invitation to bugs, because there are many different places in my code that do trades under different conditions (e.g. open a single long or short position, CloseAllLongPositions(), close all positions that meet certain criteria, etc). and keeping the logic consistent among these different areas will be challenging. Better to have it in single place at a lower level.

Thanks,
Ron
profile picture

Eugene

#2
This function in Community Components causes a Strategy to wait for a certain period of time before entering a new position once the preceding position is closed:

CooledOff
profile picture

ronc

#3
Actually what I am trying to do is inhibit any trades (both opening and closing positions) based on any previous trade (both opening and closing).
profile picture

Eugene

#4
I inserted your code from post #1 into the built-in "Moving Average Crossover" and it worked as expected.
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).