ATR Take Profit and Stop Loss
Forums › ProRealTime English forum › ProBuilder support › ATR Take Profit and Stop Loss
- This topic has 1 reply, 2 voices, and was last updated 1 year ago by Nicolas.
Tagged: atr, average true range, averagetruerange, NNFX ATR
-
-
09/15/2023 at 8:55 AM #221073
Hello could you convert this please from Tradingview into pro-real-time code
I have one I have been using but it is not as correct as this thank you
12345678910111213141516171819202122232425262728293031323334353637383940414243study(title = "NNFX ATR", shorttitle = "ATR", overlay = true, format = format.price, precision = 5) //Don't add scale = scale.right as the indicator will move all over the placeatrLength = input(title = "X", defval = 14, minval = 1)atrProfit = input(title = "TP", defval = 1, type = input.float)atrLoss = input(title = "SL", defval = 1.5, type = input.float)smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])function(source, length) =>if smoothing == "RMA"rma(source, atrLength)elseif smoothing == "SMA"sma(source, atrLength)elseif smoothing == "EMA"ema(source, atrLength)elsewma(source, atrLength)formula(number, decimals) =>factor = pow(10, decimals)int(number * factor) / factoratr = formula(function(tr(true), atrLength),5)//BuybAtrBuy = atrLength ? close + atr* atrProfit : close - atr* atrProfitbAtrSell = atrLength ? close - atr* atrLoss : close + atr* atrLossplot(bAtrBuy, title = "Buy TP", color = color.blue, transp = 0, linewidth = 1, trackprice = true, editable= true)plot(bAtrSell, title = "Buy SL", color = color.red, transp = 25, linewidth = 1, trackprice = true, editable = true)//SellsAtrBuy = atrLength ? close - atr* atrProfit : close + atr* atrProfitsAtrSell = atrLength ? close + atr* atrLoss : close - atr* atrLossplot(sAtrBuy, title = " Sell TP", color = color.blue, transp = 35, linewidth = 1, trackprice = true, editable = true)plot(sAtrSell, title = "Sell SL", color = color.red, transp = 50, linewidth = 1, trackprice = true, editable = true)//This one is way below price because I don't want there to be a 5th line inbetween the 2 TPs and SLsplot(atr, title = " Main ATR", color = color.yellow, transp = 0, linewidth = 1, editable = true)//---END---1. This is an indicator specially made for NNFX traders who use the ATR rule of ATR1x for Take Profit and ATR1.5x for Stop Loss
The indicator:
1. It can be used for a quick look using the lines to see instead of calculating whether price hit a TP or SL. However I have kept the Main ATR for those who want to record the ATR into the spreadsheet when back testing or forward testing
2. When placing a buy/long order, TP is blue and appears above price, SL is red and appears below price
3. When placing a sell/short order, TP is blue and appears below price, SL is red and appears above price
4. The Main ATR, which is yellow, is way below price because I didn’t want the chart to be overwhelmed by a 5th line in the middle of 2 TPs and SLs aka make the chart look claustrophobic09/15/2023 at 2:46 PM #221114Here is below the translated code for this NNFX indicator that display the ATR takeprofit and stoploss for both Buy and Sell orders:
123456789101112131415161718192021222324252627282930//NNFX ATRatrLength = 14atrProfit = 1atrLoss = 1.5smoothing = 1//formula(number, decimals) =>once factor = pow(10, 5)//int(number * factor) / factoratr = (averagetruerange[atrlength]*factor)/factor//formula(function(tr(true), atrLength),5)//BuybAtrBuy = close + atr* atrProfit //: close - atr* atrProfitbAtrSell = close - atr* atrLoss //: close + atr* atrLoss//plot(bAtrBuy, title = "Buy TP", color = color.blue, transp = 0, linewidth = 1, trackprice = true, editable= true)//plot(bAtrSell, title = "Buy SL", color = color.red, transp = 25, linewidth = 1, trackprice = true, editable = true)//SellsAtrBuy = close - atr* atrProfitsAtrSell = close + atr* atrLoss//plot(sAtrBuy, title = " Sell TP", color = color.blue, transp = 35, linewidth = 1, trackprice = true, editable = true)//plot(sAtrSell, title = "Sell SL", color = color.red, transp = 50, linewidth = 1, trackprice = true, editable = true)//---END---return bAtrBuy coloured("blue") as "Buy TP",bAtrSell coloured("red") as "Buy SL", sAtrBuy coloured("blue") as "Sell TP",sAtrSell coloured("red") as "Sell SL"2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on