# #################################
# ATR Stop & Target based on buy price
# requested by tigerWares
input ATRStopMultiple = 1.5;
input ATRTargetMultiple = 1.0;
input length = 14;
input averageType = AverageType.WILDERS;
def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def BuyPrice = GetAveragePrice();
def PL = GetOpenPL();
def Target = BuyPrice + (ATR * ATRTargetMultiple);
def Stop = BuyPrice - (ATR * ATRStopMultiple) ;
# #################################
# Charting & Formatting
addlabel(yes, "TARGET: " + round(Target,2) +" | "+ " STOP: " + round(Stop,2) , color.dark_orange);
plot TargetLine = HighestAll(if IsNaN(Close[-1]) then Target else double.NaN);
plot StopLine = HighestAll(if IsNaN(Close[-1]) then Stop else double.NaN);
#Sase
#Add bubble above the the current candle if there is an open position
#If PL is positive then green else yellow
AddChartBubble (GetQuantity () != 0 and isnan(close[-1]), high, "buy price" +"\n"+ round(BuyPrice,2),if PL > 0 Then Color.GREEN Else Color.YELLOW, Yes);