Show Plot ATR Trailing Stop with changing parameters.

Hello

I'm having trouble even starting to construct a script for a Show Plot item.

I want to create an ATR Trailing Stop, whose parameters change depending on whether the XAO closes above or below a moving average.

I think I need to use the RATCHET function, along with the IF function, but I have no idea how to put it all together.

Is it even possible?

Any help would be really appreciated.

Thanks

 

Hi Merrilee,

That is an interesting idea. I tend to be very wary of having a stop loss calculated from another security because it adds another level of complexity to what should be a clear decision. Regardless I’m curious about what parameters you are wanting to change.

If it was length based, I’d calculate both of them.

a14 = ATR(bars=14);

a20 = ATR(bars=20);

then get the data of the security

x1 = GETDATA(CODE=XAO:WI);

now we can do an if on that. Let’s just say if the 10 day change is positive we use the a20 level, but when it turns down we tighten the stop (that’s actually a smart idea if that is what you were thinking).

a1 = if(CHANGE(x1, bars = 10) IsUp, a20, a14);

Now we subtract that from the close and apply a ratchet so it can not go down - you just need to set the start date for the ratchet function.

c1 = close() - a1;

RATCHET(c1, START=2019-01-04)

Hope that helps

Mathew

Thank you so much Mathew.

You have certainly pointed me in the right direction, and I will muck around with this code over the weekend and see if I can get it to do what I want it to.

Yes, the idea is to tighten the trailing stop when the XAO starts to show any weakness, and loosen it when it's "strong".

Thanks again

Merrilee

Hi Mathew

I have copied your script to Notepad and pasted it into Optuma, but it's showing as invalid.

I've also tried re-typing the whole thing without any luck.

The only change I have made is to the currency.

Any idea what might be wrong?

Thank you

Merrilee

XAO trail

 

Hi Mathew

I have figured out why the script was showing as invalid. Optuma didn't seem to like the minus sign used in the c1 line.

I've got it to work now, thanks so much for your help.

Merrilee