Reputation: 1
This is in the area of handling stop loss in a strategy. The stop loss code is as below:
**stop_level_long =iff (barcountLongEntry>1,max( strategy.position_avg_price * (1 - sl_long),longStopTrail),0) take_level_long = strategy.position_avg_price * (1 + tp_long) strategy.exit("Stop/Target Long", "Long", stop=stop_level_long, limit=take_level_long,when=window)//
Sometimes the move for triggering the stop loss is also triggering the short entry in the same bar. This results in maximum contracts exceeding 1 even when the pyramiding is set to 1. Thanking all in advance for the help.
Upvotes: 0
Views: 270
Reputation: 430
Strategy.exit() does not take inputs as price
for eg, strategy.exit("Long position", stop = 500) //assume 500 is your stoploss
is not valid. The inputs have to be in ticks.
A workaround is like this:
stopTicks = (long_entry_price - stopLoss)/syminfo.mintick
strategy.exit("Long position",stop = stopTicks)
Upvotes: 0