External 3 Bar Switcher
Author: swuzy
Creation Date: 4/17/2009 9:40 AM
profile picture

swuzy

#1
I would like to try a strategy which references an external symbol .SPX, such that if .SPX is down three successive bars, the regular trading rules are suspended and I stay out of the markets ... until the .SPX is up three successive bars, upon which my regular trading rules are activated and stay activated, until the .SPX is down three successive bars, etc.

Please, I would really appreciate help on the coding for this.
profile picture

Eugene

#2
Probably you were looking for something like this?
CODE:
Please log in to see this code.
profile picture

Cone

#3
I don't think that will work Eugene. Either boolean will be false as soon as the Cum series is not >= 3, which is not the requirement. Anyway, I think you need only one of those -

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

swuzy

#4
Thank you Cone and Eugene. For Cone's last set of If, Else, should it actually be three sets of whatevers?

I was probably not clear enough earlier. On Suspend Trading, I would like to sell off all positions, then on Not Suspend Trading, return to regular selling and buying.

So, should it be something like (I know, I mangle it):

CODE:
Please log in to see this code.


But maybe that is already accounted for?

Thanks for clarification.
profile picture

Cone

#5
"all positions" implies that you want a multi-position script. In that case you shouldn't use LastPosition logic. Here's the template -

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

swuzy

#6
Wonderful! Thank you Cone.

A question (I could not find anything in the F1 search), are CumUp.Series and CumDown.Series limited as to how many bars they look back or encompass for testing the condition? Is there any need to reference how many number of bars back to test the condition? For example, perhaps 30 bars is not good enough, but maybe 120 bars bars should be tested?

From your code, it appears not, but I have to ask.

For example is there any need to increase the number of bars in the normal trading loop below?

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

Cone

#7
You're only interested in 3 consecutive ups or downs, so you should start at bar 3. 3 bars (actually 4 to determine 3 up or down closes) is sufficient lookback for the condition. Other conditions in your final script may require more bars.
profile picture

swuzy

#8
I am not sure I follow your meaning.

If I run the strategy today, and the last three consecutive ups or three consecutive downs was a three consecutive down two months ago, I don't want to enter the market. Would this code keep me out of the market?

Thanks for clarifying.
profile picture

Cone

#9
Test it and see for yourself. Adjust the dates if you have to.
profile picture

swuzy

#10
Sorry again. I am such a dumb kof.

To test it, I tried to integrate it w/ the 33 liner, but no trades are generated. Can you help again, please? Thank you.

CODE:
Please log in to see this code.


profile picture

Cone

#11
CODE:
Please log in to see this code.
// Gosh, I thought it was clear, but this was something that you needed to replace, not use. This is an arbitrary condition that returns true every 100 bars (% is the modulo operator in C#).

Besides that, 2 loops and misplacement of block delimiters (terrible use of blocking - I'm not even sure how you can force this in the Editor) were the other problems. I still can't understand why you'd try to use nested loops here - "suspend routine"? Huh?

CODE:
Please log in to see this code.


profile picture

swuzy

#12
Thank you very much for your help, Cone.

This idea seems to be of very marginal or slight help to a couple of very aggressive Watch Lists I have;
otherwise though, on the vast majority of my Watch Lists, the chokedown in performance it seems make it generally an overall net loser. :(

Thanks again.



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