Trying To Create Thinkscript Code That Gives Alerts - Have Most of All Code Just Need a Little Help

KevinB-TraderGuy

New member
VIP
Hi,

I have been a long-time viewer of usethinkscript and really appreciate everyone who has helped us Thinkorswim users on here. I am wondering if you guys could help me with an issue I am having. I currently have 4 different codes that I use in my Watchlist columns - A 5-Min MACD Indicator, 3-Min MACD Indicator, an Elliott Oscillator Indicator and a DMI Oscillator Indicator. When all 4 of these light up at around the same (Provided there is proper support etc) this is usually indictive of a big move I have found. The problem I am having is combining all 4 together so I can get alerts when everything lights up. I am not sure how to combine a 3_Min and 5_Min indicator when I have to select the timeframe in the actual window and I am also not sure how to set alerts when they all turn red or green. If I could be alerted when stocks on my watchlist turn all one color I would be able to react at the proper time and would not miss moves like I do now. Anybody know of anyway this can be done? The code is below - (The 3 and 5 Min MACD indicators use the same code) -

Code:
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
plot UpSignal = if Diff crosses above 0 then 0 else Double.NaN;
plot DownSignal = if Diff crosses below 0 then 0 else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


Diff.assignValueColor(
         if Diff > 0 then color.dark_green
    else if Diff < 0 then color.dark_red
    else color.black);

assignBackgroundColor(
          if Diff > 0 then color.dark_green
    else if Diff < 0 then color.dark_red
    else color.black);

Code:
declare lower;

input length = 10;
input paintBars = yes;
input averageType = AverageType.WILDERS;

def diPlus = DMI(length, averageType)."DI+";
def diMinus = DMI(length, averageType)."DI-";

plot Osc = diPlus - diMinus;
plot Hist = Osc;
plot ZeroLine = 0;

Osc.SetDefaultColor(GetColor(1));
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(3);
Hist.DefineColor("Positive", Color.UPTICK);
Hist.DefineColor("Negative", Color.DOWNTICK);
Hist.AssignValueColor(if Hist > 0 then Hist.Color("Positive") else Hist.Color("Negative"));
Hist.HideTitle();
ZeroLine.SetDefaultColor(Color.GRAY);

DefineGlobalColor("Positive", Color.UPTICK);
DefineGlobalColor("Negative", Color.DOWNTICK);
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if Osc > 0
        then GlobalColor("Positive")
        else GlobalColor("Negative"));

Osc.assignValueColor(
         if Osc > 0 then color.dark_green
    else if Osc < 0 then color.dark_red
    else color.black);

assignBackgroundColor(
          if Osc > 0 then color.dark_green
    else if Osc < 0 then color.dark_red
    else color.black);

Code:
declare lower;

input shortLength = 5;
input longLength = 35;

def price = (high + low) / 2;
plot ElliotOsc = Average(price, shortLength) - Average(price, longLength);
plot ZeroLine = 0;

ElliotOsc.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
ElliotOsc.SetLineWeight(3);
ElliotOsc.DefineColor("Positive", Color.UPTICK);
ElliotOsc.DefineColor("Negative", Color.DOWNTICK);
ElliotOsc.AssignValueColor(if ElliotOsc > 0 then ElliotOsc.color("Positive") else ElliotOsc.color("Negative"));
ZeroLine.setDefaultColor(getColor(8));

ElliotOsc.assignValueColor(
         if ElliotOsc > 0 then color.dark_green
    else if ElliotOsc < 0 then color.dark_red
    else color.black);

assignBackgroundColor(
          if ElliotOsc > 0 then color.dark_green
    else if ElliotOsc < 0 then color.dark_red
    else color.black);
 

KevinB-TraderGuy

New member
VIP
Oh and I forgot to add... I understand this may require a little work so anyone willing to help out I will send some money to via PayPal. Thank you!
 

MerryDay

Well-known member
VIP
@KevinB-TraderGuy
This is one method:

Save the code for each indicator as individual studies. Open the scanner and scan for each indicator, as seen in the below example.

The names:
  • A00_MACD
  • A00_Eliiot
  • A00_DMI
must be changed to the study names that you are using.

 
Last edited:

Similar threads

Top