Strategy MAEX – experiment with MFE & MAE

Viewing 15 posts - 46 through 60 (of 83 total)
  • Author
    Posts
  • #158345 quote
    nonetheless
    Participant
    Master

    Anyone else get the dreaded div by zero for this? Apart from the indicators, the only lines I can see with division by anything are

    averecentmael=close-(maerec/nn)
    averecentmfel=close+(mferec/nn)
    
    averecentmaes=close+(maerec/n)
    averecentmfes=close-(mferec/n)

    but n and nn have permanent values.

    🤔🤔🤔???

    #158368 quote
    Paul
    Participant
    Master

    always that error!

    It’s either in that section or in the vectorial part.

    How about adding before

    if range[0]>0 and range[1]>0 and range[2]>0 and range[3]>0 and range[4]>0 and range[5]>0 then

    maybe up to 8/9/10, to include vectorial. Not very nice but it makes sure when the calculation starts every bar has a range.

    Otherwise use min(x,x) for certain parts?

    #158370 quote
    nonetheless
    Participant
    Master

    So, where would i add that line exactly? at the top of the //mfe & mae section?

    #158408 quote
    Paul
    Participant
    Master

    Something like this,

    I thought I tried it in the past and in that situation it didn’t work, but I’ve got no other solution.

    vectorial seems ok and also Stochastic RSI

    ps you get check the time of the error and see if in the chart test=1

    TIMEFRAME(default)
    // mfe & mae
    
    if range[0]>0 and range[1]>0 and range[2]>0 and range[3]>0 and range[4]>0 then
    
    n = 4
    nn= 1
    
    if method=1 then
    
    maerec=0
    mferec=0
    
    for i=1 to n
    maerec=maerec+(high[i]-open[i])
    mferec=mferec+(open[i]-low[i])
    next
    
    for j=1 to nn
    maerec=maerec+(open[j]-low[j])
    mferec=mferec+(high[j]-open[j])
    next
    
    averecentmael=close-(maerec/nn)
    averecentmfel=close+(mferec/nn)
    
    averecentmaes=close+(maerec/n)
    averecentmfes=close-(mferec/n)
    
    avgl=(averecentmael+averecentmfel)/2
    avgs=(averecentmaes+averecentmfes)/2
    
    elsif method=2 then
    maerec=0
    mferec=0
    maerec2=0
    mferec2=0
    
    for i=1 to n
    maerec=maerec+(high[i]-open[i])
    mferec=mferec+(open[i]-low[i])
    next
    
    for j=1 to nn
    maerec2=maerec2+(open[j]-low[j])
    mferec2=mferec2+(high[j]-open[j])
    next
    
    averecentmael=close-(maerec2/nn)
    averecentmfel=close+(mferec2/nn)
    
    averecentmaes=close+(maerec/n)
    averecentmfes=close-(mferec/n)
    
    avgl=(averecentmael+averecentmfel)
    avgs=(averecentmaes+averecentmfes)
    endif
    endif
    
    if range[0]=0 or range[1]=0 or range[2]=0 or range[3]=0 or range[4]=0 then
    test=1
    else
    test=0
    endif
    
    graph test
    
    #158448 quote
    Tanou
    Participant
    Senior

    Hi guys!

     

    What is this error? I dn’t see it when I backtest! How does it affects the code?

    #158458 quote
    nonetheless
    Participant
    Master

    it doesn’t show up in backtest, that is what’s so infuriating. Just when you think you’ve done the hard work and everything is sweet, you launch it but it wont run live because ‘division by zero’. They don’t tell you where the problem is and it’s almost never apparent in the code because the values are changing all the time. Try doing a search, there’s dozens of threads on the subject but I don’t think anyone’s found a cure.

    For me it is definitely worse in v11. Algos that ran fine in 10.3 are now getting stopped for this regularly.

    #158473 quote
    Monobrow
    Participant
    Senior

    Yeah, ive had a bunch of div 0 and similar errors recently. Very frustrating but a bit of hard work and help from the forum has solved them all.

    Fact is there will be something attempting to div/0 and a well placed MAX(<something above zero that doesn’t break your system>, <offending code>) will fix most of them.

    graph all your variables/returning values,  find the zero and it should be possible to fix.

    You can also try using If variable <> 0 then <do dodgy code>  Endifs also.

    its a pain but it is what it is.

    #158513 quote
    Paul
    Participant
    Master

    I don’t think it’s the solution above/below works though in my post, because it only  solves to have a value before dividing it. And the error appears to be the other way around.

    Problem is a zero is never used as far I can tell.

    Anyway another way to have it programmed, instead testing and coding each bar individually, like this below. Should only take trades if the last xx bars have range and not have open=close=high=low.

     

    // mfe & mae
    
    count = 0
    For zz = 1 to xx do
    IF range[zz]=0 THEN
    count= 1
    ENDIF
    next
    
    if count=0 then
    
    n = 4
    nn= 1

    wild guess, but what if with live data feed i.e. there’s no tick/bar data is not the same as the backtest data?

    Something like backtestdata has open=low=high=close and running live the bar is simply skipped or the other way around.

    Maybe such bar is processed another way but not visible and maybe the error is broader then the error message itself gives indication.

    #158522 quote
    nonetheless
    Participant
    Master

    Thanks Paul, I’ll try that and see if it runs 🤞

    #158536 quote
    Tanou
    Participant
    Senior

    @nonetheless, can you please upload a .itf file? As I don’t see the error I’d like to see what’s the difference… thanks 😉

    #158539 quote
    nonetheless
    Participant
    Master
    #158551 quote
    Tanou
    Participant
    Senior

    Have you change something regarding the previous version? I don’t see any changes!

    #158553 quote
    nonetheless
    Participant
    Master

    at the moment I have it in demo with Paul’s suggestion above but hasn’t taken a trade yet. When you say, ‘I don’t see the error’, do you mean you dont get division by zero rejection?

    #158558 quote
    Tanou
    Participant
    Senior

    Yes exactly! Can you upload the version with the implementation of Paul’s suggestion?

    #158559 quote
    nonetheless
    Participant
    Master

    it’s in my demo account that’s not open just now. but it’s exactly the same as v4.5 atr but add

    count = 0
    For zz = 1 to 5 do
    IF range[zz]=0 THEN
    count= 1
    ENDIF
    next
     
    if count=0 then

    under the // mfe & mae section, with another endif at the bottom. There’s no other changes.

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

Strategy MAEX – experiment with MFE & MAE


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Paul @micky75d Participant
Summary

This topic contains 82 replies,
has 14 voices, and was last updated by Meta Signals Pro
2 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/26/2020
Status: Active
Attachments: 37 files
Logo Logo
Loading...