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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
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 !
Size:
Color:
sorry for duplication. I made image ( in attachment ) for clarification.
Please take a look.
Size:
Color:
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 bar3. 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.
Size:
Color:
Thank you, Eugene ! Now looks like it works !
Size:
Color: