Color candles based on slope of McClellanSummationIndex


Hi Pete,

I am looking to augment the current ThinkOrSwim Study “McClellanSummationIndex” (aka NYSI) to assign a color to both the indicator and the candle based upon the current values relationship to the previous days value.

Something like this:

If, indicator value ≥ previous day value, then paint indicator and candle green.


If, indicator value ≤ previous day value, then paint indicator and candle red.


Thanks in advance!

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on January 28, 2023 11:54 am
Private answer

I updated the title of your question to include the full name of the study you are referencing. The "aka NYSI" was also a typo, because one of the three options is NYSE and not "NYSI". But "NYSI" is not a very helpful nickname for this indicator because it can be set to "NYSE", "NASDAQ" or "AMEX". The more appropriate nickname that I can think of would be to convert its name to initials, such as "MSI".

Here is the code which replicates the McClellanSummationIndex and add the new features you requested. (only two lines of code were required to add those two features).

declare lower;
input exchange = {default NYSE, NASDAQ, AMEX};
input fastLength = 19;
input slowLength = 39;
input ratioAdjusted = No;
input isCumulative = Yes;
plot msi = McClellanSummationIndex(exchange, fastLength, slowLength, ratioAdjusted, isCumulative).SummationIndex;
msi.AssignValueColor(if msi > msi[1] then Color.DARK_GREEN else Color.DARK_RED);
plot ob = McClellanSummationIndex(exchange, fastLength, slowLength, ratioAdjusted, isCumulative).OverBought;
plot os = McClellanSummationIndex(exchange, fastLength, slowLength, ratioAdjusted, isCumulative).OverSold;
plot neutral = McClellanSummationIndex(exchange, fastLength, slowLength, ratioAdjusted, isCumulative).NeutralLevel;
AssignPriceColor(if msi > msi[1] then Color.DARK_GREEN else Color.DARK_RED);

I have included a screenshot below which shows the original McClellanSummationIndex above the custom version. You can see the candles as well as the MSI have been colored according to the conditions you requested.

Marked as spam
Posted by (Questions: 37, Answers: 3976)
Answered on January 28, 2023 1:44 pm