I intend to update position PNL information on the instrument being traded through IB Controller and display it on top left corner of the chart (in order to switch over to IB Gateway from TWS connection). I have written the following code :
//DISPLAY POSITION PNL INFO
ibc = GetTradingInterface("IB");
posn = Int(ibc.GetPositionSize(Name()));
ave_cost = ibc.GetPositionInfo(Name(),"Avg. Cost");
unrlzdPNL = ibc.GetPositionInfo(Name(),"Unrealized PNL");
rlzdPNL = ibc.GetPositionInfo(Name(),"Realized PNL");
netPNL = unrlzdPNL + rlzdPNL;
NetLiqValue = ibc.GetAccountValue("NetLiquidationByCurrency");
TotCashValue = ibc.GetAccountValue( "TotalCashBalance");
text1 = "\nPosition: " + posn + "\nCost: " + ave_cost + "\nUnRlzdPNL: "+ unrlzdPNL +
"\nRlzd PNL: " + rlzdPNL + "\nNet PNL: " + netPNL;
X4 = 10;
Y4 = 10;
X5 = 200;
Y5 = 200;
GfxSelectFont("Verdana", 6, 300);
GfxSetTextColor(colorBrightGreen);
GfxDrawText(text1, X4, Y4, X4+X5, Y4+Y5, 0);
The above code works . It instantly displays the information the moment whenever an order is placed, executed or rejected etc . But the changes in "UnRealized PNL" , "Realized PNL" and "Net PNL" are not updated continuously as per change in the last traded price, even though the interval in RequestTimedRefresh(Interval) is set to 1 or 0 sec.
The Last traded price on candle chart is updated without any problem and above mentioned PNL information in IB TWS is also changing as per last traded price.
Please go through and help.