OmniTrader Professional Forum - Trade Plans In Strategies
Nbar stop with condition

^ Top
Sergey

Posts: 6

Joined: 2/11/2016

User Profile
 
Subject : Nbar stop with condition
Posted : 2/11/2016 2:44 PM
Post #25007

Hello!
I 'm trying to make a stop which work same as Nbars stop but closes the position only if market does not move in position direction, therefore leave the position open if price is higher then entry price.
It must be something like this: If after specified number of bars C < EntryPrice then Signal=ExitSignal (for long position).
Can anyone give me an idea how to tell omnitrader to check for this condition only after specified number of bars(default 2 bars)?
Thank you

^ Top
Jim Dean

Posts: 3433

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

User Profile
 
Subject : RE: Nbar stop with condition
Posted : 2/11/2016 2:56 PM
Post #25008 - In reply to #25007

#Stop
#param "Delay", 2, 1, 10
dim Bcnt as integer = 0

if Bcnt >= Delay then
if Signal = LongSignal then
if C < EntryPrice then Signal=ExitSignal
else
if C > EntryPrice then Signal=ExitSignal
end if
end if

Bcnt += 1

... not tested but it should work OK
^ Top
Sergey

Posts: 6

Joined: 2/11/2016

User Profile
 
Subject : RE: Nbar stop with condition
Posted : 2/11/2016 8:24 PM
Post #25009 - In reply to #25008

Thank you Jim. It works but not as I want. This stop continues to follow the position after 2nd bar so it can close position on 3rd, 4th or any other following bars. My idea is to wait 2 bars after position opening and if it non profitable at this time then close it. But if it profitable at 3rd bar then leave it to go no matter where the market will go after. Anyway your stop almost correct in my situation, I just change "if Bcnt >= Delay" to "if Bcnt = Delay" and now it work exactly the way I want.
Thank you very much one more time for help.


https://www.omnitrader.com/currentclients/proforum/thread-view.asp?threadid=5362&posts=3