PureBytes Links
Trading Reference Links
|
Bob Fulks pointed out that the indicator only worked properly for
single contracts. Ooops!
The attached code should handle any position size. However, be aware
that it assumes you keep the SAME position size throughout the trade.
If you add or subtract contracts during the trade, the indicator
can't handle that.
Thanks, Bob!
Gary
{ Indicator: Trade Marker
Displays lines from trade-open to trade-close.
Move the indicator to the "Hidden" subgraph to save screen space.
Note: since TS doesn't provide much position information to
indicators, I had to calculate the exit price using
I_CurrentEquity. The increase in equity includes any costs
you've factored into your system, so the exit price will be off
by the "cost" amount. In most cases this will be a very small
offset. Also, since I had to use I_AvgEntryPrice for the entry
price, it will show the average entry price if you have multiple
entries.
}
inputs: Win(Tool_Green), Loss(Tool_Red);
vars: MP(0), EPrice(0), EDate(0), ETime(0), ICE(0), ICC(0);
vars: PosProfit(0), ExPrice(0), Line(0);
MP = I_MarketPosition;
ICC = I_CurrentContracts;
ICE = I_ClosedEquity;
if MP <> MP[1] then begin { Position has changed }
if MP[1] <> 0 then begin { Just exited a position }
PosProfit = (ICE-ICE[1])/BigPointValue;
if MP[1] = 1 then ExPrice = EPrice + PosProfit / ICC[1]
else ExPrice = EPrice - PosProfit / ICC[1];
Line = TL_New(Edate, Etime, Eprice, Date, Time, ExPrice);
TL_SetSize(Line, 1);
if PosProfit > 0 then TL_SetColor(Line, Win)
else TL_SetColor(Line, Loss);
end;
if MP <> 0 then begin { Just entered a position }
EPrice = I_AvgEntryPrice;
Edate = Date;
Etime = Time;
end;
end;
if false then plot1(0,"");
|