1. I want to Buy at a moving average.
2. I want to set a target 2 points higher.
3. I want to set a stop 2 points lower.
4. If either stop or target gets hit I want the corresponding target or stop canceled.
This doesn't seem to work though. The targets seem to work but not the stops!?!?
buy("My Buy") next bar (MovingAverageFast) limit;
sell("My Target") entry("My Buy") next bar (MovingAverageFast + 2) limit;
sell("My Target") entry("My Buy") next bar (MovingAverageFast - 2) stop;
Adding a Stop and Target to a Buy Order
-
- Posts: 261
- Joined: 28 Feb 2008
- Has thanked: 2 times
- Been thanked: 1 time
-
- Posts: 100
- Joined: 17 Jul 2009
- Location: Germany
You have to use different labels for all exits being used. E.g. you can´t use "My Target" as a label for an exit more than 1 time.
This compiles and works correctly:
var: MovingAverageFast(0);
MovingAverageFast=xaverage(close, 10);
buy("My Buy") next bar (MovingAverageFast) limit;
sell("My Target") entry("My Buy") next bar (MovingAverageFast + 2) limit;
sell("My Stop") entry("My Buy") next bar (MovingAverageFast - 2) stop;
This compiles and works correctly:
var: MovingAverageFast(0);
MovingAverageFast=xaverage(close, 10);
buy("My Buy") next bar (MovingAverageFast) limit;
sell("My Target") entry("My Buy") next bar (MovingAverageFast + 2) limit;
sell("My Stop") entry("My Buy") next bar (MovingAverageFast - 2) stop;
-
- Posts: 261
- Joined: 28 Feb 2008
- Has thanked: 2 times
- Been thanked: 1 time
Thanks I was able to resolve this issue. Had to do with having my my stop and target statements in a an if statement that causing problems.
I have another question.
I want my program to wait for 5 bars after any position has been stopped out before initiating any new trades.
Are there any useful functions that can help with this?
I have another question.
I want my program to wait for 5 bars after any position has been stopped out before initiating any new trades.
Are there any useful functions that can help with this?