Adding a Stop and Target to a Buy Order

Questions about MultiCharts and user contributed studies.
flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Adding a Stop and Target to a Buy Order

Postby flipflopper » 18 Jan 2010

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;

geektrader
Posts: 100
Joined: 17 Jul 2009
Location: Germany

Postby geektrader » 18 Jan 2010

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;

flipflopper
Posts: 261
Joined: 28 Feb 2008
Has thanked: 2 times
Been thanked: 1 time

Postby flipflopper » 19 Jan 2010

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?

tcat
Posts: 166
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

Postby tcat » 20 Jan 2010

You can either use marketposition[x]<>0 to prevent trading, or define your stop out as a trigger to enable a countdown whenever the exit price level is reached.


Return to “MultiCharts”