Linear Regression Universal Strategy, how to improve it?

Forums ProRealTime English forum ProOrder support Linear Regression Universal Strategy, how to improve it?

Viewing 15 posts - 1 through 15 (of 33 total)
  • #199478

    Hello everyone! I am new and very impressed by the great potential of Prorealtime in following the market automatically. I am writing a thesis on trading systems. So I would like to share this strategy to improve and experiment with new solutions together.

    It is a very simple strategy with stop orders that uses two linear regressions, as entry and exit signals from both long and short, and the Historical volatility indicator to dynamically manage the period of linear regressions.
    It works if optimized, on different currency pairs, (I tried it on AUDUSD, EURUSD, GBPUSD, CNHJPY, and potentially on all currency pairs)
    I advise you to improve it on CNHJPY to get low drawdowns and given the possibility of testing it live with a low initial capital (margin = $ 80).

    I’d like to add a machine learning feature to optimize the only three variables automatically.

    Thanks to anyone who wants to help me.

     

    #199505

    Looks good!

    0.7 spread is shown at Line 5, isn’t the spread on CNHJPY 1.8 pips / 180 Yen?

    I optimised and set it going on Demo Live, but it keep getting Rejected due to ‘not enough data to calculate etc’.  I added ‘Defparam PreLoad bars = 10,000’, but still keeps getting Rejected for same reason.

    Any thoughts?

    #199528

    How would you like them to be optimized at runtime?

     

    #199553
    JS

    I get strange results when I optimize the system.

    For all optimization parameters I get the same positive result equal to the graph of davidelaferla.

    If I keep the spread below 1 then the system is positive, if you get 0.1 point above 1 then the positive result suddenly turns into negative result.

    During the optimization, the parameter Regression2period is also not optimized, setting is optimization from 1 to 2 step 0.1 but the parameter remains at 1?

    #199555
    JS

    Hi @GraHal

    I also started the system today in Demo and it does start without error message…

    Remains special that different behaviour in error messages…

     

    #199556

    What Timeframe you running on? If Daily then you may get the error message tomorrow?

    I was running on 2 min TF, and although the System started okay, at the ‘first changeover of full 2 min’ I got the error message!

    I spent a few hours on it trying everything!! Narrowed it down eventually to the ’round’ function. I replaced with ‘ceil’ but got a Rejection after maybe an hour or so; ‘floor’ lasted a few hours but then also was Rejected.

    I have one version running since yesterday with no Rejections, but I had to remove ’round’ altogether!

    I feel there should be a successful Algo in there somewhere?

    EDIT / PS

    Ceil and Floor together (somehow?) may work as then the value would be rounded from above and below?

    #199558
    JS

    I do use a time frame of a day so the error message will still come…

    As you probably know, it uses the ’round’ function because the number, which refers to the period, must be an integer… (and positive)

    Very special that you do not get an error message on this …

    Strange things are happening here, but I don’t know yet what it’s about…

    #199560
    JS

    Do you have no problems with the optimization?

    When I optimize the system, all optimization parameters give the same (positive) result…

    #199566

    Try setting up on 1 min or 2 mins TF then you can see if you get Rejected as you only have to wait 1 or 2 mins.

    Also the opti may work better? ( I do recall strange happenings trying to recreate David’s results). 

    I rarely do 1 day TF hence me setting up on M2, also mine is running on DJI.

    #199569
    JS

    I now have the system running in Demo on a time frame of two minutes and I do indeed get the same error message about “too little historical data to be able to calculate…”??

    What a waste of time…

     

    1 user thanked author for this post.
    #199577

    Hi guys,

    I’ve slightly modified this code and since yesterday it’s running in demo without problems. I’m running it with MTF with 5M as basic TF. See below. Any comment is really appreciated. I’ve also added +/- contracts based on profit.

    //Linear Regression Universal Strategy
    // instrument: VALUTE
    // timeframe : Daily
    // created and coded by davidelaferla

    DEFPARAM CUMULATEORDERS =FALSE
    DEFPARAM FLATBEFORE=080000
    DEFPARAM FLATAFTER=220000

    timeframe (default)

    //////////////////////// Q.TY CONTRACTS
    MS=1
    ONCE LongProfit = 0
    ONCE ShortProfit = 0
    IF StrategyProfit <> StrategyProfit[1] AND BarIndex > 0 THEN
    Profitto = StrategyProfit – StrategyProfit[1]
    IF LongOnMarket[1] THEN
    LongProfit = LongProfit + Profitto
    ELSIF ShortOnMarket[1] THEN
    ShortProfit = ShortProfit + Profitto
    ELSE
    p1 = 1
    p2 = 2
    IF OnMarket THEN
    p1 = 2
    p2 = 3
    ENDIF
    IF TradePrice(p1) > TradePrice(p2) THEN
    IF Profitto > 0 THEN
    LongProfit = LongProfit + Profitto
    ELSE
    ShortProfit = ShortProfit + Profitto
    ENDIF
    ELSIF TradePrice(p1) < TradePrice(p2) THEN
    IF Profitto < 0 THEN
    LongProfit = LongProfit + Profitto
    ELSE
    ShortProfit = ShortProfit + Profitto
    ENDIF
    ELSE
    LongProfit = LongProfit + (Profitto / 2)
    ShortProfit = ShortProfit + (Profitto / 2)
    ENDIF
    ENDIF
    ENDIF

    /////////////////// for LONG trades
    once LotSizeL = 1
    Once MinSizeL = 1 //minimum size required
    Once LotSizeL = MinSizeL //starting size (can be bigger than minimum)
    Once LotStepL = LL200 //250 //increase/decrease this money step
    LotSizeL = max(MinSizeL,round((MinSizeL/MS),1) + (MinSizeL * round((LongProfit / LotStepL),1)))
    if LotSizeL>MU then
    LotSizeL=MU-MMUU
    endif
    myLotL=LotSizeL

    ///////////////////// for SHORT trades
    once LotSizeS = 1
    Once MinSizeS = 1 //minimum size required
    Once LotSizeS = MinSizeS //starting size (can be bigger than minimum)
    Once LotStepS = LS200 //250 //increase/decrease this money step
    LotSizeS = max(MinSizeS,round((MinSizeS/MS),1) + (MinSizeS * round((ShortProfit / LotStepS),1)))
    if LotSizeS>MU then
    LotSizeS=MU-MMUU
    endif
    myLotS=LotSizeS
    //////////////////////////////////// END

    timeframe (daily,default)

    //myLot= 1

    Volatilityperiod=V15// different fixed value for each currency pair: range=3-20, with step=1
    Regression1period=R18// Linear Regression Imput Signal: range=6-100 with step=1
    Regression2period=RR //1.3//Linear Regression Output Signal: range=1-2, with step=0.01

    hv=HistoricVolatility[VolatilityPeriod](close)
    hv2=HistoricVolatility[VolatilityPeriod](typicalprice)
    st=linearregression[ROUND(Regression1Period*hv)](close)
    lr=linearregression[ROUND(Regression1Period*Regression2Period*hv2)](typicalprice)

    timeframe (60 minutes,default)

    // Condizioni per uscire da posizioni short e entrare su posizioni long
    IF NOT LONGONMARKET and st<lr and hour=>H1 and hour<=H2 THEN
    exitshort myLotS contract at market
    BUY myLotL contract AT lr stop
    set stop ploss SL/myLotL*CX
    set target pprofit TP
    ENDIF
    // Condizioni per uscire da posizioni long e entrare su posizioni short
    IF NOT SHORTONMARKET and st>lr and hour=>H1 and hour<=H2 THEN
    sell myLotL contract at market
    SELLshort myLotS contract At st stop
    set stop ploss SLS/myLotS*CX
    set target pprofit TPS
    ENDIF

    timeframe (default)

     

    1 user thanked author for this post.
    #199579

    Sorry I forgot to say that now it’s running on Eu/$ ’cause Davide wrote that has to be used for Forex and not indexes

    #199587

    MaoRai54 please might you post the .itf and then we will have all the same variables as you so we can compare results etc?

    Sharing feels good, like old times … before MarketPlace? 🙂

    #199589

    Grahal, see attachment !!

    1 user thanked author for this post.
    #199618

    Hi guys! I’m really glad you like it. I gave you a basis, now it would be really wonderful to implement it, that is, make it easy to optimize and create a database for each index with the fixed variable that is volatility. How can I help you?

Viewing 15 posts - 1 through 15 (of 33 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login