Trend surfer DAX modified

Viewing 15 posts - 1 through 15 (of 46 total)
  • Author
    Posts
  • #65668 quote
    irioton
    Participant
    Average

    Hi guys !

    This is the first system I post here.

    I made my own version of Reiners Trend surfer DAX, whith Nicolas´ TDI indicator and my own parameters but the backtest doesn´t work,

    I think it might be because of the trailing stop and take profit which are variables (a and b in the code) that I want to optimize because this will be how I exit the trades, no exit on signal, just sl/tp.

    The message just says “an error occured” but doesn´t say where or why.

    Here´s the code :

    // Trend Surfer DAX Modified
     
    // code-Parameter
    DEFPARAM FlatAfter = 173000
    DEFPARAM FlatBefore = 093000
     
    // DAX trading window
    ONCE BuyTimeMorning = 093000
    ONCE SellTimeMorning = 110000
    ONCE BuyTimeAfternoon = 130000
    ONCE SellTimeAfternoon = 170000
     
    ONCE lengthRSI = 13
    ONCE lengthband = 34
    ONCE lengthrsipl = 3
    ONCE lengthtradesl = 7
    ONCE lineup = 68
    ONCE linemid = 50
    ONCE linedown = 32
     
    // trading parameter
    ONCE PositionSize = 1
    ONCE sl = a
    ONCE tp = b*sl
    
    // emergency stop
    IF STRATEGYPROFIT <-500 THEN
    QUIT ENDIF
     
    // position management during trading window
    IF (Time >= BuyTimeMorning AND Time <= SellTimeMorning) OR (Time >= BuyTimeAfternoon AND Time <= SellTimeAfternoon) THEN
     
    // calculate TDI indicator
    r = rsi[lengthrsi](close)
    ma = average[lengthband](r)
    offs = (1.6185 * std[lengthband](r))
    blueup = ma+offs
    bluedn = ma-offs
    jaune = (blueup+bluedn)/2
    vert = average[lengthrsipl](r)
    rouge = average[lengthtradesl](r)
    
    // open position
    // long
    IF Not ONMARKET AND rouge<bluedn AND vert CROSSES OVER rouge OR rouge<linedown AND vert CROSSES OVER rouge THEN
    BUY PositionSize CONTRACT AT MARKET
    ENDIF
    IF Not ONMARKET AND rouge>linemid AND vert CROSSES OVER rouge THEN
    BUY PositionSize CONTRACT AT MARKET
    ENDIF
    IF Not ONMARKET AND rouge CROSSES OVER jaune THEN
    BUY PositionSize CONTRACT AT MARKET
    ENDIF
    
    
    // short
    IF Not ONMARKET AND rouge>blueup AND vert CROSSES UNDER rouge OR rouge>lineup AND vert CROSSES UNDER rouge THEN
    SELL PositionSize CONTRACT AT MARKET
    ENDIF
    IF Not ONMARKET AND rouge<linemid AND vert CROSSES UNDER rouge THEN
    SELL PositionSize CONTRACT AT MARKET
    ENDIF
    IF Not ONMARKET AND rouge CROSSES UNDER jaune THEN
    SELL PositionSize CONTRACT AT MARKET
    ENDIF
     
    // stop and profit
    SET STOP pTRAILING sl
    SET TARGET pPROFIT tp
     
    ENDIF

    can someone help please ?

    #65672 quote
    robertogozzi
    Moderator
    Master

    Remove ENDIF from line 28 and place it at line 29.

    #65677 quote
    irioton
    Participant
    Average

    Okay ! It does work now (the backtest not the system…yet) thank you ! .

    I´ve got another problem now (I put fixed sl/tp for now) : the system only goes long and cumulates orders, I don´t get it !

    It never goes short and sometimes it takes 2 long positions instead of one.

    I tried to fixe the problem and put EXITs on trades at market when it should reverse, but it doesn´t work, any ideas ?

    Here´s the modified code :

    // open position
    // long
    IF Not ONMARKET AND rouge<bluedn AND vert CROSSES OVER rouge OR rouge<linedown AND vert CROSSES OVER rouge OR rouge>linemid AND vert CROSSES OVER rouge OR rouge CROSSES OVER jaune THEN
    IF SHORTONMARKET THEN
    BUY AT MARKET
    ENDIF
    BUY PositionSize CONTRACT AT MARKET
    ENDIF
    
    
    // short
    IF Not ONMARKET AND rouge>blueup AND vert CROSSES UNDER rouge OR rouge>lineup AND vert CROSSES UNDER rouge OR rouge<linemid AND vert CROSSES UNDER rouge OR rouge CROSSES UNDER jaune THEN
    IF LONGONMARKET THEN
    SELL AT MARKET
    ENDIF
    SELL PositionSize CONTRACT AT MARKET
    ENDIF
     
    // stop and profit
    SET STOP pTRAILING sl
    SET TARGET pPROFIT tp
     
    ENDIF
    #65680 quote
    GraHal
    Participant
    Master

    You need below as the 1st line of code …

    DEFPARAM CumulateOrders = False
    #65684 quote
    irioton
    Participant
    Average

    Thank you Grahal ! That´s it for cumulated orders.

    Now the system doesn´t short, worse, it takes long positions where it shoud sell, I read it again and again but can´t figure it out.

    #65686 quote
    Vonasi
    Moderator
    Master
    BUY //Opens a long position
    SELL //Closes a long position
    
    SELLSHORT //Opens a short position
    EXITSHORT //Closes a short position

    You are using a SELL where you need a SELLSHORT

    #65688 quote
    irioton
    Participant
    Average

    wow I didn´t know that, thank you !

    I am sorry to waste your time with beginners problems,

    The good thing is that I have an edge now ! Yeeeaahh ! I just need to optimise sp/tp

    so here´s the code for now:

    // Trend Surfer DAX Modified
    DEFPARAM CumulateOrders = False
    
    // code-Parameter
    DEFPARAM FlatAfter = 173000
    DEFPARAM FlatBefore = 090500
     
    // DAX trading window
    ONCE BuyTimeMorning = 090500
    ONCE SellTimeMorning = 110000
    ONCE BuyTimeAfternoon = 130000
    ONCE SellTimeAfternoon = 170000
     
    ONCE lengthRSI = 13
    ONCE lengthband = 34
    ONCE lengthrsipl = 3
    ONCE lengthtradesl = 7
    ONCE lineup = 68
    ONCE linemid = 50
    ONCE linedown = 32
     
    // trading parameter
    ONCE PositionSize = 1
    ONCE sl = 50
    ONCE tp = 50
    
    // emergency stop
    IF STRATEGYPROFIT <-500 THEN
    QUIT 
    ENDIF
    
     
    // position management during trading window
    IF (Time >= BuyTimeMorning AND Time <= SellTimeMorning) OR (Time >= BuyTimeAfternoon AND Time <= SellTimeAfternoon) THEN
     
    // calculate TDI indicator
    r = rsi[lengthrsi](close)
    ma = average[lengthband](r)
    offs = (1.6185 * std[lengthband](r))
    blueup = ma+offs
    bluedn = ma-offs
    jaune = (blueup+bluedn)/2
    vert = average[lengthrsipl](r)
    rouge = average[lengthtradesl](r)
    
    // open position
    // long
    IF Not ONMARKET AND rouge<bluedn AND vert CROSSES OVER rouge OR rouge<linedown AND vert CROSSES OVER rouge OR rouge>linemid AND vert CROSSES OVER rouge OR rouge CROSSES OVER jaune THEN
    BUY PositionSize CONTRACT AT MARKET
    ENDIF
    
    
    // short
    IF Not ONMARKET AND rouge>blueup AND vert CROSSES UNDER rouge OR rouge>lineup AND vert CROSSES UNDER rouge OR rouge<linemid AND vert CROSSES UNDER rouge OR rouge CROSSES UNDER jaune THEN
    SELLSHORT PositionSize CONTRACT AT MARKET
    ENDIF
     
    // stop and profit
    SET STOP pTRAILING sl
    SET TARGET pPROFIT tp
     
    ENDIF
    #65692 quote
    irioton
    Participant
    Average

    So, optimisation gives me Trailingstop = 49 and tp= 2.9*sl , but only on 10 000 bars, could someone test it on a 100 000 bars version ?

    Now I have another problem, there are still bits where the trade is taken in the opposite direction (i.e. 23/01/2018 after 9H00 and goes on all day long) of  where it should go, I will see if I can solve it.

    Which also this system can give us more, I will pursue the investigation.

    #65708 quote
    GraHal
    Participant
    Master

    I am sorry to waste your time with beginners problems,

    We are happy to help when we get a good explanation of the Issue (as you have done).

    What Timeframe  is this to be run on? I can’t see TF anywhere sorry?

    #65719 quote
    Nicolas
    Keymaster
    Master

    could someone test it on a 100 000 bars version ?

    We are all willing to help, but you should be able to test yourself on 100k bars.

    #65731 quote
    irioton
    Participant
    Average

    @Grahal : it is on 5min.


    @Nicolas
    : hi ! On ut 5 min, I only got 10 000 bars, maybe if I put x bars and 100 000 it will work, I will try as soon as I get home.

    #65742 quote
    Nicolas
    Keymaster
    Master

    maybe if I put x bars and 100 000 it will work,

    Yes! That’s how it works! 😉

    #65744 quote
    irioton
    Participant
    Average

    Great ! Thanks !

    I can’t wait to get home, 16h of bus, from berlin to Paris, this will hurt…

    #65920 quote
    irioton
    Participant
    Average

    Okay, back from Berlin,

    It’s 4:30 am, I spent the night, backtesting and optimising the strategy (on 100 000 candles 😉 ), I even broke it into pieces, optimizing each one and ….

    it goes nowhere, ratios are not good or not good enough.

    So I threw it away and started a new one. This is a trend surfer DAX too, so I think we can keep it in the same thread.

    It’s 2min, 1pt spread, based on nicolas’ PRC_TTM SQUEEZE and Verdi’s Breakeven that I found in Grahal’s snippets.

    It’s simple : buy when it turns from red to yellow and sell when it turn from blue to dark blue.

    I’m close to get it right, I just got one problem, the system buys on every yellow (next candle of course) and sells on every blue (see the picture attached).

    Here is the code :

    // Trend Surfer DAX Modified
    DEFPARAM CumulateOrders = False
    
    // code-Parameter
    DEFPARAM FlatAfter = 180000
    DEFPARAM FlatBefore = 080500
     
    // DAX trading window
    ONCE BuyTimeMorning = 090500
    ONCE SellTimeMorning = 110000
    ONCE BuyTimeAfternoon = 130000
    ONCE SellTimeAfternoon = 173000
    
    // trading parameter
    ONCE sl = a
    ONCE tp = b
    ONCE lengthKC=20
    
    // position management during trading window
    IF (Time >= BuyTimeMorning AND Time <= SellTimeMorning) OR (Time >= BuyTimeAfternoon AND Time <= SellTimeAfternoon) THEN
    
    value = (Highest[lengthKC](high)+Lowest[lengthKC](low)+average[lengthKC](close))/3
    val = linearregression[lengthKC](close-value)
    
    
    if val>0 and val<val[1] then
    IF LONGONMARKET THEN
    SELL 1 SHARES AT MARKET
    SELLSHORT 1 SHARES AT MARKET
    ELSE
    SELLSHORT 1 SHARES AT MARKET
    ENDIF
    ENDIF
    
    
    if val<0 and val>val[1] then
    IF SHORTONMARKET THEN
    EXITSHORT 1 SHARES AT MARKET
    BUY 1 SHARES AT MARKET
    ELSE
    BUY 1 SHARES AT MARKET
    
    ENDIF
    ENDIF
    
    
    StopdistanceBreakeven = c
    NormalStop = sl
    
    nb = barindex - tradeindex
    minprice = lowest[nb + 1](Low)
    maxprice = highest[nb + 1](High)
    
    If longonmarket then
    If maxprice >= positionprice + StopdistanceBreakeven then
    sell at (positionprice + 1) stop
    else
    sell at positionprice - NormalStop stop
    endif
    endif
    
    If shortonmarket then
    If minprice <= positionprice - StopdistanceBreakeven then
    exitshort at (positionprice - 1) stop
    else
    exitshort at positionprice + NormalStop stop
    endif
    endif
    // stop and profit
    //SET STOP pLOSS sl
    SET TARGET pPROFIT tp
     
    ENDIF
    

    My guess is I should define what is yellow and dark blue (this I think I can do) and then buy/sell on the change of color (this I have no idea, how do you say “buy if red then yellow ???)

    Can you help ?

    Also, when I do the backtest, I have MFE and MAE in the closed positions toggle, which one should I trust ? (Cause I like MAE 🙂 )

    Should I do a “e-ratio” like I read somewhere on the internet ?

    Squeeze.png Squeeze.png
    #65961 quote
    GraHal
    Participant
    Master

    Also, when I do the backtest, I have MFE and MAE in the closed positions toggle, which one should I trust ? (Cause I like MAE )

    Glad you got back safe, shouldn’t you have been sleeping at 4:30 AM? 🙂

    My brain has not woken enough yet re most of the questions, but MFE is Max Profit and MAE is Max Loss during that trade.

    I check these and if a Strategy shows big MAE and then eventually a small MFE for lots of individual trades then I consider the Strat not good (even if overall a good profit shows). Reason: it would mean I’ve been sitting there stressing while the trade has had big drawdowns! Okay eventually it managed repeatedly to hitch-hike onto a favourable trend and come out smelling of roses / profit in the end, but the journey was tiring … just like yours from Berlin to Paris! 🙂

    Cheers
    GraHal
    PS I drew same conclusion as you re your original Strat, but I didn’t like to say.
    Thank you for your sterling effort through the night on the new version Strat, I will test it out later.

Viewing 15 posts - 1 through 15 (of 46 total)
  • You must be logged in to reply to this topic.

Trend surfer DAX modified


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
irioton @irioton Participant
Summary

This topic contains 45 replies,
has 6 voices, and was last updated by irioton
7 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/19/2018
Status: Active
Attachments: 27 files
Logo Logo
Loading...