bbnm
bbnm

Reputation: 1094

How to do an action when an order is filled?

strategy.order("long tp", strategy.short, 1, longTP, alert_message=alert)

When "long tp" is filled it sends me an alert message. Is it possible to do a different action when this order is filled, like set color = color.blue ? What expression do I need to achieve this: if the order "long tp" is filled, color := color.blue

Upvotes: 0

Views: 113

Answers (1)

Andrey D
Andrey D

Reputation: 1714

If order was filled then the strategy position was changed. You can monitor the strategy position change and react on this. The example:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov

//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)

longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)

someOrderFilled = strategy.position_size != strategy.position_size[1]
plotshape(someOrderFilled, style=shape.xcross)

Upvotes: 3

Related Questions