#Example of Average Entry Price with stops
# Plotting Average Actual Entry with ATR stops
# Mobius
# 01.01.2018
input AtrMultiplier = 2.00;
input Atr_Length = 5;
input Dir = {default long, short};
plot hide = double.nan;
hide.setDefaultColor(Color.Black);
def c = if isNaN(close[-1]) then close else c[1];
def ATR = Average(TrueRange(high, close, low), Atr_Length) * AtrMultiplier;
def Entry = if isNaN(GetAveragePrice())
then Entry[1]
else GetAveragePrice();
def LastEntryBar = if Entry != Entry[1]
then barNumber()
else LastEntryBar[1];
plot Entry_ = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1])
then Entry
else double.nan)
else double.nan;
Entry_.SetStyle(Curve.Long_Dash);
Entry_.SetLineWeight(3);
Entry_.SetDefaultColor(CreateColor(255,215,0));
Entry_.HideBubble();
Entry_.HideTitle();
def PL = if Entry > 0 then Entry - c else 0;
#AddChartBubble(barNumber() == HighestAll(barNumber()), Entry_, "AVG " + AsDollars(Entry), Entry_.TakeValueColor());
plot stop;
stop.SetLineWeight(2);
stop.SetdefaultColor(color.red);
switch (Dir)
{
case long:
stop = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1])
then Entry - ATR
else double.nan)
else double.nan;;
case short:
stop = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1])
then Entry + ATR
else double.nan)
else double.nan;;
}
plot tgt;
tgt.SetLineWeight(2);
tgt.SetdefaultColor(color.green);
switch (Dir)
{
case long:
tgt = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1])
then Entry + ATR
else double.nan)
else double.nan;;
case short:
tgt = if barNumber() >= HighestAll(LastEntryBar) and Entry > 0
then highestAll(if isNaN(close[-1])
then Entry - ATR
else double.nan)
else double.nan;;
}
# End Code