|
Diamondjag
 Legend
    Posts: 404
Joined: 3/12/2006
Location: Brighton, Colorado
User Profile |
I'm looking for an OmniLanguage function that would look for a 250 day low then trigger a sell order if the RSI(5) goes above 85 in the next 4 days. I got a start but don't know how to incorporate the RSI within the next four days.
Any help would be appreciated. Thanks.
IF L=LLV(250) and RSI(5) >= 85 Then
Signal = ShortSignal
End If
|
|
Jim Dean
 Sage
       Posts: 3433
Joined: 3/13/2006
Location: L'ville, GA
User Profile |
Hi, Dave
The trick is to check the 250-day-low condition for five days PRIOR, and the four bars SINCE then. OT/OL don't allow looking into the future. ;~)
IF L[5]=LLV(250)[5] and HHV(RSI(5),4) >= 85 Then Signal = ShortSignal
However, that simple approach will create a ***delayed*** entry signal if the RSI rule is met on days 1-3 after the low rule is met.
The correct way to do it is to ask if the RSI rule is met TODAY, and if so, check back for the Low rule being satisfied in the "acceptable" window:
dim gI as integer
If RSI(5) >= 85 then
for gI = 1 to 4
if L[gI]=LLV(250)[gI] then
Signal = ShortSignal
exit for
end if
next gI
This will give you the earliest possible entry signal that meets your rules. The forum doesn't permit indentation but hopefully you can follow it OK.
Note that LLV is an "inefficient" function, so this code tries to minimize its use ... an efficient workaround to LLV for this application requires a lot more code. I doubt that you'd notice the difference, unless your rule allowed for the prior lowest-low to occur a long time before the RSI rule.
[Edited by Jim Dean on 10/3/2019 1:06 PM]
|
|
Diamondjag
 Legend
    Posts: 404
Joined: 3/12/2006
Location: Brighton, Colorado
User Profile |
Jim,
Always happy when I see you respond to an Omni Language question.
I copied what you sent. Probably did something wrong at the end. Got a message that said that line 15 needed a closing "end if". What am I missing here?
Thanks

[Edited by Diamondjag on 10/3/2019 2:06 PM]
Attached file : Low Pullback.JPG (16KB - 494 downloads)
|
|
Jim Dean
 Sage
       Posts: 3433
Joined: 3/13/2006
Location: L'ville, GA
User Profile |
Here is the corrected code with final end if, in pretty indentation form that makes the whole thing more understandable:

[Edited by Jim Dean on 10/3/2019 2:12 PM]
Attached file : code snippet with indentation.png (5KB - 523 downloads)
|
|
Diamondjag
 Legend
    Posts: 404
Joined: 3/12/2006
Location: Brighton, Colorado
User Profile |
Added the "end if" and it works nicely. Will now go in and pretty it up with the indentations.
Thank you so much!
|