multiple position strategy using multiple moving averages
Author: asurapan
Creation Date: 1/30/2009 1:50 AM
profile picture

asurapan

#1
i am trying to code a strategy using multiple moving averages. Here is what I am trying to do:
1) Buy when C crosses above SMA1
2) Buy when C crosses above SMA1
3) Buy when SMA1 crosses above SMA2

4) Sell when C crosses below SMA1
5) Sell when C crosses below SMA2
6) Sell when SMA1 crosses below SMA2

The problem I am having is that I want the the exit signal parameters to be the same as the entry signal pareamaters. (ie: if buy when SMA1 crosses above SMA2; then the position can only be exited when SMA1 crosses below SMA2). With the code I have below, the position is being closed by a different cross scenario.

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

Eugene

#2
QUOTE:
The problem I am having is that I want the the exit signal parameters to be the same as the entry signal pareamaters. (ie: if buy when SMA1 crosses above SMA2; then the position can only be exited when SMA1 crosses below SMA2).


For that you need to query the EntrySignal property and exit only if it matches:
CODE:
Please log in to see this code.
profile picture

asurapan

#3
Thanks Eugene. "p.EntrySignal == " was the key.
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).