Error with historical data

Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #146062 quote
    robertogozzi
    Moderator
    Master

    The issue seems to happen only on TF involving seconds (1 or 10-second TF’s), probably because in a day there are more than 10000 bars of 1 seconds, so it cannot calculate correctly something.

    It doesn’t occur on 1-minute TF and greater.

    #146064 quote
    Tanou
    Participant
    Senior

    But if I launch it today, the today’s daily pp won’t be good but would it be good from tomorrow as the system would be running?

     

    Otherwise do you have any other suggestions?

     

    Thanks!

    #146066 quote
    robertogozzi
    Moderator
    Master

    It’s weird that if a day has more than 10K bars, why does the code suggested by Nicolas work:

    DEFPARAM PRELOADBARS = 3000
    DEFPARAM CumulateOrders = False
    Ht = DHigh(1)
    Bs = DLow(1)
    C = DClose(1)
    Pivot = (Ht + Bs + C) / 3
    buy at -Pivot LIMIT

    ?

    It shouldn’t because it needs more than 10K 1-second bars to compute the Daily PIVOT!

    #146067 quote
    Tanou
    Participant
    Senior

    I’m in 10 seconds and not 1 second. With this code I get a daily pp at 12787 instead of 12770,6 in real

    #146070 quote
    Nicolas
    Keymaster
    Master

    Try with:

    IF openday<>openday[1] THEN
     PlusHaut = High
     PlusBas = Low
     PP = (PlusHaut[1] + PlusBas[1] + Close[1]) / 3
     Premierpassage=0
    ELSE
     PlusHaut = Max(High,PlusHaut[1])
     PlusBas = Min(Low,PlusBas[1]) 
    ENDIF

    or

    IF intradaybarindex=0 THEN
     PlusHaut = High
     PlusBas = Low
     PP = (PlusHaut[1] + PlusBas[1] + Close[1]) / 3
     Premierpassage=0
    ELSE
     PlusHaut = Max(High,PlusHaut[1])
     PlusBas = Min(Low,PlusBas[1]) 
    ENDIF
    #146080 quote
    Tanou
    Participant
    Senior

    With the second option it perfectly works! Thank you so much @Nicolas! I hope one day I’ll be able to get half of your knowledge..! 😀

     

    I just have another question regarding the following code. I don’t get any error but the calculation of the PP month isn’t right when I implement it in real. Do you have suggestions?

     


    @Nicolas
    , any magic tricks? 😀

     

    Thanks!

     

    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    DEFPARAM Preloadbars = 5000
    
    // Cumul des positions désactivé
    DEFPARAM CumulateOrders = False
    
    //************************************************************************
    
    //Horaires de trading
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 080000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 170000
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 080000
    timeEnterBefore = time >= noEntryBeforeTime
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 170000
    timeEnterAfter = time < noEntryAfterTime
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    
    //************************************************************************
    IF OpenMonth <> OpenMonth[1] THEN
    myLastHigh = myHigh
    myLastLow = myLow
    myLastClose = Close[1]
    myHigh = High
    myLow = Low
    Premierpassage=0
    ELSE
    myHigh = Max(myHigh, High)
    myLow = Min(myLow, Low)
    ENDIF
    
    pp = (myLastHigh + myLastLow + myLastClose) / 3
    
    //************************************************************************
    
    // Conditions pour ouvrir une position acheteuse
    c1 = (close CROSSES UNDER pp)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 55
    ENDIF
    
    // Conditions pour ouvrir une position en vente à découvert
    c2 = (close CROSSES OVER pp)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 55
    ENDIF
    
    
    //************************************************************************
    
    //trailing stop function
    trailingstart = 15 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
    newSL = tradeprice(1)+trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
    newSL = tradeprice(1)-trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep THEN
    newSL = newSL-trailingstep
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    #146081 quote
    Tanou
    Participant
    Senior

    Wether I write

    DEFPARAM Preloadbars = 10000 or DEFPARAM Preloadbars = 0

     

    I still got the Month pp at 12688 instead of 12842..

    #146091 quote
    Nicolas
    Keymaster
    Master

    Depends of the timeframe, but 10.000 bars might not be enough to calculate correctly the monthly high/low/close at start of the strategy. I suggest you use an higher timeframe only for this part, in order to compute the monthly pivot points correctly.

    #146118 quote
    Tanou
    Participant
    Senior

    I tried but the monthly pp is not correct it’s something like 8550 which is completely out as it should be 12859..

     

    I’m sure I’ve done a stupid mistake but I can’t figure out where…! Moreover I can’t write “Premierpassage=0” in this part as it doesn’t accept to be modify in another UT and I don’t know how to solve it..:

    ELSE
    myHigh = Max(myHigh, High)
    myLow = Min(myLow, Low)
    Premierpassage=0
    ENDIF

     

     

    Thanks so much for your help @Nicolas

     

    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    
    DEFPARAM Preloadbars = 10000
    
    // Cumul des positions désactivé
    DEFPARAM CumulateOrders = False
    
    //************************************************************************
    
    //Horaires de trading
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 080000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 170000
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 080000
    timeEnterBefore = time >= noEntryBeforeTime
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 170000
    timeEnterAfter = time < noEntryAfterTime
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    
    //************************************************************************
    timeframe(20 minutes,updateonclose)
    
    
    IF OpenMonth <> OpenMonth[1] THEN
    myLastHigh = myHigh
    myLastLow = myLow
    myLastClose = Close[1]
    myHigh = High
    myLow = Low
    ELSE
    myHigh = Max(myHigh, High)
    myLow = Min(myLow, Low)
    ENDIF
    
    pp = (myLastHigh + myLastLow + myLastClose) / 3
    
    //************************************************************************
    timeframe(default)
    // Conditions pour ouvrir une position acheteuse
    c1 = (close CROSSES UNDER pp)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 55
    ENDIF
    
    // Conditions pour ouvrir une position en vente à découvert
    c2 = (close CROSSES OVER pp)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 55
    ENDIF
    
    
    //************************************************************************
    
    //trailing stop function
    trailingstart = 15 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
    newSL = tradeprice(1)+trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
    newSL = tradeprice(1)-trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep THEN
    newSL = newSL-trailingstep
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    graph pp as "pp"
    #146133 quote
    Nicolas
    Keymaster
    Master

    and with:

    timeframe(daily,updateonclose)
    #146147 quote
    Tanou
    Participant
    Senior

    Hello Nicolas,

     

    Thank you for your answer!

     

    Here’s what I’ve done.

     

    Do you spt any mistakes?

     

    Cheers 🙂

     

    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    //-------------------------------------------------------------------------
    // Code principal : MonSystème
    //-------------------------------------------------------------------------
    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    //-------------------------------------------------------------------------
    // Code principal : PPM avec trailing stop
    //-------------------------------------------------------------------------
    
    DEFPARAM Preloadbars = 10000
    
    // Cumul des positions désactivé
    DEFPARAM CumulateOrders = False
    
    //************************************************************************
    
    //Horaires de trading
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 080000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 170000
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 080000
    timeEnterBefore = time >= noEntryBeforeTime
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 170000
    timeEnterAfter = time < noEntryAfterTime
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    
    //************************************************************************
    timeframe(5 minutes,updateonclose)
    If Month<>Month[1] then
    monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
    monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
    lastMonthBarIndex = BarIndex
    
    pp = (monthlyHigh + monthlyLow + Close[1]) / 3
    
    endif
    
    timeframe(default)
    
    If Month<>Month[1] then
    Premierpassage=0
    Endif
    //************************************************************************
    
    // Conditions pour ouvrir une position acheteuse
    c1 = (close CROSSES UNDER pp)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 55
    ENDIF
    
    // Conditions pour ouvrir une position en vente à découvert
    c2 = (close CROSSES OVER pp)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 55
    ENDIF
    
    
    //************************************************************************
    
    //trailing stop function
    trailingstart = 15 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
    newSL = tradeprice(1)+trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
    newSL = tradeprice(1)-trailingstep
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep THEN
    newSL = newSL-trailingstep
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
Viewing 11 posts - 16 through 26 (of 26 total)
  • You must be logged in to reply to this topic.

Error with historical data


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Tanou @tanou Participant
Summary

This topic contains 25 replies,
has 4 voices, and was last updated by Tanou
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/30/2020
Status: Active
Attachments: No files
Logo Logo
Loading...