Error indicator negative entry or zero parameter

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #163679 quote
    Tanou
    Participant
    Senior

    Hello everyone! 😀

     

    I hope you are well!

     

    I launched live a code yesterday and today it has been stopped with the message ” indicator negative entry or zero parameter” and I can’t find why and where could be the error…

     

    Could someone give me a hint?

     

    Thanks! 😀

     

    //-------------------------------------------------------------------------
    // Code principal : PP4H V1
    //-------------------------------------------------------------------------
    
    // Définition des paramètres du code
    // Cumul des positions désactivé
    DEFPARAM CumulateOrders = False
    DEFPARAM PRELOADBARS = 100000000
    //************************************************************************
    
    //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 = 090000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 173000
    // 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 = 090500
    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 = 125000
    timeEnterAfter = time < noEntryAfterTime
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 5 OR OpenDayOfWeek = 0
    
    //************************************************************************
    // Calcul Points Pivots 4h
    Int = (OpenTime[1] < 010000 AND OpenTime > 010000) OR (OpenTime[1] < 050000 AND OpenTime > 050000) OR (OpenTime[1] < 090000 AND OpenTime > 090000) OR (OpenTime[1] < 130000 AND OpenTime > 130000) OR (OpenTime[1] < 170000 AND OpenTime > 170000) OR (OpenTime[1] < 210000 AND OpenTime > 210000) OR (Openday <> Openday[1] AND DayOfWeek < DayOfWeek[1])
    IF (OpenTime Mod 40000 = 10000) OR Int THEN
    myLastHigh = myHigh
    myLastLow = myLow
    myLastClose = Close[1]
    myHigh = High
    myLow = Low
    Premierpassage=0
    DebutOpen = Barindex
    ELSE
    myHigh = Max(myHigh, High)
    myLow = Min(myLow, Low)
    ENDIF
    
    
    PP = (myLastHigh + myLastLow + myLastClose) / 3
    
    
    
    hh = highest[85](high)
    ll = lowest[85](low)
    
    if (hh-ll)<20 then
    Rang = 0
    else
    Rang = 1
    Endif
    
    
    BarresDepuisOpen = Barindex - DebutOpen
    HighSinceOpen = highest[BarresDepuisOpen](high)
    LowSinceOpen = lowest[BarresDepuisOpen](low)
    DiffHighSinceOpen = HighSinceOpen - pp
    DiffLowSinceOpen = pp - LowSinceOpen
    
    If DiffHighSinceOpen>25 or DiffLowSinceOpen>25 then
    Rang2 = 1
    else
    Rang2 = 0
    Endif
    
    // Conditions pour ouvrir une position acheteuse
    c1 = (close[1] CROSSES UNDER pp)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang  and Rang2 THEN
    BUY 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 60
    ENDIF
    
    // Conditions pour ouvrir une position en vente à découvert
    c2 = (close[1] CROSSES OVER pp)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang and Rang2 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 50
    ENDIF
    
    If time>=090500 and time<=125000 then
    If Premierpassage=0 and c1 or c2 then
    Premierpassage=1
    endif
    Endif
    
    //************************************************************************
    //trailing stop function
    trailingstartL = 21 //LONG  trailing will start @trailinstart points profit
    trailingstartS = 21 //SHORT trailing will start @trailinstart points profit
    trailingstep    = 11 //trailing step to move the "stoploss"
    breakeven = 0 //Activate or not the Brakeven
    breakevenlevel = 15 //Level of activation of the breakeven
    PointsToKeepBreakeven = 1
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    BreakevenStop=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    If Breakeven and BreakevenStop=0 then
    IF close-tradeprice(1)>=breakevenlevel*pipsize THEN
    BreakevenStop = tradeprice(1) + PointsToKeepBreakeven
    Endif
    Endif
    //first move trailing stop
    IF newSL=0 AND close-tradeprice(1)>=trailingstartL*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    If Breakeven and BreakevenStop=0 then
    IF tradeprice(1)-close>=breakevenlevel*pipsize THEN
    BreakevenStop = tradeprice(1) - PointsToKeepBreakeven
    Endif
    Endif
    //first move trailing stop
    IF newSL=0 AND tradeprice(1)-close>=trailingstartS*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions with trailing stop
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    //stop order to exit the positions with breakeven
    IF BreakevenStop>0 THEN
    SELL AT BreakevenStop STOP
    EXITSHORT AT BreakevenStop STOP
    ENDIF
    //************************************************************************
    
    #163682 quote
    robertogozzi
    Moderator
    Master

    Try replacing lines 57-58 with:

    HighSinceOpen = highest[max(1,BarresDepuisOpen)](high)
    LowSinceOpen  = lowest[max(1,BarresDepuisOpen)](low)

    because the first time BarresDepuisOpen retains 0.

    #163687 quote
    Tanou
    Participant
    Senior

    Thanks @Robertogozzi ! I’ll try that!

     

    Do you think it could also come from elsewhere?

    #163691 quote
    robertogozzi
    Moderator
    Master

    No, I think that can only be the cause.

    #219936 quote
    jmf125
    Participant
    Senior

    I have had virtually the same problem and although it works if you leave the code in the main algo, it still gives the error when you place the code in an indicator.

    Would you know why it behaves differently in an indicator vs main algo ?

    #220055 quote
    robertogozzi
    Moderator
    Master

    I assume you are talking about the syntax error regarding the variable BREAKEVEN.

    As you can see it’s coloured in blue, this means it’s a reserved keyword (now, it wasn’t at the time the code was written). You only have to replace it with a name of your choice, whenever it occurs, usually adding (at the beginning or at the end of that name) any character of yoiur choice so that it’s no more recognized as a keyword.

    I replaced it with MYBREAKEVEN (all variables and keywords are case insensitive):

    //-------------------------------------------------------------------------
    // Code principal : PP4H V1
    //-------------------------------------------------------------------------
    
    // Définition des paramètres du code
    // Cumul des positions désactivé
    DEFPARAM CumulateOrders = False
    DEFPARAM PRELOADBARS = 100000000
    //************************************************************************
    
    //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 = 090000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 173000
    // 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 = 090500
    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 = 125000
    timeEnterAfter = time < noEntryAfterTime
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 5 OR OpenDayOfWeek = 0
    
    //************************************************************************
    // Calcul Points Pivots 4h
    Int = (OpenTime[1] < 010000 AND OpenTime > 010000) OR (OpenTime[1] < 050000 AND OpenTime > 050000) OR (OpenTime[1] < 090000 AND OpenTime > 090000) OR (OpenTime[1] < 130000 AND OpenTime > 130000) OR (OpenTime[1] < 170000 AND OpenTime > 170000) OR (OpenTime[1] < 210000 AND OpenTime > 210000) OR (Openday <> Openday[1] AND DayOfWeek < DayOfWeek[1])
    IF (OpenTime Mod 40000 = 10000) OR Int THEN
    myLastHigh = myHigh
    myLastLow = myLow
    myLastClose = Close[1]
    myHigh = High
    myLow = Low
    Premierpassage=0
    DebutOpen = Barindex
    ELSE
    myHigh = Max(myHigh, High)
    myLow = Min(myLow, Low)
    ENDIF
    
    
    PP = (myLastHigh + myLastLow + myLastClose) / 3
    
    
    
    hh = highest[85](high)
    ll = lowest[85](low)
    
    if (hh-ll)<20 then
    Rang = 0
    else
    Rang = 1
    Endif
    
    
    BarresDepuisOpen = Barindex - DebutOpen
    HighSinceOpen = highest[BarresDepuisOpen](high)
    LowSinceOpen = lowest[BarresDepuisOpen](low)
    DiffHighSinceOpen = HighSinceOpen - pp
    DiffLowSinceOpen = pp - LowSinceOpen
    
    If DiffHighSinceOpen>25 or DiffLowSinceOpen>25 then
    Rang2 = 1
    else
    Rang2 = 0
    Endif
    
    // Conditions pour ouvrir une position acheteuse
    c1 = (close[1] CROSSES UNDER pp)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang  and Rang2 THEN
    BUY 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 60
    ENDIF
    
    // Conditions pour ouvrir une position en vente à découvert
    c2 = (close[1] CROSSES OVER pp)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry and Rang and Rang2 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Premierpassage=1
    SET STOP pLOSS 50
    ENDIF
    
    If time>=090500 and time<=125000 then
    If Premierpassage=0 and c1 or c2 then
    Premierpassage=1
    endif
    Endif
    
    //************************************************************************
    //trailing stop function
    trailingstartL = 21 //LONG  trailing will start @trailinstart points profit
    trailingstartS = 21 //SHORT trailing will start @trailinstart points profit
    trailingstep    = 11 //trailing step to move the "stoploss"
    mybreakeven = 0 //Activate or not the Brakeven
    breakevenlevel = 15 //Level of activation of the breakeven
    PointsToKeepBreakeven = 1
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    BreakevenStop=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    If mybreakeven and BreakevenStop=0 then
    IF close-tradeprice(1)>=breakevenlevel*pipsize THEN
    BreakevenStop = tradeprice(1) + PointsToKeepBreakeven
    Endif
    Endif
    //first move trailing stop
    IF newSL=0 AND close-tradeprice(1)>=trailingstartL*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    If mybreakeven and BreakevenStop=0 then
    IF tradeprice(1)-close>=breakevenlevel*pipsize THEN
    BreakevenStop = tradeprice(1) - PointsToKeepBreakeven
    Endif
    Endif
    //first move trailing stop
    IF newSL=0 AND tradeprice(1)-close>=trailingstartS*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions with trailing stop
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    //stop order to exit the positions with breakeven
    IF BreakevenStop>0 THEN
    SELL AT BreakevenStop STOP
    EXITSHORT AT BreakevenStop STOP
    ENDIF
    //************************************************************************
    #220176 quote
    jmf125
    Participant
    Senior

    Thanks for you response Roberto. But no I wasn’t talking about the variable BREAKEVEN.

    I have the following code in the main algo, and it works fine in real time. If I move this piece of code in an indicator and call the indicator in the main algo , I am getting an error saying a zero or negative parameter ….

    any idea why it would behave differently if in main algo or in the indicator section ? Thanks in advance

    If Month <> Month[1] and Barindex > 0 then
    monthlyHigh = Highest[BarIndex – lastMonthBarIndex](dailyHigh)

    monthlyLow = Lowest[BarIndex – lastMonthBarIndex](dailyLow)

    lastMonthBarIndex = BarIndex
    ENDIF

    #220207 quote
    robertogozzi
    Moderator
    Master

    I added that code as an indicator of its own, then calling it from the strategy, and it works as expected.

    I placed those lines in your code above and it works fine like in the indocator.

    I couldn’t spot anything wrong.

    You should post the whole code for both the strategy and the indicator, specifying the instrument, timeframe and units used.

    #220233 quote
    jmf125
    Participant
    Senior

    Thanks again for the reply.

    I should have also indicated that the error is only in real time (i.e when trading) not when running BT.

    #220237 quote
    jmf125
    Participant
    Senior

    The code is below inspired from Reiner – Pathfinder that I am trying to use as one indicator to buy or sell. If I insert in the main algo it works but stopped working as I put it in an indicator
    It does not really matter, I can continue to have it in the main algo but just tidier to use as an indicator to simplify the view of the main code.
    And also curious to understand why it works in one case and fails in the other.

    timeframe(4h, updateonclose)
    
    Cbuy, Csell =Call "JM INDICATOR V0.1"
    

     

    ONCE periodFirstMA = 6
    ONCE periodSecondMA = 10
    ONCE periodThirdMA = 4
    
    // filter parameter
    ONCE periodLongMA = 160
    ONCE periodShortMA = 40
    
    ONCE lastweekbarindex =0
    once lastmonthbarindex = 0
    
    
    // calculate daily high/low
    dailyHigh = DHigh(1)
    dailyLow = DLow(1)
    
    // calculate weekly high/low
    If DayOfWeek < DayOfWeek[1] and barindex > 0 then
    weeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)
    lastWeekBarIndex = BarIndex
    ENDIF
    
    // calculate monthly high/low
    If Month <> Month[1] and barindex > 0 then
    monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
    monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
    lastMonthBarIndex = BarIndex
    ENDIF
    
    // calculate signalline with multiple smoothed averages
    firstMA = WilderAverage[periodFirstMA](close)
    secondMA = TimeSeriesAverage[periodSecondMA](firstMA)
    signalline = TimeSeriesAverage[periodThirdMA](secondMA)
    
    // filter criteria because not every breakout is profitable
    c1 = close > Average[periodLongMA](close)
    c2 = close < Average[periodLongMA](close) c3 = close > Average[periodShortMA](close)
    c4 = close < Average[periodShortMA](close)
    
    
    // long position conditions
    l1 = signalline CROSSES OVER monthlyHigh
    l2 = signalline CROSSES OVER weeklyHigh
    l3 = signalline CROSSES OVER dailyHigh
    l4 = signalline CROSSES OVER monthlyLow
    
    
    
    // short position conditions
    s1 = signalline CROSSES UNDER monthlyHigh
    s2 = signalline CROSSES UNDER monthlyLow
    s3 = signalline CROSSES UNDER dailyLow
    
    
    
    
    
    
    
    CondAchat =  ((l1) OR (l4) OR (l2)OR (l3 AND c2))
    CondVente= ((s2 AND c4) OR (s3 AND c1))
    
    
    RETURN CondAchat, CondVente
    
    #220238 quote
    jmf125
    Participant
    Senior

    The error should reoccur tomorrow Monday at 4:00 (GMT)  – I believe because it is a new week and 4:00 is due to the 4h timeframe

    #220240 quote
    JS
    Participant
    Senior

    Hi,

    I tried the indicator, and I don’t get an error message (also not on Monday) and the indicator gives buy and sell signals…?

    Scherm­afbeelding-2023-09-03-om-12.38.51.png Scherm­afbeelding-2023-09-03-om-12.38.51.png
    #220242 quote
    jmf125
    Participant
    Senior
    Hi JS When you say trying do you mean in BT ? The error only occurs in real time trading I also can run the BT without any problems
    #220247 quote
    JS
    Participant
    Senior

    Hi,

    That’s right, I hadn’t read everything yet… 🙂

    I personally think that error message is due to the “Crosses Over” and “Crosses Under”…

    Perhaps it would be better to use “greater than (>) ” and “smaller than (<)” here…

    (remark: there is no WeeklyLow in the code…?)
    #220275 quote
    jmf125
    Participant
    Senior
    Thanks JS. If the error is due to cross over – under , replacing these with > and < is fundamentally different. Cross over and under are only valid for 1 bar whereas > and < are not limited in time
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.

Error indicator negative entry or zero parameter


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Tanou @tanou Participant
Summary

This topic contains 17 replies,
has 4 voices, and was last updated by robertogozzi
2 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/10/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...