ProRealCode - Trading & Coding with ProRealTime™
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
//************************************************************************
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.
No, I think that can only be the cause.
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 ?
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
//************************************************************************
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
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.
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.
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
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
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…?
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…?)Error indicator negative entry or zero parameter
This topic contains 17 replies,
has 4 voices, and was last updated by
robertogozzi
2 years, 5 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 03/10/2021 |
| Status: | Active |
| Attachments: | 1 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.