Stop and reverse strategy based on SMA crossover/crossunder
Author: caseyjay_48
Creation Date: 10/25/2008 8:23 PM
profile picture

caseyjay_48

#1
First Post for new member!
Trying to make simple strategy based on fast/slow SMA crossover on crossunder
On crossunder, I want to sell my long and begin a short
On crossunder, I want to cover my short and begin a long

My code(below) will not trade past beginning the short, even though running them separately will get all of the crosses.

Any help would be appreciated (or a ref if this has already been solved)

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

Eugene

#2
Welcome to the forums.

Here is your stop and reverse system:
CODE:
Please log in to see this code.

Can you elaborate on those on-tomorrow's-close orders?
profile picture

caseyjay_48

#3
Thanks for the example Eugene!
Obviously you already had thought about this.
The particular entry and exit criteria that I had in my post were just made up to be simple, so I wouldn't get confused when someone like yourself offered some help. The main thing I was looking for was the code logic of the reversal from "bear" to a "bull" conditions involving a long and short posistion.
When I detect "bear" conditions, then I would sell my long and then go short.
When I detect "bull" conditions, then I would cover my short and then go long.
"Bull" and "bear" being mutually exclusive.

My criteria to detect "bull" or "bear" conditions are more complex than shown.

I haven't go a chance yet to incorporate your code suggestions, but I will report on their success.
Tnx Again!!
profile picture

Eugene

#4
QUOTE:
My criteria to detect "bull" or "bear" conditions are more complex than shown.

Anticipating this, the dummy conditions were moved into a pair of boolean variables (maXo, maXu) to easily swap with different ideas.
profile picture

gbullr

#5
Eugene or Cone.

Would you mind adding a cooledoff thing to the above code.

I am having a hell of a time doing it.

Thanks.

profile picture

Eugene

#6
Well, let's see how you're doing it and we'll explain what's wrong in there. Show us what you've come up with.
profile picture

gbullr

#7
For example.

In the code below there are trade on 9/11 and 9/12 so there does no appear to be a delay.

I am trading this fred download: BAMLHYH0A0HYM2TRIV

Thanks again.

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

Eugene

#8
The way you applied CooledOff is that it affected exits. Here's the corrected revision fixing another error and making something more streamlined:

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