Initial stop that turns into trailing stop
Author: leeto
Creation Date: 6/1/2015 11:04 AM
profile picture

leeto

#1
Could you help me. I Need to set up first stop loss order which turn move to trailing stop if price go to my direction.

For example, Let's take some default strategy.
CODE:
Please log in to see this code.





My condition for the first stop in the code below ( at the end )

CODE:
Please log in to see this code.


Please help me to write these few lines. Thx in advance.



profile picture

Eugene

#2
Wow, you're pretty inquisitive for your first day of evaluation! :)

On a related note, that built-in Two Bar Breakout system you're referring to in all your posts has some room for improvement. The order of exits is not realistic enough (too optimistic). The correct way as per the WealthScript Programming Guide > Programming Trading Strategies > Peeking > Order of Trading Signals should be:

CODE:
Please log in to see this code.


As to your code, follow the design pattern and if the code you've written doesn't work, we'll try to help.
profile picture

leeto

#3
Eugene,

Sorry, if I bother you so much I promise when I adopt to syntax and functions usage the numbers of inquiries will be less tenfold.
profile picture

Eugene

#4
Okay. Your request is somewhat ambiguous as it's not clear if those low/high prices are fixed at the bar of entry. This example assumes they are:

CODE:
Please log in to see this code.
profile picture

Eugene

#5
In an unnecessary duplicate thread, leeto asked

I need to set up simple condition for initial stop and trailing stop.
Initial stop should be at the low of the entry candle
and once the price goes up and candles with low that higher than initial stop appears - > trailing stop should be placed at the low of the previous candle

I test the code below on DOW 30 (last 500 bars ) daily and find nonsense trades when trades keep going 26 bars and ended in money lost and (exit by "initial stop") .


CODE:
Please log in to see this code.


Many thanks in advance !
profile picture

leeto

#6
sorry for duplication. I made image ( in attachment ) for clarification.
Please take a look.
profile picture

Eugene

#7
Here's food for thought to keep you busy for some time:

1. First and foremost, these exits are peeking into the future. You should never use "bar" for anything but AtClose orders. For all other exit types, change the code to execute at "bar+1".

Further reading:

* The Dangers of Looking Ahead (Peeking) in Trading System Development
* WealthScript Programming Guide > Programming Trading Strategies > Peeking

2. And if by using "bar" instead of "bar+1" you intended to exit at the same bar, it's time to reconsider. See FAQ: I want to test a strategy that buys and sells with stop/limit orders on the same bar

3. You should not use Bars.Open[bar+1] when bar == Bars.Count as this will throw an exception.

BTW, Wealth-Lab has means to access current session's opening price (aka Open[bar+1]) with GetSessionOpen but it will not work with ASCII data by design.

4. This code doesn't require Position.AllPositions as it follows the single-position template.
profile picture

leeto

#8
Thank you, Eugene ! Now looks like it works !
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).