Moving Avg Exp Ribbon Column


Category:
0
0

Hi Pete. I tried to create a watchlist column that appears green with a label of “Bull” if the Moving Average Exp Ribbon XMA1 > XMA2 > XMA3 > XMA4 > XMA5 > XMA6 > XMA7 > XMA8

Also, the column would appear red with a label of “BEAR” if the XMA1 < XMA2 < XMA3 < XMA4 < XMA5 < XMA6 < XMA7 < XMA8

The system is stating my code is too complex. Below I have provided a screen shot of the code I created and the error. Any help would be appreciated!

Attachments:
Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on October 9, 2023 8:55 am
123 views
0
Private answer

There is now way around this type of error because Thinkorswim has determined your script is too complex to compute a reliable value. The only alternative is to remove some of the complexity.

You can do this one of two ways. Reduce the number of conditions in each of your statements or split this into two separate columns.

For option one, I found that the error cleared up when I reduced the conditions to only include "XMA1" through "XMA6".

For option two, you can include all XMA's plots, but you can only include the bullish conditions in one column and the bearish conditions in another column.

For those interested in implementing option one, the following code will do that:

def bull = MovAvgExpRibbon()."XMA1" is greater than MovAvgExpRibbon()."XMA2" and MovAvgExpRibbon()."XMA2" is greater than MovAvgExpRibbon()."XMA3" and MovAvgExpRibbon()."XMA3" is greater than MovAvgExpRibbon()."XMA4" and MovAvgExpRibbon()."XMA4" is greater than MovAvgExpRibbon()."XMA5" and MovAvgExpRibbon()."XMA5" is greater than MovAvgExpRibbon()."XMA6";
def bear = MovAvgExpRibbon()."XMA1" is less than MovAvgExpRibbon()."XMA2" and MovAvgExpRibbon()."XMA2" is less than MovAvgExpRibbon()."XMA3" and MovAvgExpRibbon()."XMA3" is less than MovAvgExpRibbon()."XMA4" and MovAvgExpRibbon()."XMA4" is less than MovAvgExpRibbon()."XMA5" and MovAvgExpRibbon()."XMA5" is less than MovAvgExpRibbon()."XMA6";
AssignBackgroundColor (if bear then Color.RED else if bull then Color.GREEN else Color.BLACK);
Addlabel (yes, if bull then "BULL" else if Bear then "BEAR" else " " , Color.BLACK);

For those interested in implementing option 2:

Bullish column:

def bull = MovAvgExpRibbon()."XMA1" is greater than MovAvgExpRibbon()."XMA2" and MovAvgExpRibbon()."XMA2" is greater than MovAvgExpRibbon()."XMA3" and MovAvgExpRibbon()."XMA3" is greater than MovAvgExpRibbon()."XMA4" and MovAvgExpRibbon()."XMA4" is greater than MovAvgExpRibbon()."XMA5" and MovAvgExpRibbon()."XMA5" is greater than MovAvgExpRibbon()."XMA6" and MovAvgExpRibbon()."XMA6" is greater than MovAvgExpRibbon()."XMA7" and MovAvgExpRibbon()."XMA7" is greater than MovAvgExpRibbon()."XMA8";
AssignBackgroundColor (if bull then Color.GREEN else Color.BLACK);
Addlabel (yes, if bull then "BULL" else " " , Color.BLACK);

Bearish Column:

def bear = MovAvgExpRibbon()."XMA1" is less than MovAvgExpRibbon()."XMA2" and MovAvgExpRibbon()."XMA2" is less than MovAvgExpRibbon()."XMA3" and MovAvgExpRibbon()."XMA3" is less than MovAvgExpRibbon()."XMA4" and MovAvgExpRibbon()."XMA4" is less than MovAvgExpRibbon()."XMA5" and MovAvgExpRibbon()."XMA5" is less than MovAvgExpRibbon()."XMA6" and MovAvgExpRibbon()."XMA6" is less than MovAvgExpRibbon()."XMA7" and MovAvgExpRibbon()."XMA7" is less than MovAvgExpRibbon()."XMA8";
AssignBackgroundColor (if bear then Color.RED else Color.BLACK);
Addlabel (yes, if Bear then "BEAR" else " " , Color.BLACK);

Screenshot below shows each of these options applied to a watchlist gadget (listed in the order of the options described above).

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 9, 2023 9:56 am
0
Perfect. Thank you Pete!
( at October 9, 2023 10:42 am)