Idea for a Trailing Stop Strategy

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Idea for a Trailing Stop Strategy

Postby loseend » Tue Jul 31, 2018 1:14 pm

Hello everybody

Last couple weeks I tried two of the Trailing Stop Strategies offered here for download.
Chandelier and SAR. This is fascinating programming stuff to me. The strategies work just fine, technically. I am really stunned to just leaning back and watch the Stops moving and get triggered eventually without laying a hand on it.

I’m sure the underlying logic of those two Trailing Stops is extremely tricky but actually the strategies won’t work for me. I got kicked out early too often in good trades. Shame, for I kinda like the way Chandelier yoyos.
Matter of fact I’ve been using a Trailing Stop technique for years now that “yoyos” as well, I mean, it’s shifting Stop level up and down as Chandelier does.

I wondered if someone might be willing to write it as a strategy. I only can write VBA but I don’t understand lua.

Explanation for a Short Trade:
Step 1. If a Bar closes below prev Bar then Stop: High(1) + 1p
So, Stop point is 1pip above pevious High.
Step 2. If Bar closes within previous Bar-Range then Stop : High(2) + 1p
Previous bar has now become an Outsider.
So, Stop is shifted back 1 pip above the second to last High
Stop will remain there until current Close breakes Outsider’s Low.
Step 3. If Close makes new Low proceed with Step 1.

If Outsider’s High happens to be the Max High of (n) Range and there is no previous higher High then Stop: Outsider’s High.

Vice versa for Longs.

One of your pros here feeling to turn my idea (not my own idea but taken from a trading book) into a strategy?? If so – the distance to previous High should be optional, that is, whether 1pip above previous Highh ore more. And it should be optional to call whether Stop is to be be shifted (in case of an Outsider) or not. Third option should call the distance of when a Low is considered being taken (e.g. a new Low of 1 Pip is a different thing in H1 or M15 or M5)

Dirk
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby Apprentice » Wed Aug 01, 2018 9:31 am

Your request is added to the development list under Id Number 4208
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Idea for a Trailing Stop Strategy

Postby loseend » Wed Aug 01, 2018 12:00 pm

Thank you very much! eh, I'm a freshman here - is there actually a development list where I can look up all the requests? Or does it just mean it'll take awhile? Stupid question I suppose
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby Apprentice » Wed Aug 01, 2018 2:02 pm

The list is available to all fxcodebase developers.
If and when the task will be developed depends on available time and interest of all available developers.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Idea for a Trailing Stop Strategy

Postby loseend » Thu Aug 02, 2018 2:13 am

I see. An idea should be intreresting to be bothered of, sure thing actually. I fear my idea is just too f*** simple to sound interesting. Curious about it...
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby Apprentice » Fri Aug 03, 2018 3:56 am

As an additional incentive.
We get being paid for all our work also.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Idea for a Trailing Stop Strategy

Postby Apprentice » Fri Aug 03, 2018 4:02 am

Try this version.
Trailing_stop_loseend.lua
(45.98 KiB) Downloaded 529 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Idea for a Trailing Stop Strategy

Postby loseend » Fri Aug 03, 2018 11:40 am

WWhat a wonderfu!! work. I don't get it. Thank you very much.
I'll be back later.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Fri Aug 03, 2018 1:55 pm

Hey, I didn't have too much time yet to testing the strategy - but at first sight it looks like a good match to my rules! I diddn' figure out yet what "Range" means (is it the Max Hihg(n)? ), but I#ll see. What is missing still is the option shift/shift not.

I don't know but looks like the strategy did something wrong when I tested a short trade in simulation mode. I did repeat the same trade a couple times but I just don't understand why the Stop Level moves down within an Outside Range.
4 Insidebars the Stop remained above the Outsider - it was a long-Range-Outsider, so shifting the Stop to the second to last High would not have been appropriate. Strategy did perfectly well up to this 4th bar! But then with the 5th Bar it moved - though none of the prev 4 Insiders closed below the Outsider.

The 4th bar or candle was a Doji - it took the Outsider's Low by 12 Pips but bounced back into the Outsider's Range and closed there. It turned out that arbitrarily moving the Stop did'nt spoil the trade - for the 5th bar instantly started to really run.

In fact the result was 100% perfect. When the Stop got triggered I would have triggered it myself when trading the technique on a discretionary basis. But that flaw on the 4th bar worries me.


I tried to send you 100 bucks but now my own strategy has a problem. I used to have a credit card for 20 years or so, but this july the bank didn't renew it for I didn't use it a single time in 20 years. hehe. Neither do I have a PayPal account and I won't open one. Is there a way to bank-transfer money? I would prefer that. May be you you have an idea for I really would like to pay you.
Even with this little flaw the strategy is usable.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Sat Aug 04, 2018 5:58 am

I think I found the "error".

Hopefully html won't mess around with pasted notepad-text.

Apprentice, I don't know nothing about lua but with a common sense of logic lua is becoming legible, at least when it gets to the signal logic and code itself. I cut your original code down to a SHORT-Trade.

This is where you define an OUTSIDER (I figure):
[if ...]
elseif mode == 2 then
if trade.BS == "S" then
local diff = (lowest - source.low[period]) / source:pipSize();
if diff >= threshold then -->another if/then missing here

trading:MoveStop(trade, source.high[period] + distance * source:pipSize());
mode = 1;

else
local max = core.max(source.high, core.rangeTo(period, range));
if max == source.high[period] then
trading:MoveStop(trade, source.high[period] + distance * source:pipSize());
end
end
end
end

Once an Outsider's becoming active (Mode 2) the Outsider must then be handled like being a previous bar (Mode 1). Actually switching back to Mode 1 shall only be allowed if CLOSE breakes Outsider's Low, so the same if/then-condition as of Mode 1 got to be applied with Mode 2:

if source.close[period] < lowest then
trading:MoveStop(trade, source.high[period] + distance * source:pipSize());
mode = 1;
end


This eliminates the flaw (according to signal rules) and works just pefrfect.

I also tinkered a version that implements the Shift-option - i.e. not as an option but as a separate Indicator (for I don't know how to handle such things in lua).
This also works fine.

I think I got what was I was hoping for - thank you so much, Apprentice!
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Next

Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Majestic-12 [Bot] and 28 guests