TradeTracker
TradeTracker copied to clipboard
Incorrect "ITM" color if market price fully breaches a vertical spread
The corrected code for the PerformITMcalculation function located in ActiveTrades.cpp should be as follows. This code will eventually find its way into a future update/release.
void PerformITMcalculation(AppState& state, std::shared_ptr<Trade>& trade) {
// Puts have aready been sorted before calls by strike price
const ImU32 RED = clrRed(state);
const ImU32 GREEN = clrGreen(state);
int ITMCOLOR = 0;
double strike_price = 0;
// Iterate forward over the open legs to process the Puts but iterate in
// reverse to process the Calls in order to properly ensure that the ITM
// color is not reset if strike price is fully through a vertical spread.
for (const auto& leg : trade->open_legs) {
if (leg->underlying != Underlying::Options) continue;
if (leg->put_call != PutCall::Put) continue;
strike_price = AfxValDouble(leg->strike_price);
if (trade->ticker_last_price < strike_price) {
if (leg->open_quantity < 0) ITMCOLOR = RED; // credit
if (leg->open_quantity > 0) ITMCOLOR = GREEN; // debit
}
}
// Process the Calls in reverse
for (int i = trade->open_legs.size() - 1; i >= 0; --i) {
auto leg = trade->open_legs[i];
if (leg->underlying != Underlying::Options) continue;
if (leg->put_call != PutCall::Call) continue;
strike_price = AfxValDouble(leg->strike_price);
if (trade->ticker_last_price > strike_price) {
if (leg->open_quantity < 0) ITMCOLOR = RED; // credit
if (leg->open_quantity > 0) ITMCOLOR = GREEN; // debit
}
}
trade->itm_text = (ITMCOLOR ? "ITM" : "");
trade->itm_color = (ITMCOLOR ? ITMCOLOR : clrTextLightWhite(state));
}