MACD Format, Triggers, Scan, Label, Watchlist For ThinkOrSwim

i don't like changing the background color. can't see the bars, to see what is going on.
this has 3 options for drawing things when macd crosses zero
.. draw vertical line
.. change background color
.. draw a column of color between 2 bars


Code:
#macd_cross_zero

# do things when macd crosses zero
#  draw vertical line
#  change background color
#  draw a column of color between 2 bars


DefineGlobalColor("up", color.cyan);
DefineGlobalColor("dwn", color.yellow);
#NinetyPercent.SetDefaultColor(GlobalColor("up");

def na = double.nan;

def lvl = 0;
def v = macd().value;
def xup = v crosses above lvl;
def xdwn = v crosses below lvl;

def top = double.positive_INFINITY;
def bot = double.negative_INFINITY;

input change_back_color = yes;
AssignBackgroundColor(if !change_back_color then color.current else if xup then GlobalColor("up") else if xdwn then GlobalColor("dwn") else color.current);


# draw cloud between 2 bars , when a crossing
input cloud_columns = yes;
def cldtop = if !cloud_columns then na else if xup[-1] or xup then double.POSITIVE_INFINITY else na;
def cldbot = if !cloud_columns then na else if xdwn[-1] or xdwn then double.negative_INFINITY else na;
addcloud(cldtop, bot, GlobalColor("up"));
addcloud(top, cldbot, GlobalColor("dwn"));


input vert_lines = yes;
addverticalline(vert_lines and xup, "-", GlobalColor("up"));
addverticalline(vert_lines and xdwn, "-", GlobalColor("dwn"));
#
Perfect, but can you make it PARAMETER changeable ? also color changeable?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This is an adaptation I made on the MACD reflecting two separate MACD's:

Given that the typical MACD is normally by default calculating off the close, I decided to check out calculating by high and low instead.

Naturally the next step was seeing how it would work as an oscillator with the HIGH and LOW showing at the same time.

The initial view was messy as you may imagine. To mitigate this, I simply averaged the two MACD lines into a single, then put them together.

Enjoy!

Code:
declare lower;

input MACD_type = {default SLOW, "FAST"};
input averagetype = averageType.EXPONENTIAL;
input avglookback = 89;

def fastlength;
def slowlength;
def MACDlength;
 
switch (MACD_Type) {
case SLOW:
    fastlength = 33;
    slowlength = 100;
    MACDlength = 13;

case FAST:
    fastlength = 12;
    slowlength = 26;
    MACDlength = 9;
}

### HIGH MACD ###

def highdata = -high;
def HIGHValue = MovingAverage(averageType, HIGHdata, fastLength) - MovingAverage(averageType, HIGHdata, slowLength);
def HIGHAvg = MovingAverage(averageType, HIGHValue, MACDLength);
plot HIGHaverage = (HIGHvalue+highavg)/2;
highaverage.setdefaultcolor(createcolor(255,103,20));

### LOW MACD ###

def lowdata = low;
def LOWValue = MovingAverage(averageType, LOWdata, fastLength) - MovingAverage(averageType, LOWdata, slowLength);
def LOWAvg = MovingAverage(averageType, LOWValue, MACDLength);
plot LOWaverage = (LOWvalue+LOWavg)/2;
lowaverage.setdefaultcolor(createcolor(50,201,86));

plot zeroline = 0;
zeroline.setdefaultcolor(createcolor(212,212,212));
zeroline.setlineweight(2);
zeroline.hidetitle();

### BUY LEVELS GRID

def chartlow = lowest(lowaverage,avglookback);
def charthigh = highest(highaverage,avglookback);

plot stageonebuy = chartlow/3;
stageonebuy.setdefaultcolor(createcolor(50,201,86));
stageonebuy.hidetitle();
plot stagethreebuy = chartlow;
stagethreebuy.setdefaultcolor(createcolor(0,51,204));
stagethreebuy.hidetitle();
plot stagetwobuy = (stageonebuy+stagethreebuy)/2;
stagetwobuy.setdefaultcolor(createcolor(0,153,255));
stagetwobuy.hidetitle();
plot stage25 = (stagethreebuy + stagetwobuy)/2;
stage25.setdefaultcolor(color.yellow);
stage25.hidetitle();

### SELL LEVELS GRID

plot stageonesell = charthigh/3;
stageonesell.setdefaultcolor(createcolor(255,103,20));
stageonesell.hidetitle();
plot stagethreesell = charthigh;
stagethreesell.setdefaultcolor(createcolor(255,226,66));
stagethreesell.hidetitle();
plot stagetwosell = (stageonesell+stagethreesell)/2;
stagetwosell.setdefaultcolor(createcolor(255,153,0));
stagetwosell.hidetitle();
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
411 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top