Coding stop loss 2% below SMA
Author: brucetravali
Creation Date: 6/6/2011 6:03 PM
profile picture


I'm new to WL, so I apologize if this is a basic question but here it goes....

I'm trying to set a sell order at certain percentage below a moving average. I'm using weekly bars. My problem is that I want the sell order to trigger exactly at 2% below the 22 bar sma.

If I enter the "sell at close" option, it will always trigger at the closing price on that day. If I enter "sell at market", it will trigger at the open on the next bar.

Does anyone know how to have the sell order trigger as soon as it hits (crosses over) a certain indicator, in this case 2% below the 22 sma?

profile picture


The nature of your question suggests you're not coding - because you'd just pick SellAtStop and settle with that - but using the rule wizard. Problem is, such type of order isn't feasible with Rules.

Below is an illustration of two of the possible approaches: 1) define the SMA offset by 2% and 2) simply subtract a percentage from the 22-week SMA:

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).