♥ 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(); RESOLVED
Marked as spam
|
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:
Change this to:
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:
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:
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:
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:
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
|
Please log in to post questions.