Portfolio thinkscript studies - N/A if trade opened and close in same bar

Sly

New member
Hi all, just wondering if there is a way around variables/plots using portfolio functions - getaverageprice() getopenpl() etc. - reading N/A if a trade was opened and closed in the same bar at a given agg period?

A part of what I'm trying to do is capture the QTY as if a trade was not closed to see theoretical P/L if the trade was left open. At its simplest:
Code:
def qty = getquantity();
plot qtyPlot = qty;
plot lastQTY = if qty != 0 then qty else lastQTY[1];
This works so long as a trade was not opened and closed in the same bar. If you are looking at a day trade on the daily bar, for example. Otherwise both plots will show N/A as the QTY at close of the bar was 0.

Is there any work around or trick to just capture just buys, or to access the more detailed trade data displayed in the buy/sell bubbles that contain the trade price, qty, time etc. that are on the bars, that anyone knows?
 

Similar threads

Top