In thinkscript the entry price(s) is averaged with every new position in the same direction though in the strategy report it is itemized per transaction.
In the attached image the bubbles display on entry price change (including consecutive long or short) with the delta value of the fpl value from the prior value which is captured on every entry price change.
When the strategy is configured for more than 1 contract the calculated value of the fpl is only for a single contract as a 1/n of the total pnl but on the strategy report it is itemized and summed for all the contracts when the position closes.
Could someone help figure this out?
The example below is using a built- in strategy from thinkorswim but any strategy with consecutive entries will display the same issue.
Code for the bubbles display (must be saved as a strategy)
In the attached image the bubbles display on entry price change (including consecutive long or short) with the delta value of the fpl value from the prior value which is captured on every entry price change.
When the strategy is configured for more than 1 contract the calculated value of the fpl is only for a single contract as a 1/n of the total pnl but on the strategy report it is itemized and summed for all the contracts when the position closes.
Could someone help figure this out?
The example below is using a built- in strategy from thinkorswim but any strategy with consecutive entries will display the same issue.
Code for the bubbles display (must be saved as a strategy)
Code:
##Begin
##
addOrder(OrderType.BUY_AUTO, no); #dont change this line
input enableDashBoard = yes;
input ShowStrategyCurrentPnlBubble = yes;
input ShowStrategyPnlBubble = no;
input ShowStrategyPnlEntryBubble = yes;
input ShowStrategyPnlVertical = no;
def fpl = FPL();
def StrategyEntryprice = if IsNaN(EntryPrice()) then 0 else EntryPrice();
def ep = entryprice();
def poschange = ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice == 0 ) or ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] == 0 ) or ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] > 0 and StrategyEntryprice[0] > 0 );
def pnlentry = if poschange then fpl[1] else pnlentry[1];
def currentprofit = fpl - pnlentry[1];
def pnlprofit = if pnlentry <> pnlentry[1] then fpl[0] - pnlentry[0] else 0 ;
def entryprofit = (if pnlprofit> 0 then 1 else -1 ) * absValue( if poschange then if StrategyEntryprice == 0 then open[0] - ep[1] else ep-ep[1] else 0) ;
def dollarentryprofitloss = Round(((entryprofit ) / TickSize()) * TickValue());
AddChartBubble(enableDashBoard and ShowStrategyPnlEntryBubble and poschange and absValue(dollarentryprofitloss )>0, open[0], AsDollars(dollarentryprofitloss[0]), if dollarentryprofitloss[0] > 0 then Color.light_GREEN else if dollarentryprofitloss[0] < 0 then Color.pink else Color.BLUE);
AddVerticalLine(ShowStrategyPnlVertical and ShowStrategyPnlEntryBubble and poschange, AsDollars(fpl) + " (" + dollarentryprofitloss + ")" , if dollarentryprofitloss > 0 then Color.GREEN else if dollarentryprofitloss < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def fplpnlprofit = pnlprofit;
AddChartBubble(enableDashBoard and ShowStrategyPnlBubble and poschange[0] and absValue(fplpnlprofit )>0, open[0], AsDollars(fplpnlprofit[0]), if fplpnlprofit[0] > 0 then Color.GREEN else if fplpnlprofit[0] < 0 then Color.RED else Color.BLUE);
AddVerticalLine(enableDashBoard and ShowStrategyPnlVertical and ShowStrategyPnlBubble and poschange, AsDollars(fpl) + " (" + pnlprofit + ")" , if pnlprofit > 0 then Color.GREEN else if pnlprofit < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def lastentry =if isnan( entryprice()) then lastentry[1] else entryprice() ;
AddChartBubble(enableDashBoard and ShowStrategyCurrentPnlBubble and !IsNaN(close) and IsNaN(close [-1] ) and HighestAll(BarNumber()) and absValue(currentprofit)> 0, lastentry, AsDollars(currentprofit[0]), if currentprofit[0] > 0 then Color.green else if currentprofit[0] < 0 then Color.red else Color.BLUE);
##
##End