OmniTrader Professional Forum OmniTrader Professional Forum
forums calendars search
today this week
 
register logon control panel Forum Rules
You are currently browsing as a guest.
You should logon to access more features
A Self-Moderated Community - ALL MEMBERS, PLEASE READ!
Vote for Members who contribute the most to your trading, and help us moderate content within the Forums.


  Current location        Thread information  
OmniTrader Professional Forum
OmniLanguage Discussion
Help with Programming Stops
Last Activity 10/5/2024 12:51 AM
8 replies, 2833 viewings

Jump to page : 1
Now viewing page 1 [25 messages per page]
 
back reply
Printer friendly version

^ Top
Diamondjag

Legend
100100100100
Posts: 404

Joined: 3/12/2006
Location: Brighton, Colorado

User Profile
 
Subject : Help with Programming Stops
Posted : 6/7/2018 10:48 PM
Post #30064

My local investing club put together their “ideal” system and I agreed to program it and run it in OmniTrader to see how it does. They have so many filters in it that it hardly ever trades. Clearly it will be a terrible system but I want to run it for them. I’ve programmed all except the stops. They have three stops and a profit target. I’m not really a programmer and a couple of stops I’m especially having trouble with. I would think all should be fairly easy for a real programmer:

They want a stop ATR(5) X 1.65 below the entry. I’ve programmed:

Stop 1:

If Signal = LongSignal And Entryprice-(ATR(5)*1.67) < Entryprice then
Signal = ExitSignal

ElseIf Signal = ShortSignal And Entryprice+(ATR(5)*1.67) > Entryprice then
Signal = ExitSignal

End If

Doesn’t seem to work. I have no stops in my Omni language files that I can use as an example that deal with stops from the entry price. Any help would be appreciated.

Stop 2:

2% below the Lowest Low of the past 5 days. I’ve programmed:

If Signal = LongSignal And C < (LLV(5)-(LLV(5)*.02))[1] then
Signal = ExitSignal

ElseIf Signal = ShortSignal And C > (HHV(5)+(HHV(5)*.02))[1] then
Signal = ExitSignal

End If

Stop 3:

And the final stop is a close that crosses a Parabolic SAR. I’ve programmed:

If Signal = LongSignal And C[1] > SAR(0.02,0.2) and C < SAR(0.02,0.2) then
Signal = ExitSignal

ElseIf Signal = ShortSignal And C[1] < SAR(0.02,0.2) and C > SAR(0.02,0.2) then
Signal = ExitSignal

End If


PProfit Target:

Finally, they have a profit target that I haven’t even tackled….

Profit Target - 2 times (the entry price minus the initial stop loss price).

Any help on these would be greatly appreciated.

Thanks


[Edited by Diamondjag on 6/7/2018 10:50 PM]

^ Top
Mel

Veteran
10010025
Posts: 235

Joined: 3/18/2006

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/8/2018 7:46 AM
Post #30065 - In reply to #30064

Use the Nirvana Fixed Profit Stop for Stop 1

Use the Nirvana Parabolic SAR stop for Stop 3

Stop 2: I have attached a simple pct Stop (haven't tested it, but it shows the form you can use to write simple stops.)

Modify the pct stop to compute you profit target in the initial part to get Stop 4

Attached file : pctStop.txt (0KB - 259 downloads)

^ Top
Diamondjag

Legend
100100100100
Posts: 404

Joined: 3/12/2006
Location: Brighton, Colorado

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/8/2018 3:22 PM
Post #30066 - In reply to #30065

Mel, Appreciate the reply. Will be looking into your suggestions today. Thanks.
^ Top
Diamondjag

Legend
100100100100
Posts: 404

Joined: 3/12/2006
Location: Brighton, Colorado

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/12/2018 9:54 PM
Post #30069 - In reply to #30066

Mel, or anyone else...I think I've got everything working except the stop for an entry price plus or minus ATR(5)*1.67. In other words a stop 5 ATR's times 1.67 below entry on long trades and 5 ATR's times 1.67 above entry for short trades. I've programmed this but it doesn't seem to work...the stops are too far away. Any help would be appreciated.

#Stop

'CSG FIB ATR Stop
'1.67 time ATR(5) from Entry

dim myLevel as single

if myLevel = 0 then
'this must be first bar of the trade if myLevel=0

'set the fixed level
if Signal = LongSignal then
myLevel = EntryPrice-(ATR(5)+(1.67*(ATR(5)*EntryPrice)))
elseif Signal = ShortSignal then
myLevel = EntryPrice+(ATR(5)+(1.67*(ATR(5)*EntryPrice)))
end if
end if

if Signal = LongSignal then
if C Signal = ExitSignal
end if
elseif Signal = ShortSignal then
if C>myLevel then
Signal = ExitSignal
end if
end if

ExitLevel = myLevel 'so it will plot on chart


^ Top
Jim Dean

Sage
2000100010010010010025
Posts: 3433

Joined: 3/13/2006
Location: L'ville, GA

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/13/2018 6:43 AM
Post #30070 - In reply to #30069

Here ya go:

myLevel = EntryPrice-1.67*ATR(5)
elseif Signal = ShortSignal then
myLevel = EntryPrice+1.67*ATR(5)

Also correct/simplify the final if then to:

If Signal = LongSignal and C < myLevel then
Signal = ExitSignal
elseif Signal = ShortSignal and C > myLevel then
Signal = ExitSignal
end if


PS: although is legal not to in OL, when you post code on the forum the > < disappear unless you put spaces around them.

[Edited by Jim Dean on 6/13/2018 6:46 AM]

^ Top
Diamondjag

Legend
100100100100
Posts: 404

Joined: 3/12/2006
Location: Brighton, Colorado

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/13/2018 1:27 PM
Post #30071 - In reply to #30070

Jim, I really appreciate the response. I put in the code and get one error. Tried all kinds of things but can't straighten it out. Simple, I'm sure but my coding skill is pretty far down the scale.

myLevel = EntryPrice-1.67*ATR(5)
elseif Signal = ShortSignal then
myLevel = EntryPrice+1.67*ATR(5)

If Signal = LongSignal and C < myLevel then
Signal = ExitSignal
elseif Signal = ShortSignal and C > myLevel then
Signal = ExitSignal
end if

Line: 13; 'ElseIf' must be preceded by a matching 'If' or 'ElseIf'.
^ Top
Jim Dean

Sage
2000100010010010010025
Posts: 3433

Joined: 3/13/2006
Location: L'ville, GA

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/13/2018 1:32 PM
Post #30072 - In reply to #30071

Hi sorry I was unclear. I was providing snippets not complete code. Here is the complete version:

#Stop
'CSG FIB ATR Stop
'1.67 time ATR(5) from Entry
dim myLevel as single
if myLevel = 0 then
'this must be first bar of the trade if myLevel=0
'set the fixed level
myLevel = EntryPrice-1.67*ATR(5)
elseif Signal = ShortSignal then
myLevel = EntryPrice+1.67*ATR(5)
end if
end if
If Signal = LongSignal and C Signal = ExitSignal
elseif Signal = ShortSignal and C>myLevel then
Signal = ExitSignal
end if
Exitlevel = myLevel 'so it will plot on chart

PS - I normally use a plotprice command instead of the last line.

[Edited by Jim Dean on 6/13/2018 1:34 PM]

^ Top
Diamondjag

Legend
100100100100
Posts: 404

Joined: 3/12/2006
Location: Brighton, Colorado

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/13/2018 2:44 PM
Post #30073 - In reply to #30072

Jim,

Sorry. Shows my level of coding expertise although I have a lot of stops, systems, indicators I've coded throughout the years but obviously all of them relatively simple.
I really appreciate your help. Need to get this local club system off my back so I can get back to working with all the new Nirvana goodies. Hard to keep up with them.

Missed seeing you at the BASH.

Thanks again.

Dave

^ Top
Jim Dean

Sage
2000100010010010010025
Posts: 3433

Joined: 3/13/2006
Location: L'ville, GA

User Profile
 
Subject : RE: Help with Programming Stops
Posted : 6/13/2018 3:19 PM
Post #30074 - In reply to #30073

Glad I could help ... missed seeing you and other friends. Next year!
Jump to page : 1
Now viewing page 1 [25 messages per page]
back reply

Legend    Action      Notification  
Administrator
Forum Moderator
Registered User
Unregistered User
E-Mail this thread to a friend
Toggle e-mail notification


Nirvana Systems
For any problems or issues please contact our Webmaster at webmaster@nirvsys.com.