Trailing Stop Modification

Hello,

 

  • Leon Wilson and others use the ADX or other indicators to control the level of the trailing stop to ensure we get out the market at better times.
  • I have tried to code something along the lines of once the ADX > 30 then the stop is 3.5x ATR away whilst when it is below its > 7.5x ATR awa.
  • The problem I have is the stop should stay at 3.5x once the ADX > 30 and not go back 7.5x. The time when the price peaks the stop temporarily moves up but then goes back to 7.5x
v1 = adx();

v2 = IF(v1>30,st(MULTI=3.50, BARS=10), st(MULTI=7.50, BARS=20));

close() CrossesBelow v2

thnaks

mandeep

Hi Mandeep

Have a look at the Ratchet function. It should help with this https://help.optuma.com/kb/faq.php?id=1045

All the best

Mathew

Hi Mathew

I have looked at the Ratchet function and put together the following script:

//Get the value when ADX CA 30

$v=VALUEWHEN(adx() > 30);

//Calculate trailing below the low on the date of the ADX move

v1 = RATCHET((LOW() - 3.5*atr()), START=$v);

v2 = st(MULTI=7.50, BARS=20);

if($v,v1,v2)

Unfortunately its not allowing showing or allowing a bactest possible. Is this script an error or is what I’m trying to do not possible?

Thanks any advice is always appreciated.

cheers

Mandeep

Hi Mandeep,

For the IF statement to work there has to be a boolean (true/false) condition so it knows when to choose v1 or v2. What is the condition?

Hi Darren,

Thanks - the condition should be when the ADX() > 30, which is why i put that here: $v=VALUEWHEN(adx() > 30).

Is there another way to specify the start period … basically when adx() > 30, tighten the stop. When is <30 leave a wider stop.

Thanks

Mandeep

 

Hi Mandeep,

ValueWhen gives the price value when that event happens. See Here https://help.optuma.com/kb/faq.php?id=1048

Because that is a value, you can not use it in the IF statement. That first item in the if must be a true false result (or at least 0 or 1)

I added “ad1” as a separate variable so it can be used in the ValueWhen and the If.

//Get the value when ADX CA 30
ad1 = adx() > 30;
$v=VALUEWHEN(ad1);

//Calculate trailing below the low on the date of the ADX move
v1 = RATCHET((LOW() – 3.5*atr()), START=$v);
v2 = st(MULTI=7.50, BARS=20);

if(ad1,v1,v2)

All the best

Mathew

Hi

Thanks - unfortunately I have plotted this script and it doesn’t work. I also tried varying the script to make it 2x ATR. The dotted line is this 2x ATR where the script should have taken me out of the market.

Any advice for this at all . Thanks

 

Capture

Hi Mandeep,

My response was just to show you that you needed a boolean value for the IF condition. I’m not trying to give you a script that works.

My advice is to break out each individual value and make sure that it is doing what you expect.

If you want me to write the full script for you, please go to optuma.com/consults and book an enterprise consult. One of the other guys will do it for a normal scripting consult.

All the best

Mathew