# Crude Buy Sell Zone indicator by ANTHDKN 06.04.2021
# Free to use to all
# First posted on usethinkscript.com
# Auto entries from positions
input days = 3 ;
def avg = getaveragePrice();
def AreYouIn = if getquantity() != 0 then yes else no;
def Entry = if isNaN(avg) then Entry[1] else avg;
def LastEntryBar = if Entry != Entry[1] then barNumber() else LastEntryBar[1];
def BuyBarsAgo = if barNumber() != LastEntryBar
then barNumber() - LastEntryBar
else if barNumber() == LastEntryBar
then Double.NaN
else BuyBarsAgo[1];
AddLabel(AreYouIn,
"Cost: " +round(avg,2) +
(if GetOpenPL() > 0
then " | "+ "P/L: $" + GetOpenPL() +
" | "+ aspercent(getopenPL() / (avg * getquantity()))
else " | "+ "P/L: -$" + GetOpenPL() +
" | "+ aspercent(getopenPL() / (avg * getquantity())))
+ " | "+ " Bought: " +BuyBarsAgo +" days ago"
+(if BuyBarsAgo >= days then " SELL" else " "),
if GetOpenPL() > 500
then Color.cyan
else if GetOpenPL() > 0
then Color.DARK_GREEN
else Color.DARK_RED);
plot avgprice = if avg != 0 then avg else double.nan;
avgprice.setstyle(curve.SHORT_DASH);
avgprice.setdefaultColor(color.Yellow);