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.
Size:
Color:
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.
Size:
Color:
Thanks Eugene. "p.EntrySignal == " was the key.
Size:
Color: