IchimokuDM Strategy on SAF40

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #37795 quote
    juanj
    Participant
    Master

    Okay so I wrote this strategy today after studying some Ichimoku Trading Stategies.

    It is mainly based around Ichimoku breakout strategy but also includes checks for Directional Movement and Divergence.

    I wrote it for my local market (South Africa 40 Cash) on the 1Hr Timeframe on which it performs okay, which is no mean feat.

    But to be completely honest i am disappointed with Ichimoku as an automated strategy in general.

    But enough mumbling. Here is the code, maybe someone will find it useful.

    //Stategy: IchimokuDM
    //Market: South Africa 40 Cash (ZAR2 Micro)
    //Timeframe: 1Hr
    //Spread: 15
    //Timezone: UTC +2
    
    Defparam Cumulateorders = False
    Defparam Flatbefore = 090000
    Defparam Flatafter = 170000
    
    If hour < 9 or hour > 17 then //Works in conjunction with Flat Before/After time
    possize = 0
    If longonmarket then
    SELL AT MARKET
    ElsIf shortonmarket then
    EXITSHORT AT MARKET
    EndIf
    Else
    possize = 2 //Minimum position size
    EndIf
    
    P = 11 //Standard Period
    R = P*2 //Standard Period x 2
    I = P*3 //Standard Period x 3
    TS = (highest[P](high)+lowest[P](low))/2 //Tenkan-Sen
    KS = (highest[I](high)+lowest[I](low))/2 //Kijun-Sen
    CS = close[I] //Chikou-Span
    SA = (TS+KS)/2 //Senkou-Span A
    SB = (highest[I](high)+lowest[I](low))/2 //Senkou-Span B
    DP = DIplus[R](close) //DI+
    DN = DIminus[R](close) //DI-
    AX = ADX[R] //ADX
    ATR = AverageTrueRange[P](close)
    
    If RSI[R](close) > RSI[R](close[I]) Then
    If close < CS Then
    BDIV = 1 //Buy Divergence Present
    SDIV = 0
    EndIf
    EndIf
    
    If RSI[R](close) < RSI[R](close[I]) Then
    If close > CS Then
    BDIV = 0 //Sell Divergence Present
    SDIV = 1
    EndIf
    EndIf
    
    
    If countofposition = 0 and BDIV = 1 and AX > 17 and DP > 20 and DP > DN and close > SA and close > SB and TS > KS and close > CS and Close > SA[I] and Close > SB[I] Then
    Buy possize*3 contracts at close + ATR stop
    EndIf
    
    If countofposition = 0 and SDIV = 1 and AX > 17 and DN > 20 and DP < DN and close < SA and close < SB and TS < KS and close < CS and Close < SA[I] and Close < SB[I] Then
    Sellshort possize*3 contracts at close - ATR stop
    EndIf
    
    If Longonmarket then
    If close < TS Then
    Sell possize contracts at Market //Exit third of position at close below Tenkan-Sen Line
    ElsIf close < TS and close < KS Then
    Sell possize contracts at Market //Exit third of position at close below Kijun-Sen Line
    ElsIf close < TS and close < KS and close < SA or close < SB Then
    Sell at market //Exit full position at close below Senkou-Span
    EndIf
    ElsIf Shortonmarket then
    If close > TS Then
    Exitshort possize contracts at Market //Exit third of position at close below Tenkan-Sen Line
    ElsIf close > TS and close > KS Then
    Exitshort possize contracts at Market //Exit third of position at close above Kijun-Sen Line
    ElsIf close > TS and close > KS and close > SA or close > SB Then
    Exitshort at market //Exit full position at close above Senkou-Span
    EndIf
    EndIf
    
    Set Stop pLOSS ATR*4
    Set Target pPROFIT ATR*5
    Francesco78 thanked this post
    ichimokudm-1496845809lcp841.jpg ichimokudm-1496845809lcp841.jpg
    #37798 quote
    Nicolas
    Keymaster
    Master

    Thanks for this automatic trading strategy code. It seems to work fine on backtests, though I moved your post to the forum instead of the library, because ProOrder don’t support yet partial closure of positions and that’s what your strategy does between lines 58 to 74. I hope this will be available one day, but actually this strategy could only work in paper trading / backtest, not in real trading environment under ProOrder..Sorry for that 😐

    #37840 quote
    juanj
    Participant
    Master

    Hi Nicolas

    Yes it is unfortunate about ProOrder not supporting close of partial positions, however replacing lines 58 to 74 with the below code yields a very similar result to above without having to use partial position closing. So what about we modify the code and move it to the library in order for a bigger audience to benefit?

    If Longonmarket then
    If close < TS Then //If close below Tenkan-Sen Line
    If close < close[1] Then
    Sell at Market //Close position at next lower close
    EndIf
    EndIf
    ElsIf Shortonmarket then
    If close > TS Then //If close below Tenkan-Sen Line
    If close > close[1] Then
    Exitshort at Market //Close position at next higher close
    EndIf
    EndIf
    EndIf
    #37849 quote
    Nicolas
    Keymaster
    Master

    Great! I do not have much time now, but I’ll have a look tomorrow. Thanks juanj! 😉

    #37864 quote
    Nicolas
    Keymaster
    Master

    So here is the modified code with your last addition:

    //Stategy: IchimokuDM
    //Market: South Africa 40 Cash (ZAR2 Micro)
    //Timeframe: 1Hr
    //Spread: 15
    //Timezone: UTC +2
    
    Defparam Cumulateorders = False
    Defparam Flatbefore = 073000
    Defparam Flatafter = 163000
    
    If hour < 9 or hour > 17 then //Works in conjunction with Flat Before/After time
    possize = 0
    If longonmarket then
    SELL AT MARKET
    ElsIf shortonmarket then
    EXITSHORT AT MARKET
    EndIf
    Else
    possize = 2 //Minimum position size
    EndIf
    
    P = 11 //Standard Period
    R = P*2 //Standard Period x 2
    I = P*3 //Standard Period x 3
    TS = (highest[P](high)+lowest[P](low))/2 //Tenkan-Sen
    KS = (highest[I](high)+lowest[I](low))/2 //Kijun-Sen
    CS = close[I] //Chikou-Span
    SA = (TS+KS)/2 //Senkou-Span A
    SB = (highest[I](high)+lowest[I](low))/2 //Senkou-Span B
    DP = DIplus[R](close) //DI+
    DN = DIminus[R](close) //DI-
    AX = ADX[R] //ADX
    ATR = AverageTrueRange[P](close)
    
    If RSI[R](close) > RSI[R](close[I]) Then
    If close < CS Then
    BDIV = 1 //Buy Divergence Present
    SDIV = 0
    EndIf
    EndIf
    
    If RSI[R](close) < RSI[R](close[I]) Then
    If close > CS Then
    BDIV = 0 //Sell Divergence Present
    SDIV = 1
    EndIf
    EndIf
    
    
    If countofposition = 0 and BDIV = 1 and AX > 17 and DP > 20 and DP > DN and close > SA and close > SB and TS > KS and close > CS and Close > SA[I] and Close > SB[I] Then
    Buy possize*3 contracts at close + ATR stop
    EndIf
    
    If countofposition = 0 and SDIV = 1 and AX > 17 and DN > 20 and DP < DN and close < SA and close < SB and TS < KS and close < CS and Close < SA[I] and Close < SB[I] Then
    Sellshort possize*3 contracts at close - ATR stop
    EndIf
    
    If Longonmarket then
    If close < TS Then //If close below Tenkan-Sen Line
    If close < close[1] Then
    Sell at Market //Close position at next lower close
    EndIf
    EndIf
    ElsIf Shortonmarket then
    If close > TS Then //If close below Tenkan-Sen Line
    If close > close[1] Then
    Exitshort at Market //Close position at next higher close
    EndIf
    EndIf
    EndIf
    
    Set Stop pLOSS ATR*4
    Set Target pPROFIT ATR*5
    

    I changed the time schedule between 07.30-16.30 for the intraday 8 points spread. Results attached, please confirm before I add it into the library! thanks.

    Francesco78 thanked this post
    SAF40-automatic-trading-strategy.png SAF40-automatic-trading-strategy.png
    #37870 quote
    juanj
    Participant
    Master

    Hi Nicholas, the results seem valid. I don’t have the amount of data points you have so mine will look slightly different. Pleased to see it still performs on par in the period outside of my optimization time frame. This actually serves as validation of the strategy.

    #37891 quote
    Nicolas
    Keymaster
    Master
    #37907 quote
    Maz
    Participant
    Veteran

    Nice idea, will take a look and post any updates.

    Yea, bit of a pain with the lack of partial closures, bi-directional trading and stuff- but as quick proof of concept it’s useful.

    Just for future reference guys, if you are dependent on abilities such as to execute partial closures and wish to run with such features, I could actually make that happen for you using our own tools. Wouldn’t normally disclose the screen shots attached but I think there’s some good ideas and thinking out here that is out-growing PRT.  (attached is monitoring views from our system)

    Best,

    M

    Francesco78 thanked this post
    bot-monitor.png bot-monitor.png bot-monitor-2.png bot-monitor-2.png
    #37917 quote
    juanj
    Participant
    Master

    @Maz, regarding your screenshots, what are we looking at???

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

IchimokuDM Strategy on SAF40


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by juanj
8 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/08/2017
Status: Active
Attachments: 4 files
Logo Logo
Loading...