Stage trailing stop

Strategies are published here.

Moderator: admin

Stage trailing stop

Postby Alexander.Gettinger » Wed May 04, 2011 2:56 am

Strategy move stop order correspondence to user level.
Supported maximum 5 levels. If level=0 stop is not used.
Algorithm: if profit of order reaches [Level1] strategy supports stop at level [Stop1], if profit reaches [Level2] strategy supports stop at level [Stop2] etc.

Download:
StageStop.lua
(8.22 KiB) Downloaded 2899 times


The Strategy was revised and updated on December 10, 2018.
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Stage trailing stop

Postby oritzbaba » Tue May 10, 2011 10:54 am

Please is there any more trailing stop management tool like this one on this site, someone more familiar with TS2 custom indicator please help out. Will the Stage Trailing Stop work on automated trading?

Thanks.
oritzbaba
 
Posts: 10
Joined: Tue May 10, 2011 3:55 am

Re: Stage trailing stop

Postby sunshine » Thu May 12, 2011 4:01 am

oritzbaba wrote:Please is there any more trailing stop management tool like this one on this site, someone more familiar with TS2 custom indicator please help out.

Hi,
    Please check the following strategies:
    1. Moving-average based stop order
      The strategy moves stop level of the chosen position exactly on the chosen Moving Average Value.
      viewtopic.php?f=31&t=2339&p=4997#p4997
    2. Trailing by time
      This strategy moves stop on [StepTrailing] points each [TimeInterval] minutes in order direction (up for BUY and down for SELL).
      viewtopic.php?f=31&t=2804&p=6393&hilit=trailing+stop#p63933
    3. Shadow trailing stop
      The strategy sets stop value for the chosen trade using several next candles.
      viewtopic.php?f=31&t=2793&p=6363&hilit=trailing+stop#p6363
    4. SAR trailing stop
      The strategy sets stop value for the chosen trade using SAR indicator.
      viewtopic.php?f=31&t=2449#p5318
    5. ATR trailing stop
      The strategy sets stop value for the chosen trade using ATR oscillator.
      viewtopic.php?f=31&t=2795&p=6365&hilit=trailing+stop#p6365
    6. Fractal trailing stop
      The strategy sets stop value for the chosen trade using fractals.
      viewtopic.php?f=31&t=2791&p=8622&hilit=trailing+stop#p6361
    oritzbaba wrote:Will the Stage Trailing Stop work on automated trading?

    Yes. For this it's necessary to include the code of Stage Trailing Stop to the code of your strategy.
    sunshine
     

    Re: Stage trailing stop

    Postby oritzbaba » Sun May 15, 2011 6:56 pm

    Thank you so much Sunshine for your assistance. But pardon me, I will be asking a lot of questions for a better understanding. First, I want to use this stage trailing stop with the FX Sniper Ergodic CCI strategy, how this will work out I don't know yet but it looks good on paper, any idea on this from you is highly welcome. You mentioned using a code linking it to the strategy, how do I do this? And where can I find the code?

    Questions: 1) Do I have to add it to every currency pair I want to trade for it to be effective? Since it is a strategy, can I assume it will accompany each trade automatically as long as it's attached to that currency pair? 2) Will both strategies be active on TradingStation server? 3) Do I still need to set a stop loss while entering a trade? On TS can I set fixed stop loss and take profit target? 4) If level1 is 10 and stop1 is 0, does this mean stop1 is equal to breakeven? Can it be used in any way for breakeven point? 5) The Choose Trade parameter on the stage trailing stop is blank, what do I put there as there is nothing on the selection dropdown button? 6) How do I use it to lock in profit? Example; if stop1 is 50, I assume it is 50 pips away from the entry price, when I have a profit level3 of 70 pips and I want the stop3 to lock in 40 pips above the entry price on a long position, how do I do this?

    Please Sunshine help out and thank you in advance for your time and energy but above all, your kindness.

    Thanks.
    oritzbaba
     
    Posts: 10
    Joined: Tue May 10, 2011 3:55 am

    Re: Stage trailing stop

    Postby uff2163 » Mon May 16, 2011 9:27 am

    Hi guys:
    It seems hard to find the orders automatically.
    Most of stop strategy requires you enter the trade by yourself..
    such as:
    ---------------------------------------
    strategy.parameters:addGroup("Trade");
    strategy.parameters:addString("Trade", "Choose Trade", "", "");
    strategy.parameters:setFlag("Trade", core.FLAG_TRADE);
    -----------------------------------------
    if row.AccountID == Account and (instance.parameters.Symbol=="- All -" or row.Instrument==instance.parameters.Symbol) then
    ------------------------------------------
    if (haveTrades) then
    local enum = trades:enumerator();
    while true do
    local row = enum:next();
    if row == nil then break end

    if row.AccountID == Account and row.OfferID == Offer then
    -- Close position if we have corresponding closing conditions.
    if row.BS == 'B' then
    CurrentOrder="B";
    MaxB=math.max(MaxB,row.Open);
    elseif row.BS == 'S' then
    CurrentOrder="S";
    MinS=math.min(MinS,row.Open);
    end

    end
    end


    May CurrentOrder is useful .
    uff2163
     
    Posts: 5
    Joined: Fri Mar 18, 2011 8:51 am

    Re: Stage trailing stop

    Postby uff2163 » Wed May 18, 2011 6:46 am

    Hi Guys:
    I found a puzzle from my profit lock strategy.
    I try to develop this strategy to look after all my orders, but it can not work.
    It seems hard to manage all the orders from TS2. :?:

    Code: Select all
    function Init()
        strategy:name("Profit lock");
        strategy:description("Profit lock");
        strategy.parameters:addGroup("Profit lock Parameters");   
        strategy.parameters:addInteger("PriceLevel33", "Profit lock in pips", "", 30, 1, 10000);
        strategy.parameters:addInteger("Stop5", "Lock Profit in pips", "", 2);   
        strategy.parameters:addString("SIDE55", "Use Profit lock", "", "false");
        strategy.parameters:addStringAlternative("SIDE55", "true", "", "true");
        strategy.parameters:addStringAlternative("SIDE55", "false", "", "false");
       
        strategy.parameters:addString("SIDE25", "Close strategy without orders", "", "false");
        strategy.parameters:addStringAlternative("SIDE25", "true", "", "true");
        strategy.parameters:addStringAlternative("SIDE25", "false", "", "false");
    end
    function Prepare(onlyName)
         local Source = nil;
         Level33 = instance.parameters.Level33;
         SIDE55= instance.parameters.SIDE55;
         SIDE25= instance.parameters.SIDE25;
    end

    function ExtUpdate(id, source, period)

    if SIDE55=="true" then


        if (Source:first() > (period - 1)) then
            return
        end

        local pipSize = instance.bid:pipSize()

        local trades = core.host:findTable("trades");
        local haveTrades = (trades:find('AccountID', Account) ~= nil)
       
        local MaxB=0;
        local MinS=100000000;
       
        if (haveTrades) then
            local enum = trades:enumerator();
            while true do
                local row = enum:next();
                if row == nil then break end

                if row.AccountID == Account and row.OfferID == Offer then
                        -- Close position if we have corresponding closing conditions.
                    if row.BS == 'B' then
                     CurrentOrder="B";
                     MaxB=math.max(MaxB,row.Open);
                    elseif row.BS == 'S' then
                     CurrentOrder="S";
                     MinS=math.min(MinS,row.Open);
                    end

                end
            end



            if CurrentOrder=="B" then

             if instance.ask[NOW]-MaxB>=instance.parameters.PriceLevel33*PipSize then
           

                     
            stopValue=instance.bid[NOW]-instance.parameters.Stop5*instance.bid:pipSize();
                   

             
             end
            end
           
            if CurrentOrder=="S" then
             if MinS-instance.bid[NOW]>=instance.parameters.PriceLevel33*PipSize then
           

           
            stopValue=instance.ask[NOW]+instance.parameters.Stop5*instance.bid:pipSize();
             

             
             end
            end

       
    -----------------------------------------------------------------------
        local enum, row, valuemap;

        local count = 0;
        enum = core.host:findTable("trades"):enumerator();
        row = enum:next();
        while count == 0 and row ~= nil do
            if row.AccountID == Account and
               row.OfferID == Offer and
               row.BS == BuySell then
               count = count + 1;
            end
            row = enum:next();
        end

        if count > 0 then
            valuemap = core.valuemap();

           
            valuemap.OrderType = "CM";
            valuemap.OfferID = Offer;
            valuemap.AcctID = Account;
            valuemap.NetQtyFlag = "Y";
            valuemap.Rate = stopValue;
        end   

    -------------------------------------------------------------------------------


       else
         
    if SIDE25 == "true" then
            if CurrentOrder==nil then
              core.host:execute("stop");
            end
            end     
           
    end 
    end
    end

    dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");

    uff2163
     
    Posts: 5
    Joined: Fri Mar 18, 2011 8:51 am

    Re: Stage trailing stop

    Postby Laurus12 » Fri May 27, 2011 12:08 pm

    Hello Alexander,

    If this is the strategy I believe it is I would like to say thank you very much for making it. I have been longing for this for a long time.

    I am not sure if I understand the setup. I get the message "Trade disappear".

    As a starter I would like to just use one level, so I am wondering if you could give an example on how to set it up. As an example I would like to use 25 pips in stop loss and when price reaches 20 pips in profit I would like the stop to jump to 1 pips on the profit side. Meaning 1 pips more than break even. If you could help me with this I would appreciate it a lot.

    Tank you.
    Laurus
    Laurus12
    FXCodeBase: Confirmed User
     
    Posts: 45
    Joined: Tue Jan 26, 2010 6:49 pm
    Location: Norway

    Re: Stage trailing stop

    Postby STEIGO » Fri Oct 28, 2011 6:00 pm

    Alexander

    Could this strategy be modified as follows:
    If profit reaches level1 set SL stop 1
    if profit reaches level2 set SL to "fixed trailing stop" with a starting price of current price-stop 2
    If profit reaches level3 set SL stop 3
    if profit reaches level4 set SL to "fixed trailing stop" with a starting price of current price-stop 4
    etc
    This modification, might allow a normal trailing (fixed pip) SL strategy to deal with expected Support/Resistance levels

    Thanks in advance for your replies :mrgreen:
    STEIGO
     
    Posts: 20
    Joined: Thu Apr 07, 2011 5:28 pm

    Re: Stage trailing stop

    Postby vaguthun » Sun Oct 30, 2011 3:24 am

    I like this Trailing stop..
    I wonder if you could add another feature.

    For example: I traded 2 Mini lots
    when Level1 is reached take Profit of 1 lot
    and at level2 take profit of second lot etc..

    What do u think guys??? :roll:
    vaguthun
     
    Posts: 3
    Joined: Thu Oct 27, 2011 12:10 pm

    Re: Stage trailing stop

    Postby vaguthun » Sun Oct 30, 2011 3:30 am

    I wonder if you could update it this way..

    For Example: I traded 2 mini lots

    And when the level1 is reached take profit of 1 lot. and move TS to level1
    And when Level2 is reached take the second profit or move TS.. etc

    Thanks
    vaguthun
     
    Posts: 3
    Joined: Thu Oct 27, 2011 12:10 pm

    Next

    Return to Custom Strategies

    Who is online

    Users browsing this forum: Baidu [Spider] and 51 guests