Is it possible to use trailing stop as trigger?
Author: sofia
Creation Date: 10/2/2015 3:56 PM
profile picture

sofia

#1
Hello,

Is it possible to create a trigger in form of Boolean condition if trailing stop is hit ?

Here is an example

CODE:
Please log in to see this code.

Instead of trailing stop is it possible to generate a trigger ?

I tried this, but it won't work
CODE:
Please log in to see this code.


I don't want to exit the position when trailing stop is hit, but simply use it as a trigger for some other condition.

Thanks,

Sofia
profile picture

Eugene

#2
QUOTE:
I don't want to exit the position when trailing stop is hit, but simply use it as a trigger for some other condition.


Your condition would only work for one bar. Below is the design pattern for triggers that last for a number of bars or indefinitely:

WealthScript Techniques | Setups, Triggers, Delays, and Timeouts
profile picture

sofia

#3
Thanks,

Sofia
profile picture

sofia

#4
Hello,

I tried this, but the trigger is not activated.

CODE:
Please log in to see this code.


Thanks,
Sofia
profile picture

Eugene

#5
Today's close can not cross above/below the lowest (or highest) close of 5 days because the lowest price includes today's close too, by definition. In this case, offset the series one bar to the right:
CODE:
Please log in to see this code.


And the resulting demo strategy may look like this:

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

sofia

#6
Thanks,

Sofia
profile picture

sofia

#7
Hello,

One more question. In the following code, how do I enter another condition that when buy condition is met if absolute value of current close price is smaller than the absolute value of previous sell price by percent amount less than percent PPO.Series(1,2) then ignore the buy condition. Also when sell condition is met if absolute value of current close price is smaller than the absolute value of previous buy price by amount less than percent PPO.Series(1,2), ignore the sell condition.
Basically would like to filter out buy/sell trades based on previous conditions.
It doesn't matter for daily bars, but for intraday bars.

Here is the code.
CODE:
Please log in to see this code.


Thanks,

Sofia
profile picture

Eugene

#8
Did you notice that the unformatted code in your posts come up nicely formatted and colorized? This has been my edits but it's time to tell that you can do it too. Please use the # button (CODE) to wrap your code, and not the "" (QUOTE) nearby. Thanks.

As to your question, you've probably stumbled onto defining the previous sell price. The function PreviousSell below can be used as a building block. It returns a -1 if the previous position is still open (or you've just entered for the first time), or the previous exit price.

CODE:
Please log in to see this code.


Now your job is to integrate this into your code. Hope that helps.
profile picture

sofia

#9
Thanks Eugene

Regards,
Sofia
profile picture

sofia

#10
Hi Eugene,

One more question, if I also want to store a value of some DataSeries when previous sell position is asserted. Can I do that.
I tried this by modifying your previousell function.

CODE:
Please log in to see this code.


Thanks,
Sofia
profile picture

Eugene

#11
Hi Sofia,

By saying "is asserted", did you mean to store the volatility value at this Position's exit bar (or any other bar for that matter)? What's the need in a DataSeries?

1. You could store that value within the Position's .Tag property (see QuickRef for more info).
2. Or you could simply store the ExitBar in your series and compare the ATR values between the current and the saved bars.

What is the trading rule in plain English?
profile picture

sofia

#12
Hi Eugene,

The program is based on volatility and percent price change. In order to eliminate the redundant sell signals, I am using volatility as a filter. If volatility is falling and price is off per ppo, then there is chance that market will go up, even though the sell signal is triggered.
In such cases ignore the sell signal comparing the volatility when buy was triggered and volatility when sell is triggered.
If sell volatility is less than buy volatility then ignore sell.
I tried using DataSeries, but something is not right and I cannot figure that out.
Sorry about my poor programming code.

Here is my code. In comment section in the code, I have explained what I am trying to do.

CODE:
Please log in to see this code.




Thanks & regards,

Sofia
profile picture

Eugene

#13
Please try to follow either one of my suggestions. Feel free to ask further questions if something is unclear.
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).