I am trying to get the avg entry price of any open trades as of the last bar. The intent is to plot a horizontal line across the chart at the avg entry price of any open trades. I am getting spurious values.
def nan = double.nan;
def cb = barnumber();
def lastBNonChart = HighestAll(if !isnan(close) then BarNumber() else nan);
def indexoffset = lastBNonChart - cb;
plot oep = getvalue(getaverageprice(), indexoffset);
Tried using getvalue() with getquantity() instead, but still spurious values.
plot oq = getvalue(getquantity(), indexoffset);
Tried using getvalue() with close and even that fails in a weird way.
plot gvclose = getvalue(close, indexoffset);
When accessing close via getvalue() theres a pattern to the values plotted. Last bar on chart has the accurate closing price, but [last bar - 1] has closing price of [last bar - 2] and [last bar -2] has closing price of [last bar - 4] and so on.
Appreciate any pointers/thoughts.
def nan = double.nan;
def cb = barnumber();
def lastBNonChart = HighestAll(if !isnan(close) then BarNumber() else nan);
def indexoffset = lastBNonChart - cb;
plot oep = getvalue(getaverageprice(), indexoffset);
Tried using getvalue() with getquantity() instead, but still spurious values.
plot oq = getvalue(getquantity(), indexoffset);
Tried using getvalue() with close and even that fails in a weird way.
plot gvclose = getvalue(close, indexoffset);
When accessing close via getvalue() theres a pattern to the values plotted. Last bar on chart has the accurate closing price, but [last bar - 1] has closing price of [last bar - 2] and [last bar -2] has closing price of [last bar - 4] and so on.
Appreciate any pointers/thoughts.