Color candles based on slope of McClellanSummationIndex


Category:
0
0

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.

and

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
128 views
0
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;
ob.SetDefaultColor(GetColor(5));
plot os = McClellanSummationIndex(exchange, fastLength, slowLength, ratioAdjusted, isCumulative).OverSold;
os.SetDefaultColor(GetColor(5));
plot neutral = McClellanSummationIndex(exchange, fastLength, slowLength, ratioAdjusted, isCumulative).NeutralLevel;
neutral.SetDefaultColor(GetColor(7));
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.

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