Basic coding question

Viewing 15 posts - 16 through 30 (of 31 total)
  • Author
    Posts
  • #36829 quote
    GraHal
    Participant
    Master

    What results did you get … post a screenshot (like mine above) that shows what  timeframe and instrument you are working on?

    #36840 quote
    BC
    Participant
    Master

    HiGrahal

    I test it with DAX 1 hr.

    Big3-DAX.png Big3-DAX.png
    #36845 quote
    GraHal
    Participant
    Master

    Bin, use GRAPH as  below and you will see your StopLossLong never triggers.

    GRAPH Close = StopLossLong

    Substitute actual numbers from a bar and you will see why …

    StopLossLong(68) = BuyPrice (12637) - SMA (12569)

    But nonetheless the code shows profit … well done! Most be room for tweaking / more profit?

    GraHal

    #36847 quote
    Francesco78
    Participant
    Master

    Guys can you please post the code relative to Bin’s picture in attachment? I’m trying to replicate the results before working on it.

    Thank you

    Francesco

    #36851 quote
    GraHal
    Participant
    Master

    Forgive me @Bin, what I said in  #36845 re Stop Loss not triggering was incorrect … I need to concentrate and not have one eye on the TV! 🙁

    Thanks Francesco78, I can’t replicate Bin’s results either with code on this Thread.

    I tried to optimise 4 variables for 5m and 15m (not good) and settled on attached for  Dax @ 30M. Results over 100,000 bars attached and .itf attached with  4 variables in the Optimiser.

     

    //defparam preloadbars = 3000
    defparam cumulateorders =false //true //false
     
    //Big Three MA
    FMA=Average[f](close) //green coloured(0,255,0)
    MMA=Average[m](close)//blue coloured(0,0,255)
    SMA=Average[s](close)//red coloured(255,0,0)
     
    //High Low Bar Setting
    CP=cp
     
     
    //Buy Signal
    B1=low > SMA and low>MMA and low>FMA
    B2=high >= highest[CP](high)
    BC=B1 and B2
     
    //Buy Candle
    BC1 = Close[1] < Close[2]
    BC2 = Close > Close[1]
    BC3 = Close > Open
    BCandle = BC1 and BC2 and BC3
     
    //Sell Signal
    S1=high < FMA and high<MMA and high<SMA
    S2=low <= lowest[CP](low)
    SC=S1 and S2
     
    //Sell Caandle
    SC1 = Close[1] > Close[2]
    SC2 = Close < Close[1]
    SC3 = Close < Open
    SCandle = SC1 and SC2 and SC3
     
     
    //Long Entry
    if BC and BCandle then
    BUY 1 CONTRACT AT MARKET
    BuyPrice=Close
    StopLossLong = BuyPrice - SMA
    endif
     
    //Long Exit
    if LongonMarket and close crosses under SMA then
    sell at market
    endif
     
    //short entry
    if SC and SCandle then
    //SELLSHORT min(25,PositionSizeShort) CONTRACT AT MARKET
    SELLSHORT 1 CONTRACT AT MARKET
    SellPrice=Close
    StopLossShort=SMA-SellPrice
    //takeProfit = takeProfitShort
    endif
     
    //Short Exit
    if ShortonMarket and close crosses over SMA then
    exitshort at market
    endif
     
     
    // Stop Loss
    if LongonMarket then
    SET STOP LOSS StopLossLong
    endif
     
    if ShortonMarket then
    SET STOP LOSS StopLossShort
    endif
     
    //graph SMA
    //graph Tradeprice
    //graph StopLossLong
    //graph StopLossShort
    
    Francesco78 thanked this post
    Bin3.jpg Bin3.jpg Bin-Croc-DAX-30M.itf
    #36854 quote
    BC
    Participant
    Master

    Sorry Grahal, , I forgot post the updated version with target profit and limited the loss. My bad.

    defparam preloadbars = 3000
    defparam cumulateorders =false 
    
    //Big Three MA
    FMA=Average[20](close) //green  coloured(0,255,0)
    MMA=Average[40](close) //blue  coloured(0,0,255)
    SMA=Average[80](close) //red  coloured(255,0,0)
    
    //High Low Bar Setting
    CP=3
    
    
    //Buy Signal
    B1=low > SMA and low>MMA and low>FMA
    B2=high >= highest[CP](high)
    BC=B1 and B2
    
    //Buy Candle
    BC1 = Close[1] < Close[2]
    BC2 = Close > Close[1]
    BC3 = Close > Open
    BCandle = BC1 and BC2 and BC3
    
    //Sell Signal
    S1=high < FMA and high<MMA and high<SMA
    S2=low <= lowest[CP](low)
    SC=S1 and S2
    
    //Sell Candle
    SC1 = Close[1] > Close[2]
    SC2 = Close < Close[1]
    SC3 = Close < Open
    SCandle = SC1 and SC2 and SC3
    
    //Long Entry
    if BC and BCandle then
    //BUY min(25,PositionSizeLong) CONTRACT AT MARKET
    BUY 1 CONTRACT AT MARKET
    BuyPrice=Close
    StopLossLong = MIN(100,MAX(30,(BuyPrice - SMA))) //100, 30
    TakeProfitLong = StopLossLong * 4.5 //1-5
    StopLoss = StopLossLong
    TakeProfit = TakeProfitLong
    endif
    
    //Long Exit
    if LongonMarket and close crosses under SMA then
    sell at market
    endif
    
    //short entry
    if SC and SCandle then
    //SELLSHORT min(25,PositionSizeShort) CONTRACT AT MARKET
    SELLSHORT 1 CONTRACT AT MARKET
    SellPrice=Close
    StopLossShort = MIN(60,MAX(10,(SMA - SellPrice))) //60, 10
    TakeProfitShort = StopLossShort * 2.5 //1-5
    StopLoss = StopLossShort
    TakeProfit = TakeProfitShort
    endif
    
    //Short Exit
    if ShortonMarket and close crosses over SMA then
    exitshort at market
    endif
    
    // Stop Loss
    SET STOP LOSS StopLoss
    
    //Target Profit
    SET TARGET PROFIT TakeProfit
    
    graph BuyPrice
    graph SellPrice
    graph StopLossLong
    graph StopLossShort
    
    GraHal and Francesco78 thanked this post
    #36886 quote
    Francesco78
    Participant
    Master

    Thanks, on the 1 hour and 30minutes TF is pretty nice.

    have you run WF yet?

    #36926 quote
    BC
    Participant
    Master

    Hi Francesco

    A modified version with WF result attached.

    defparam preloadbars = 3000
    defparam cumulateorders =false //true  //false
    
    //Big Three MA
    FMA=Average[20](close) //green  coloured(0,255,0)
    MMA=Average[40](close)//blue  coloured(0,0,255)
    SMA=Average[80](close)//red  coloured(255,0,0)
    
    //High Low Bar Setting
    CP=3
    
    // Money Management
    Capital = 2000
    //Risk = 5 //in %
    MaxD = 50
    equity = Capital + StrategyProfit
    
    //Time Management
    ONCE maxCandlesLongWithoutProfit = 62  // 46,  62
    ONCE maxCandlesShortWithoutProfit = 72  // 46,  72
    
    //Check system account balance
    if equity<QuickLevel then
    quit
    endif
    recordhighest = MAX(recordhighest,equity)
    QuickLevel = recordhighest*((100-MaxD)/100)
    
    //Buy Signal
    B1=low > SMA and low>MMA and low>FMA
    B2=high >= highest[CP](high)
    BC=B1 and B2
    
    //Buy Candle
    BC1 = Close[1] < Close[2]
    BC2 = Close > Close[1]
    BC3 = Close > Open
    BCandle = BC1 and BC2 and BC3
    
    //Sell Signal
    S1=high < FMA and high<MMA and high<SMA
    S2=low <= lowest[CP](low)
    SC=S1 and S2
    
    //Sell Caandle
    SC1 = Close[1] > Close[2]
    SC2 = Close < Close[1]
    SC3 = Close < Open
    SCandle = SC1 and SC2 and SC3
    
    
    //Long Entry
    if BC and BCandle then
    BUY 1 CONTRACT AT MARKET
    BuyPrice=Close
    StopLossLong = MIN(100,MAX(30,(BuyPrice - SMA))) //100, 30
    TakeProfitLong = StopLossLong * 4.5 //1-5
    StopLoss = StopLossLong
    TakeProfit = TakeProfitLong
    endif
    
    //Long Exit
    if LongonMarket and close crosses under SMA then
    sell at market
    endif
    
    //short entry
    if SC and SCandle then
    SELLSHORT 1 CONTRACT AT MARKET
    SellPrice=Close
    StopLossShort = MIN(60,MAX(10,(SMA - SellPrice))) //60, 10
    TakeProfitShort = StopLossShort * 2.5 //1-5
    StopLoss = StopLossShort
    TakeProfit = TakeProfitShort
    endif
    
    //Short Exit
    if ShortonMarket and close crosses over SMA then
    exitshort at market
    endif
    
    // stop and profit management
    IF LONGONMARKET THEN
    posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
    ELSIF SHORTONMARKET THEN
    posProfit = (((positionprice - close) * pointvalue) * countofposition) / pipsize
    ENDIF
    
    //Time Exit
    m3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfit
    m4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit
    
    IF LONGONMARKET AND m3 THEN
    SELL AT MARKET
    ENDIF
    
    IF SHORTONMARKET AND m4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    
    //Stop Loss
    SET STOP LOSS StopLoss
    
    //Target Profit
    SET TARGET PROFIT TakeProfit
    Big3-DAX-CL.png Big3-DAX-CL.png Big3-DAX-CL-WF.png Big3-DAX-CL-WF.png Big3-V2-DAX.itf
    #36930 quote
    Francesco78
    Participant
    Master

    looks really good, thanks a lot, any idea if it can be adapted to other markets?

    what are the variables you have optimized for the WF if I may ask?

    #36937 quote
    BC
    Participant
    Master

    I keep the original idea which using 20, 40, 80 MA and only add the highest/lowest filter and tested with Hang Seng (12.6 spread)and DAX (2.9 spread) only, HS not good because the high spread.

    WF only check quit level, I think can take a test on Max stop loss and target profit.

    #36938 quote
    Francesco78
    Participant
    Master

    Thanks, I think

    CP and

    maxCandlesLongWithoutProfit

    maxCandlesShortWithoutProfit
    should be subjected to backtest.
    Will try tomorrow
    #36944 quote
    BC
    Participant
    Master

    Hi Francesco

    Yes, you are right.

    #36984 quote
    BC
    Participant
    Master

    I try DJI 30m, 1 hr, 4 hr with fixed MA and CP only but no luck, may be this Big3 idea not soild enough.

    Francesco78 thanked this post
    #36999 quote
    GraHal
    Participant
    Master

    Bin why are you not optimising the MA and CP … every market is different in volatility and cycles etc and you / we can check how robust an optimised set of variables (including MA & CP) are by using the Walk Forward  tool?

    #37004 quote
    Francesco78
    Participant
    Master

    I think CP was optimized, I tried myself..

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

Basic coding question


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
BC @robin_chan Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/25/2017
Status: Active
Attachments: 8 files
Logo Logo
Loading...