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

Re: Idea for a Trailing Stop Strategy

Postby loseend » Sat Aug 04, 2018 12:55 pm

Of sporting reasons: there was much more jelly in the coded signal logic than it looked to me at first. But sure thing, to the Apprentice pro it was just a sketch, a very useful one to me.
Spent the day adjusting these few code lines. Exhausting but it payed.

Interesting thing is that the 2 strategies (shifted and non shifted) now absolutely safely detect the relevant Outsider - and will freeze it's high/low as Break- or Stoplevel, not matter if Outsiders within Outsiders occur on the way ...

What a fine board that is.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Mon Aug 06, 2018 3:58 am

Apprentice,
I asked if it's possible to write the strategy as an indicator - but that might be to much work, I guess. It would be fair enough if you would implement a line-option into the strategy itself.

As I said before I revised the signal code to my needs: e.g. I dropped the option "Range".

(The following is explained just for the SHORT side only)
So, when loop is in mode = 2 there is no "else" (no Range) anymore instead the Stop level just remains as defined in mode 1. Also defined in mode 1 (within that same loop) is "lowest".

So, the "else"-condition should be reapplied in mode 2 - something like:
else
draw line at "lowest"-value
end


Once mode is switching again: STOP drawing line.

Can you do that?
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Tue Aug 07, 2018 12:12 am

Yeah, I#m learning... That was bad thinking. To have such line I asked for it has to be an indicator, right? Right.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Wed Aug 08, 2018 3:09 am

I tried to copy & and paste an indicator version - source was the simple mva for the mva got what I need: a line within the chart. Thought I could just replace mva's calculation by the Trailing Stop's signal code. But didn't work.

Most likely my indicator is just crap, but may be yet it's revisable. I cut the signal code down to the Short-mode so for now there is just the down line to be generated.

Apprentice can you have a look at it and may be correct it?
I doubt that I would have any further indicator or strategy request in the future.
Attachments
Trailing_stop_loseend_Line.lua
(2.53 KiB) Downloaded 486 times
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby Apprentice » Wed Aug 08, 2018 9:11 am

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

Re: Idea for a Trailing Stop Strategy

Postby loseend » Wed Aug 08, 2018 10:19 am

Thank you!
Until then I'll keep on trying myself. Image shows how I got along so far in generating a horizontal line.
Problem is that the indicator won't do the switch from mode 1 to mode 2.
Should I eventually figure out a working code I'll tell you.

TSdw.png
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Thu Aug 09, 2018 3:26 am

I finally made it, give or take.
"Trick" was to add a third mode in order to replace the trading mode (BUY/SELL) from the strategy, i.e. to avoid a down line in an up move, and vice versa.

TSdw_freeze.png


Idea was to have the particular outsider marked the trailing stop strategy has determined to be outsider. First outsider of the image is correct - the second and third outsiders are correct as well but the horizontals won't make it to their break bars. Not so bad.
But there is an effect I didn't expect.

After applying the line generator and the the price chart keeps on moving the lines are - don't know, do you call that repainting? I think I don't want that. Is there a way to cut the crap?

Now, my request has eventually come down to just deactivate this "repainting" effect.


TSdw_moving.png


This is the code cut for the short side only.
Attachments
TS_Outsider_indicator_loseend.lua
(3.31 KiB) Downloaded 472 times
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

Re: Idea for a Trailing Stop Strategy

Postby loseend » Thu Aug 09, 2018 8:14 am

Done.

A user showed me a perception error. But thanks Apprentice anyway, you can cancel me from your development list.

I think that was it for me requesting any source codes. An interesting request I find is in the neighbor thread "Nesw Breakeven" - very curious about that.
See ya around.
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm


Re: Idea for a Trailing Stop Strategy

Postby loseend » Sat Aug 11, 2018 5:09 am

Yeah I kind of guessed something like that.

Besides: as i said I revised the original strategy code to my needs. Especially I added three conditions according to which the STOP is to be moved to the second to last bar.

But the routine gave me an error call (calculating with a nil value). I googled for error handling in lua, I was hoping to find something like in VBA (On error resume next/on error goto 0) - for if the calculation would bump into a nil value just skip the error and leave the STOP where it is.

I found pcall - but it remained obscure to me. I just don't feel to getting more into lua for my experience with learning languages is: it's keeping you from trading.
But then after 2 hours! or so I noticed that the prblem was not the nil value but a simple wrongly assigned variable name...
So - happily I didn't find something like ON ERROR RESUME NEXT...

The excel debugger would have prevented me from that kind of error by Option Explicit
loseend
 
Posts: 56
Joined: Tue Jul 31, 2018 12:37 pm

PreviousNext

Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 13 guests