TheObDur

Trailing Stop and Profit Taking

A starting point of a Stop Loss and Profit Taking idea.

Define a percent for Stop Loss and Profit Catch. This percent will be used to draw a blue line for profit catch, orange of stop loss, and a black line for where the order entered.

Blue diamond for Profit Catch, Orange for Stop Loss.

The entry and exits points in this script are only to invoke opens/closing of orders.





Find this useful, please donate or PM message for other goodies or projects :D
'BTC' : 1FkhMjjHxgE86YXbbBwQP9UU7GLCNfA8b4
'ETH' : 0xF06C21c75BB41f52Aa6152D50C59C9773Ee5D3fd
'LTC' : LVWrSFF9MeZF9GEXG63WRHbVRpv5qSPk74
Notas de Lançamento: A starting point for a Stop Loss and Profit Taking idea.

Define a percent for Stop Loss and Profit Catch. This percent will be used to draw a blue line for profit catch, orange for stop loss, and black for where the order entered.

Blue diamond for Profit Catch triggering, Orange for Stop Loss triggering.

The entry and exits points in this script are only to invoke opens/closing of orders.
Remover dos Scripts Favoritos Adicionar para Scripts Favoritos
This strategy has both integrated Trailing Stop and Trailing Take profit!
Resposta
Hello, very useful stuff in there!

One trouble for me: my open positions get their Stop Loss and Take Profit values from the ATR which is fine.

But if the position is still open (a "long" for example) when another one of my "long" signals comes along, the Stop Loss and Take Profit of the open order will adjust to the ATR of this new signal.

How can I prevent this and have my open position stick to the original ATR values till it exits?

(strategy.position_avg_price, is no good for me, as I prevents the closing of positions on the same candle they opened. That's why I turned to this script in the first place).

Pine Script beginner here, needless to say. Thanks for your help!



entryPrice=0.0
entryPrice:= nz(entryPrice)

stopLossLevel=0.0
stopLossLevel:=nz(stopLossLevel)

profitPriceLevel=0.0
profitPriceLevel:=nz(profitPriceLevel)

if(buySignal or sellSIgnal)
entryPrice:=close

//Set up StopLoss and TakeProfit
if buySignal
stopLossLevel := (1 - ATR_BK) * entryPrice
profitPriceLevel := (1 + ATR_BK) * entryPrice

if sellSignal
stopLossLevel := (1 + ATR_BK) * entryPrice
profitPriceLevel :=(1 - ATR_BK) * entryPrice

strategy.entry(id="Long", long = true, when=buySignal, qty=orderSize)
strategy.exit(id="close Long", from_entry = "Long", stop=stopLossLevel, limit=profitPriceLevel)

strategy.entry(id="Short", long = false, when=sellSignal, qty=orderSize)
strategy.exit(id="close Short",from_entry = "Short", stop=stopLossLevel, limit=profitPriceLevel)
Resposta
so this does not have a trailing stop...its only stoploss and take profit......can you clear this question please...thank you....this is a nice script by the way.
Resposta
Having some trouble getting this to work. It seems to generate a long entry whenever close of a short position. I can take out longEntry from shortExit condition and vice versa, but then I start to see short entries closed the moment they are opened, and I cannot figure out why.
Resposta
abwallet bodeen88
@bodeen88, Hi,please use

if(testPeriod() and (tradeType == "LONG" or tradeType == "BOTH" ))
strategy.entry("Long", strategy.long, when=longEntry)
strategy.exit("Exit Long", from_entry = "Long", when = longExit)

if(testPeriod() and (tradeType == "SHORT" or tradeType == "BOTH" ))
strategy.entry("short", strategy.short, when=shortEntry)
strategy.exit("Exit Short", from_entry = "Short", when = shortExit)

instead of given in the code, your dual quantity issue will resolve. The issue was strategy.entry was not able to see strategy.close. That's whenever both happens on same candle irrespective of long or short, the strategy.entry fire dual order i.e half to close the long/short and half for new position but already strategy.close has closed the order. I hope it helps.
+1 Resposta
bodeen88 abwallet
@abwallet, Hey thanks for the reply! I'm looking at the code you just posted and saying "Ohhhh, duuuH!" :) That makes sense. I knew it was something simple.
+1 Resposta
bodeen88 bodeen88
@bodeen88, by the way, great job writing this. I will be using it so thank you.
Resposta
Início Rastreador de Fundamentos Rastreador Forex Rastreador de Sinais Criptomoedas Calendário econômico Como Funciona Recursos gráficos Planos Regras da Casa Moderadores Soluções para sites e corretoras Widgets Soluções em Gráficos Obter Ajuda Solicitação de recurso Blog & Notícias FAQ Wiki Twitter
Perfil Configurações de perfil Conta e cobrança TradingView Coins Meus Tíquetes de Suporte Obter Ajuda Ideias Publicadas Seguidores Seguindo Mensagens Privadas Conversa Deslogar