Moving Average Crossover Watchlist Column for ThinkorSwim

Madhu

Member
VIP
Yes Ben, I am looking for ema8 > ema21 and ema21 > ema50...
Hi Ben, i need to show if they moving avg are showing in a order - 8 , 8 below 21 ,21 below 50. If these three conditions are met show in a watch list with some me color indication. Could you please help me on this?
 

rad14733

Well-known member
VIP
Hi Ben, i need to show if they moving avg are showing in a order - 8 , 8 below 21 ,21 below 50. If these three conditions are met show in a watch list with some me color indication. Could you please help me on this?

So now you're looking for ema8 > ema21 and ema21 < ema50...??? Or do you mean close < ema8 and ema8 < ema21 and ema21 < ema50...??? Or are you not providing enough information for us to adequately help you...??? Or are you expecting us to provide the entire script for you rather than the logic you should be able to work with...???
 

Madhu

Member
VIP
So now you're looking for ema8 > ema21 and ema21 < ema50...??? Or do you mean close < ema8 and ema8 < ema21 and ema21 < ema50...??? Or are you not providing enough information for us to adequately help you...??? Or are you expecting us to provide the entire script for you rather than the logic you should be able to work with...???
HI Rad,

AjXGBA3.png


I this image on 6/1--- 8 EMA(dark Blue) is above the 21 EMA(light yellow) and 21 EMA is above the 50 EMA(light Blue).

I am looking this type of set up. If it is there I need see this in watchlist.

thank you for helping.
 

rad14733

Well-known member
VIP
@Madhu I was fairly certain I knew what you wanted when I initially replied... Are you unable to code in Thinkscript because you should be able to glean enough information in this very topic to achieve what you are looking for... I gave you the logic for the code but you know the logic already so it's a matter of adapting what is here... Or are you looking to have the code handed to you...??? I already asked you in the my previous post... Have you tried to code for yourself...???
 

JamesF

New member
Sorry, the code I am using and having trouble with is as follows:

def EMA50 = ExpAverage(close,50);
def EMA100 = ExpAverage(close,100);

def bullish = EMA50 > EMA100[1];
def count = if EMA50 > EMA100[1] then 1 else count [1]+1;
def bearish = EMA50 < EMA100 [1];
def count_2 = if EMA50 < EMA100 [1] then 1 else count [1]+1;

AddLabel(bullish, "" + count, color.black);
AddLabel(bearish, “” + count_2, color.black);

AssignBackgroundColor(if bullish then color.green else if bearish then color.red else color.black);
 

JamesF

New member
Thank you for your reply.

I gave your suggestion a try but for some reason, it is still not returning the correct number of periods from the most recent 50 ema / 100 ema cross.

Appreciate your help. I will keep working at it.

Keep well!
 

Pensar

Well-known member
VIP
@JamesF Perhaps this?

Code:
def EMA50 = ExpAverage(close,50);
def EMA100 = ExpAverage(close,100);

def bullish = EMA50 > EMA100;
def count = if bullish and !bullish[1] then 1 else count[1] + 1;
def bearish = EMA50 < EMA100;
def count_2 = if bearish and !bearish[1] then 1 else count[1] + 1;

AddLabel(bullish, "" + count, color.black);
AddLabel(bearish, “” + count_2, color.black);

AssignBackgroundColor(if bullish then color.green else if bearish then color.red else color.black);
 

JamesF

New member
Thank you Pensar for your reply.

I appreciate you giving this a shot. I am still receiving a "funky" count that fails to match with the number of periods of the most recent ema cross.

I will keep at it.

Have a great day!
 

Pensar

Well-known member
VIP
Thank you Pensar for your reply.

I appreciate you giving this a shot. I am still receiving a "funky" count that fails to match with the number of periods of the most recent ema cross.

I will keep at it.

Have a great day!
@JamesF Make sure that your aggregation of the column matches the aggregation of the chart. It worked fine for me.
 

JamesF

New member
Thanks again.

Yes, the aggregation does match however; still getting the same issue.

Example: Using a 1Y 1D chart, HTBX 50 ema most recently crossed below the 100 ema April 12th however, the code is returning a period of 66 days with the aggregation of the column set to D.

I'll keep going.

Really appreciate you taking the time.

Great community here.
 

Pensar

Well-known member
VIP
@JamesF There's a error in the line of code for "count_2" - change the "count[1]" to "count_2[1]". It is referencing the bullish count instead of bearish. I hadn't checked the short side.
 

JamesF

New member
That is it!

Terrific. Thank you very much for your help here. Greatly appreciated.

Always good to learn something new.

Keep well!
 

rickbw

New member
VIP
How would I write thinkscript if I wanted to have several columns with different timeframes (i.e. 1 minute, 5 minutes, 10 minutes etc) that would compare a 9 EMA versus current price for each timeframe?

All I would want is a color if above the 9EMA and a different color if below?

Thanks,
 

rad14733

Well-known member
VIP
@rickbw The simplest solution would be to use the following code for each Custom Watchlist Column and set the proper timeframe for each column...

Ruby:
AddLabel(yes, "", if close >= ExpAverage(close, 9) then Color.GREEN else Color.RED);
 

Similar threads

Top