Functions by Category Functions by Alphabetical list
PlaceStopLoss ([label], [stop price]) |  | This function places a stop loss order only if there is a position for the current symbol. The actual order that is placed is either a buy or sell stop depending if the position is short or long. There are two important aspects to this function:
- This function only places a buy/sell stop if there are no other orders for the current symbol (once the bar event has completed, not at the time of calling PlaceStopLoss)
- Orders created as a result of this order are automatically cancelled before the next bar event is executed.
These two factors make it easy to create various stoploss strategies without having to manage the actual orders. Consider the simple trading system below:
unless ( Position) {
PlaceBuyOpen('Enter Long',1000) if Crossover(EMA(Close,12),EMA(Close,26));
}
else {
PlaceSellOpen('Exit Long',1000) if Crossunder(EMA(Close,12),EMA(Close,26));
}
PlaceStopLoss('Trailing',EnterPrice-Now(ATR(45)));
This trading system is the classic moving average crossover, with a dynamic trailing stop loss of 1 ATR always being maintained.
When there is no position, PlaceStopLoss does not create an order - so it's safe to use the function without having to check for an existing position. When we have a position, PlaceStopLoss will always create a SellStop order, with the Stop being 1 unit of ATR below the entry price. As the order is automatically cancelled before the next bar event, you will not end up with multiple active stop orders. When we have a sell signal, we exit the position with a Sell market order. As we have manually created an order for this position, the stop loss order will not be created.
Examples: PlaceStopLoss('LowClose',Lowest(Close,5));
#Place the stop at the lowest close of the last 5 bars
Related functions: BuyOpen , SellOpen , SellStop , BuyStop , BuyLimit , SellLimit , BuyStopLimit , SellStopLimit , StopLoss , PlaceBuyOpen , PlaceSellOpen , PlaceBuyStop , PlaceSellStop , PlaceBuyLimit , PlaceSellLimit , PlaceBuyStopLimit , PlaceSellStopLimit , NextBarOpen , PlaceSellMarketClose , PlaceBuyMarketClose , PlaceBuyAtPrice , PlaceSellAtPrice , OnFill
|