SAR trailing stop

Strategies are published here.

Moderator: admin

SAR trailing stop

Postby Nikolay.Gekht » Mon Oct 18, 2010 9:11 pm

The strategy sets stop value for the chosen trade using SAR indicator.

Note: Since SAR is a bar indicator, the stop value is changed only in the moment when new candle of chosen time frame appears. I.e. if you choose 1 minute time frame - the stop will be changed every minute. If you choose 1 hour time frame - the stop will be changed every hour.

Note: SAR sometimes generates a stop value which is very close to the price. So, choose ask price to set stops on shorts and bid prices to set stops on longs.

sarstop.png


download:
sarstop.lua
(5.83 KiB) Downloaded 2277 times


The Strategy was revised and updated on December 11, 2018.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: SAR trailing stop

Postby ronald3rg » Sun Jan 29, 2012 5:44 pm

Strategy does not work
Right place at the right time

3Rg
ronald3rg
 
Posts: 39
Joined: Tue Oct 18, 2011 6:12 pm
Location: New York

Re: SAR trailing stop

Postby sunshine » Mon Jan 30, 2012 1:03 am

Please tell me the error message you are getting. You can see it in the Events window.
The strategy works for me. Please note that the strategy is not intended to be used on US based accounts.
sunshine
 

Re: SAR trailing stop

Postby ronald3rg » Mon Jan 30, 2012 3:59 pm

Ok that might be the problem Im in the US.
Right place at the right time

3Rg
ronald3rg
 
Posts: 39
Joined: Tue Oct 18, 2011 6:12 pm
Location: New York

Re: SAR trailing stop

Postby tradaplaya » Tue Nov 13, 2012 1:45 pm

I have a question about this strategy;

What happens if I am in a long trade, and the sar value is current showing the down value. How will the stop be calculated, or will it automatically enter the stop order once the sar value is in the right direction?

Can this program be modified to execute as soon as you get into a position or will that result in a loss if the sar value is opposite that of trade.

I am trying to add this strategy to the NEW PIVOT STRATEGY to make pivot stratgey that uses the sar value as the trailing stop once the pivot strategy generates an order.

Please help me, I can do some coding I just need help with where to start.
tradaplaya
 
Posts: 3
Joined: Tue Nov 13, 2012 1:39 pm

Re: SAR trailing stop

Postby Nikolay.Gekht » Wed Nov 14, 2012 9:12 am

tradaplaya wrote:What happens if I am in a long trade, and the sar value is current showing the down value. How will the stop be calculated, or will it automatically enter the stop order once the sar value is in the right direction?


The strategy uses only down part of SAR for "B" (long) trades and up part of SAR for "S" (short) trades. If SAR is above long TRADE the stop isn't touched at all. The same for SAR below a short trade.

Here is a part of the logic which is in charge for this:
Code: Select all
            if trade.BS == "B" then
                if sar.DN:hasData(period) then
                    stopValue = sar.DN[period];
                else
                    return ;
                end
                stopSide = "S";
                if stopValue >= instance.bid[NOW] then
                    return ;
                end
            else
                if sar.UP:hasData(period) then
                    stopValue = sar.UP[period];
                else
                    return ;
                end
                stopSide = "B";
                if stopValue <= instance.ask[NOW] then
                    return ;
                end
            end
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: SAR trailing stop

Postby tradaplaya » Wed Nov 14, 2012 2:25 pm

okay perfect. Thanks for pointing that bit out there.
tradaplaya
 
Posts: 3
Joined: Tue Nov 13, 2012 1:39 pm

Re: SAR trailing stop

Postby tradaplaya » Wed Nov 14, 2012 7:44 pm

is there a way to change the order id to accept pending orders not just existing trades? That way once is order is filled the strategy kicks in and places the sar stop automatically.
tradaplaya
 
Posts: 3
Joined: Tue Nov 13, 2012 1:39 pm

Re: SAR trailing stop

Postby Nikolay.Gekht » Mon Dec 03, 2012 1:47 pm

Yes, it is possible to change trade selector to order selector (by using core.FLAG_ORDER instead of core.FLAG_TRADE in the parameters).

The the strategy should watch changes in the orders table (until order disappears) and trades table (until a trade created by the order appears) and then implement the existing logic. I hope that Alex Gettinger or Apprentice can easily do this.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: SAR trailing stop

Postby dell123 » Tue Apr 09, 2013 10:40 pm

Is there a sar stop strategy strategy for US based accounts and if not, can this one be modified to work? Thank you for your help.
dell123
 
Posts: 17
Joined: Thu Apr 05, 2012 12:20 pm

Next

Return to Custom Strategies

Who is online

Users browsing this forum: No registered users and 90 guests