Reversal and PullBack Scan


Category:
0
0

Hahn,

First of all thank you so much for your help for this community. I need your help creaing a scan with alert using below script. It is working 100% fine on study chart, but not working for Scan. I am getting “Exactly one plot expected” error.  Sorry, I am not that tech, so I have not much idea abt this script and issue.

Here is the script, which you have to look.

def h = high;

def l = low;

def c = close;

def x = barNumber();

def nan = double.nan;

def rth = getTime() >= RegularTradingStart(getYYYYMMDD()) and

getTime() <= RegularTradingEnd(getYYYYMMDD());

def LOD = if rth and !rth[1]

then l

else if rth and l < LOD[1]

then l

else LOD[1];

def LOD_x = if l == LOD and rth

then x

else nan;

def LOD_h = if l == LOD

then h

else LOD_h[1];

plot LOD_h_line = if x >= highestAll(LOD_x)

then highestAll(if isNaN(c[-1])

then LOD_h

else nan)

else nan;

LOD_h_line.SetDefaultColor(createColor(25,180,25));

LOD_h_line.hideBubble();

LOD_h_line.hideTitle();

def upBar = if c crosses above LOD_H_line and RTH

then x

else upBar[1];

plot ArrowUP = if x == highestAll(upBar)

then l – (2*TickSize())

else nan;

ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);

ArrowUP.SetLineWeight(3);

ArrowUP.SetDefaultColor(createColor(25,180,25));

ArrowUP.HideBubble();

ArrowUP.HideTitle();

def HOD = if rth and !rth[1]

then h

else if rth and h > HOD[1]

then h

else HOD[1];

def HOD_x = if h == HOD and rth

then x

else nan;

def HOD_l = if h == HOD

then l

else HOD_l[1];

plot HOD_l_line = if x >= highestAll(HOD_x)

then highestAll(if isNaN(c[-1])

then HOD_l

else nan)

else nan;

HOD_l_line.SetDefaultColor(createColor(75, 55, 175));

HOD_l_line.HideTitle();

HOD_l_line.HideBubble();

def dnBar = if c crosses below HOD_l_line

then x

else dnBar[1];

plot ArrowDN = if x == highestAll(dnBar)

then h + (2*TickSize())

else nan;

ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);

ArrowDN.SetLineWeight(3);

ArrowDN.SetDefaultColor(createColor(75,55,175));

ArrowDN.HideBubble();

ArrowDN.HideTitle();
Alert(if x == highestAll(upBar) then l – (2*TickSize())else nan, “UP Arrow”, Alert.BAR, Sound.RING);

RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on November 14, 2019 9:12 pm
546 views
0
Thank you so much Hahn for your help and quick response. I got what I wanted using above suggestion.
( at November 16, 2019 3:51 am)
0
Private answer

This code is hideous to look at so I will not be making any modifications to give my solutions. Instead I will explain the steps required to get it working as a scan. Sorry, this code is painful to read. Be sure to read through this entire set of instructions before you begin.

Convert Plot Statements To Def:

There are four plot statements in the code. Find each of them and change the word "plot" to "def". For example, here is the first one:

plot LOD_h_line

Change this to:

def LOD_h_line

AND LEAVE EVERYTHING ELSE IN PLACE

After each plot statement you will find a series of style statements. You will identify them as lines that begin with the name of the plot you just changed to def, immediately followed by a decimal point. So again taking the first one as an example we find the following style statements:

LOD_h_line.SetDefaultColor(createColor(25,180,25));
LOD_h_line.hideBubble();
LOD_h_line.hideTitle();

Delete these entirely.

Repeat this process for the rest of the plot statements you find in the code. As you proceed, these are the rest of the plot statements you will find:

plot ArrowUP (followed by 5 lines of associated style statements)

plot HOD_l_line (followed by 3 lines of associated style statements)

plot ArrowDN (followed by 5 lines of associated style statements)

Remove the Alert Statement:

The very last line is a statement that generates the alerts. This line is not used by the scan so it should be removed. However it happens to contain the signal we'll use for the scan. So here is the alert statement you will remove from the code:

Alert(if x == highestAll(upBar) then l – (2*TickSize())else nan, “UP Arrow”, Alert.BAR, Sound.RING);

Adding the Scan Signal:

The first parameter of the Alert() function contains the true/false condition used to trigger the alert. You can all the details here:

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Alert.html

In the case of your code it takes the form of an if/then/else statement. Which is entirely inappropriate for this use. This code is really bad. As I said, painful to read.

So here is the line of code you will add to the bottom of the scan to generate the signal:

plot scan = x == highestAll(upBar);

Complete:

That's it. Nothing more to do. But I will say the scan results from this code can never perfectly match what you see on the chart. This code repeatedly uses a function called "HighestAll()". Which means the levels and plots formed by this code will change based on how much historical data is loaded on the chart. And there is no way to adjust the amount of historical data on a chart to match the amount of historical data used by the scan engine. This code is VERY poorly written.

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 15, 2019 8:27 am