Hello,
I'm hoping someone can help with an issue I'm having.
I have a simple study that shows a label on the chart with the quantity of shares I have, either long or short.
Randomly it just gets stuck, and I'm not sure if it's on the Ameritrade side or the TOS side.
For example, a couple of months ago I exited a short position on NIO, but the quantity still shows -3. I've tried everything but it won't reset.
However if I have active trader open, I see that the position is flat.
If I make another trade, let's say 50 shares long, I will see 47 on the chart, because it's subtracting the -3 shares that are stuck in the system.
Does anyone know how to reset the GetQuantity() total?
Thanks
There's really not much to the study, here it is below:
def PL = GetOpenPL();
def c = if IsNaN(close[-1]) then close else c[1];
def Entry = if IsNaN(GetAveragePrice()) then Entry[1] else GetAveragePrice();
def openCost = GetQuantity() * GetAveragePrice();
def PercentPL = GetOpenPL() / AbsValue(openCost) * 100;
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.FIRM);
Entry_.SetLineWeight(1);
Entry_.SetDefaultColor(Color.WHITE);
Entry_.HideBubble();
Entry_.HideTitle();
AddLabel(1, "Q" + GetQuantity() +
" A$" + Entry +
" A%" + PercentPL + "%" +
" T$" + openCost +
" P " + AsDollars(PL),
if PL == 0 then Color.CYAN
else if PL > 0 then Color.GREEN
else Color.RED);
# end code
I'm hoping someone can help with an issue I'm having.
I have a simple study that shows a label on the chart with the quantity of shares I have, either long or short.
Randomly it just gets stuck, and I'm not sure if it's on the Ameritrade side or the TOS side.
For example, a couple of months ago I exited a short position on NIO, but the quantity still shows -3. I've tried everything but it won't reset.
However if I have active trader open, I see that the position is flat.
If I make another trade, let's say 50 shares long, I will see 47 on the chart, because it's subtracting the -3 shares that are stuck in the system.
Does anyone know how to reset the GetQuantity() total?
Thanks
There's really not much to the study, here it is below:
def PL = GetOpenPL();
def c = if IsNaN(close[-1]) then close else c[1];
def Entry = if IsNaN(GetAveragePrice()) then Entry[1] else GetAveragePrice();
def openCost = GetQuantity() * GetAveragePrice();
def PercentPL = GetOpenPL() / AbsValue(openCost) * 100;
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.FIRM);
Entry_.SetLineWeight(1);
Entry_.SetDefaultColor(Color.WHITE);
Entry_.HideBubble();
Entry_.HideTitle();
AddLabel(1, "Q" + GetQuantity() +
" A$" + Entry +
" A%" + PercentPL + "%" +
" T$" + openCost +
" P " + AsDollars(PL),
if PL == 0 then Color.CYAN
else if PL > 0 then Color.GREEN
else Color.RED);
# end code