Not logged in
Viewing 2 posts - 1 through 2 (of 2 total)

Forums>StrategyQuant>General Discussion>Will B127 support custom Trailing Stop method in CodeEditor?

  • #257678 |
    Customer
    268 Posts

    I don’t know if B127 will support custom exit method in coding editor. I want to implement some custom methods for exit, but I ’m not sure if the SQ can convert to MC / TS language well.

    B127 has been postponed for too long, and we have not seen any development or beta version so far.

    But I am really not satisfied with some exit method inside SQ.

    Friends who use TS or MC, do you think so?

    for example, this is a trailing stop with activation, using ATR.

    Compared to the trailing stop using fixed pip/size, the implementation using ATR is not very accurate.

    ...
    LongSLPlaced = false;
    
    	If BarsSinceEntry = 0 then begin
    		IntLongSL = 0;
    		IntLongTS = 0;
    	end;
    
    	// StopLoss
    	IntLongSL = EntryPrice - EnterRvrAtMrkStpLss * tickSize;
    	IntLongSL = SQ_CorrectMinMaxSLPT(IntLongSL, MinimumSL, MaximumSL, true);
    
    	Sell("LongSL") next bar at IntLongSL stop;
    	LongSLPlaced = true;
    
    	// ProfitTarget init
    	IntPT = 0;
    	
             
    	// Trailing Stop
    	IntPriceLevel = EnterRvrAtMrkTrlStpCef * SQ_ATR(20)[1];
    	If IntPriceLevel > 0 and Close - EntryPrice >= Round2Fraction(EnterRvrAtMrkTrlActCef * SQ_ATR(20)[1]) and (IntLongTS = 0 or Round2Fraction(Close - IntPriceLevel) > IntLongTS) then begin
    		IntLongTS = Round2Fraction(Close - IntPriceLevel); // remember also trailing stop
    	end;
    	If IntLongTS > 0 and IntLongTS > IntLongSL then begin
    		Sell("LongTrailingStop") next bar at IntLongTS stop;
    		LongSLPlaced = true;
    	end;		
    
    ...

    I don’t know how SQ works internally, and how it works with TS or MC’s backtest engine.

    Here is my suggestion according to this piece of EL code.

    1,IntLongsl.

    If use the ATR for intial stop loss. Lets’s use the fixed value, the ATR before the entry.

    
    preatr = SQ_ATR(20);
    
    //------------------------------------------------------------------
    //  entry
    //------------------------------------------------------------------
    //.....entry part
    
    //------------------------
    // Orders Exits (SL, PT, Trailing) for Rule: Long entry 
    //------------------------
    
    if(MarketPosition > 0) then begin
    
    	LongSLPlaced = false;
    
    	If BarsSinceEntry = 0 then begin
    		IntLongSL = 0;
    		IntLongTS = 0;
    		AtrbeforeEntry = preatr[1];	
    	end;
    //...

    Then we set the initial stop loss and profit target. SL and PT will remain at fixed levels and ensure that they are consistent with the RR ratio.

    * It is strongly recommended to put all the calculation of technical indicators before the codes of entry and exit, to ensure that there will be no deviation when calling it.

    2. Trailing stop

    There is an obvious mistake in activation. we should use the highest price in the long position holding. And it’s very easy.

    if(MarketPosition > 0) then begin
    
    	LongSLPlaced = false;
    
    	If BarsSinceEntry = 0 then begin
    		IntLongSL = 0;
    		IntLongTS = 0;
    		HighestInLong = close;	
    	end;
    	If BarsSinceEntry >0 then 
    		HighestInLong = max(HighestInLong, close);

    Like initial SL and PT, it is better using the fixed ATR value.

    IntPriceLevel > 0 and Close - EntryPrice >= Round2Fraction(AtrbeforeEntry)

    3. trailing stop price

    There are some types, like,
    1)IntLongTS = Round2Fraction(Close - IntPriceLevel) This is the method in SQ now.

    2)

    IntLongTS = Round2Fraction(Close - IntPriceLevel)
    IntLongTS = MAX( Round2Fraction(Close - IntPriceLevel), [IntLongTS] )

    3)
    IntLongTS = Round2Fraction(HighestInLong - IntPriceLevel)

    The last two method to avoid late exit due to slow down.

    If it can’t coding in the codeditor, I hope SQ can improve these exit methods. I have requested many times. I believe this will also help other traders.

    #257699
    tomas262
    Administrator
    1823 Posts

    Hello,

    we will release next SQ update 127 by the end of this week likely if no major bug is found.

    In this version you will be able to build your own “blocks” that can be used for either entry or exit  but I guess not for trailing stop activation as you suggest

    I see there has already been discussion about SL and TSL implementation in MC and EL code but I will let developers know about this

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.