Building a Chart Scan using Condition Wizzard on TOS


0
0

Hi Pete,

I am using this code on a chart and would like to build a Market Watch / Chart Scan / using the Condition Wizzard to be notified when certain criteria is met.  Can you guide me as to how to do so?

input fastLength = 50;
input slowLength = 200;
input tf = AggregationPeriod.FIFTEEN_MIN;
input offset = 0.5;

def HMAF = MovingAverage(AverageType.HULL, close(period = tf), fastLength);
def HMAS = MovingAverage(AverageType.HULL, close(period = tf), slowLength);

def rise = (HMAF > HMAF[1]) and (HMAS > HMAS[1]);
def fall = (HMAF < HMAF[1]) and (HMAS < HMAS[1]);

#def upsig = !isnan(close) and rise and !rise[1];
#def dnsig = !isnan(close) and fall and !fall[1];

def upsig = rise and !rise[1];
def dnsig = fall and !fall[1];

plot UpSignal = if upsig then low – offset * Average(TrueRange(high, close, low), 14) else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetDefaultColor(Color.GREEN);
UpSignal.SetLineWeight(3);
UpSignal.HideBubble();
plot DownSignal = if dnsig then high + offset * Average(TrueRange(high, close, low), 14) else Double.NaN;
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetDefaultColor(Color.RED);
DownSignal.SetLineWeight(3);
DownSignal.HideBubble();

Alert(upsig, “HMA rise signal”, Alert.BAR, Sound.Ring);
Alert(dnsig, “HMA fall signal”, Alert.BAR, Sound.Bell);

Marked as spam
Posted by (Questions: 1, Answers: 9)
Asked on March 20, 2018 10:12 am
292 views
0
Private answer

Sadly, although I originally thought it was possible, when I went to build this using the condition wizard I found it was not possible. So I’ll provide a modified version of your code that you can use in a Study Alert or the Study Filter of a custom scan.

Definition of Terms

To make things clear for all our viewers, I will take a few paragraphs to clear up some of terms you used. The phrase “Market Watch / Chart Scan”, has no meaning in the Thinkorswim platform. There is a tab on Thinkorswim called “MarketWatch”. Within that tab are various screens. One of which is named “Alerts”. In the upper right corner of that screen is a button named “Study Alert”. This is one location in which my solution can be applied. In summary, we have the following terms to help folks navigate the platform. 1. MarketWatch 2. Alerts 3. Study Alert.

There is another place my solution can be applied. That is within a Study Filter of a custom scan. There is a separate tab on Thinkorswim for scans. It is named “Scan”. Within that tab are various screens. The one my solution can be applied to is named “Stock Hacker”.

So from your original question we find the phrase “Chart Scan” does not exist anywhere on the platform. I felt it important to explain that to prevent other visitors to this post from getting confused.

The Code

Ok so this is the easy part. Your code already does the work. We just need to make some adjustments to adapt it to the Study Alert and/or Study Filter.

input fastLength = 50;
input slowLength = 200;
input tf = AggregationPeriod.FIFTEEN_MIN;
input offset = 0.5;
def HMAF = MovingAverage(AverageType.HULL, close(period = tf), fastLength);
def HMAS = MovingAverage(AverageType.HULL, close(period = tf), slowLength);
def rise = (HMAF > HMAF[1]) and (HMAS > HMAS[1]);
def fall = (HMAF < HMAF[1]) and (HMAS < HMAS[1]);
plot upsig = rise and !rise[1];
#plot dnsig = fall and !fall[1];

So what did I change? I removed all the plot and style statements at the end of the code. I also removed the Alert statement. Everything else is exactly the same. Well except for the last two lines. In the original, those were def statements and I changed them to plot statements. Since only one plot can be used at a time, I used a ‘#’ mark to turn the last line into a comment. To search for the other signal just move the ‘#’ mark.

Here is something that really surprised me. This code references a secondary time frame, 15 min. Previously, this was not permitted in Study Alerts. This means Thinkorswim has finally enabled secondary time frames for Study Alerts. Wonder if they also did so for Conditional Orders?

Screenshot below shows this code applied to a Study Alert set to 5 min time frame. Proving that we can indeed use secondary time frames on Study Alerts. Awesome!

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on March 20, 2018 11:58 am
0

Thank you Pete. This is what I was trying to do. Awesome.

( at March 20, 2018 12:28 pm)