Define trailing stop in pinescript

71 views Asked by At

Is there a possibility in the pinescript code to include an initial stop order that is, for example, at 65 pips and then updates according to price changes with the trailling stop?

Can define and initial stop loss and after chage this stop loss with the trailing stop

1

There are 1 answers

0
Gu5tavo71 On

With the information you provided, it’s difficult to answer your question.
Try strategy.exit with trail_offset

Something like this:

// Return the entry price for the latest closed trade.
currEntryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)

//Stop loss (specified in ticks)
SL_ticks = 65

//Trailling Stop (specified in ticks)
TR_ticks = 10


if strategy.position_size > 0
    strategy.exit(
      id               = 'Long Exit',
      from_entry       = 'Long',
      loss             = SL_ticks,
      trail_price      = currEntryPrice,
      trail_offset     = TR_ticks)