Date of MACD Cross on Daily Chart

british43

Member
Hello, How would I go about adding a date chartbubble at each instance where there is a MACD cross? I have been knocking my head all day trying to figure it out. Thanks.
 
Solution
Duplicate the MACDHistogramCrossover study and add this at the bottom. Where it has ATR*1.1 you can change that to adjust the vertical position. Such as 1.05 to get closer to the candles or 1.2 to get farther away.

Ruby:
AddChartBubble(
  signal,
  high + reference ATR * 1.1,
  GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + AsPrice(GetYear()),
  Color.LIGHT_GRAY
);

Slippage

Well-known member
Duplicate the MACDHistogramCrossover study and add this at the bottom. Where it has ATR*1.1 you can change that to adjust the vertical position. Such as 1.05 to get closer to the candles or 1.2 to get farther away.

Ruby:
AddChartBubble(
  signal,
  high + reference ATR * 1.1,
  GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + AsPrice(GetYear()),
  Color.LIGHT_GRAY
);
 
Solution

Wizedon

New member
VIP
Duplicate the MACDHistogramCrossover study and add this at the bottom. Where it has ATR*1.1 you can change that to adjust the vertical position. Such as 1.05 to get closer to the candles or 1.2 to get farther away.

Ruby:
AddChartBubble(
  signal,
  high + reference ATR * 1.1,
  GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + AsPrice(GetYear()),
  Color.LIGHT_GRAY
);
Can I get the full script for the MACD Crossover Please? Thanks
 

british43

Member
Thank you so much. Also, does thinkorswim has a limitation when trying to display dates in a watchlist? For example want to display the date of the MACD crossover in a watchlist column?
 

Slippage

Well-known member
Thank you so much. Also, does thinkorswim has a limitation when trying to display dates in a watchlist? For example want to display the date of the MACD crossover in a watchlist column?

This will include both crossing above and crossing below. If you want just one or the other, change the line:
def signal = Diff crosses 0;
to
def signal = Diff crosses above 0;
or
def signal = Diff crosses below 0;

Also, if want it to be sortable you should rearrange the date formatting to be YYYY-MM-DD. TOS will sort the column as text, for instance
01/01/2020
01/01/2021
02/04/2020
etc.

Ruby:
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;

def signal = Diff crosses 0;

def month = if signal then GetMonth() else month[1];
def dayOfMonth = if signal then GetDayOfMonth(GetYYYYMMDD()) else dayofMonth[1];
def year = if signal then GetYear() else year[1];

AddLabel(
  !IsNaN(month),
  month + "/" + dayOfMonth + "/" + AsPrice(year),
  Color.LIGHT_GRAY
);
 

Wizedon

New member
VIP
This will include both crossing above and crossing below. If you want just one or the other, change the line:
def signal = Diff crosses 0;
to
def signal = Diff crosses above 0;
or
def signal = Diff crosses below 0;

Also, if want it to be sortable you should rearrange the date formatting to be YYYY-MM-DD. TOS will sort the column as text, for instance
01/01/2020
01/01/2021
02/04/2020
etc.

Ruby:
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;

def signal = Diff crosses 0;

def month = if signal then GetMonth() else month[1];
def dayOfMonth = if signal then GetDayOfMonth(GetYYYYMMDD()) else dayofMonth[1];
def year = if signal then GetYear() else year[1];

AddLabel(
  !IsNaN(month),
  month + "/" + dayOfMonth + "/" + AsPrice(year),
  Color.LIGHT_GRAY
);
Thanks very much really appreciate you!
 

Shmo

New member
Duplicate the MACDHistogramCrossover study and add this at the bottom. Where it has ATR*1.1 you can change that to adjust the vertical position. Such as 1.05 to get closer to the candles or 1.2 to get farther away.

Ruby:
AddChartBubble(
  signal,
  high + reference ATR * 1.1,
  GetMonth() + "/" + GetDayOfMonth(GetYYYYMMDD()) + "/" + AsPrice(GetYear()),
  Color.LIGHT_GRAY
);
Slippage, I too am a Moxie Mastery member and a multi year Simpler Trading trade room member. I very much appreciate your coding and philosophy of streamlining the code to reduce computer resources. I am not skilled in Thinkscript. I would very much like to correspond with you concerning fine tuning some scan code for the Moxie (e.g. 50/200/50 and others) and some custom components to add to a multi compression squeeze radar screen (RAF Buy/Sell/Continuation on MTFs) that I use for day and swing trading.

If it is OK with you maybe we could exchange email addresses to correspond further through the useThinkScrip Admin or through Simpler Admin if you prefer. I am Gator in the Moxie and Day trading rooms.

Thanks for reading.

Uploaded image: "image.png"
 

Similar threads

Top