ProRealCode - Trading & Coding with ProRealTime™
Hello,
I tried to embed the PP Fractals indicator developed by Vonasi https://www.prorealcode.com/prorealtime-indicators/pp-fractals/ in a Strategy, where among conditions to go Long (Close> $resistancevalue[z]) and go Short (Close<close < $supportvalue[z]). The backtest works perfectly fine on 100k 1min TF. However, when I put it live, I got this error message twice. It seems to be linked to the number of values in the Arrays. Note: this is the only Array I’ve in my system. Also, I tried with Preload 10000 bars and without Preload and the problem is the same.
I congratulate Vonasi for his work as the System without this condition generates 40% less Gains!
Any idea on how to overcome this problem?
Thank you.
Hi Khaled,
I don’t understand much of Vonasi’s Indicator code, so the only hint I can give you is that an array can’t contain more than 1M elements. And the message you show seems to be about that.
An other hint could be that the indicator is a kind of lame (not decent) in not being able to find a “base” for its signal, as Vonasi explains himself. So you could have run into that situation where it needs to go back further than the array size allows for.
Please keep in mind that my text may not make any sense because I really can’t follow what is going on in his code (up to my thinking that it can’t work at all 😐 ).
Hopefully others can help more; the 1M max elements is key …
What I would attempt :
a = a + 1
All such situations (also for b and z at first glance) could be written like this :
if a < 999999 then // 1 extra to be on the safe side.
a = a + 1
endif
This will stop going back further than technically possible, but don’t ask me for the reliability of the result and its impact. But at least it won’t fail.
On a (not so unimportant) side note :
You may have read (elsewhere) me questioning what would or could happen in LIVE when the progression of time may cross the threshold of the boundaries of arrays. But this (erroring-out) would require 1M bars plus the amount of looking back first. Anyway, this would be a “feature” of Live which BackTesting would not allow for (it won’t go wrong when time passes).
Hope this helps !
Thank you Peter. I’ll give it a try and let you know.
Dear Peter, Just Brilliant !!!! I tried your suggestion and so far it seems to work. I must admit that Arrays are way beyond my PRT skills.
Thanks a million and have a good day!
I worked one time, then same problem again and again. Anyone has a different idea please?
Please post the strategy code, we dont know how you have implemented the code into the strategy. I assume you want to trade the last segment breakout? If so, then most of the indicator code is not necessary.
Thank you Nicolas for your time. Indeed, I’d like to get signals on the last segment breakout.
Below the code run on SP500 – 100k – 1min TF – spread 0.6
DEFPARAM CUMULATEORDERS = FALSE
TIMEFRAME(60 minutes)
LongConso=0
ShortConso= 0
Long=0
Short=0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PRC_SwingLine Ron Black | indicator by Nicolas
if upsw=1 then
if high>hH then
hH=high
endif
if low>hL then
hL=low
endif
if high<hL then
upsw=0
lL=low
lH=high
endif
endif
if upsw=0 then
if low<lL then
lL=low
endif
if high<lH then
lH=high
endif
if low>lH then
upsw=1
hH=high
hL=low
endif
endif
if upsw=1 then
swingline=hL
else
swingline=lH
endif
if close>open then
iRange = abs(close-open)
elsif close<open then
iRange = abs(open-close)
endif
if close>open then
UpWick = high - close
LoWick = open-low
elsif close<open then
UpWick = high-open
LoWick = close-low
endif
// LONG
if close>open then
if close[1]>open[1] then
if close>close[1] then
long1=1
endif
endif
endif
if close>open then
if close[1]<open[1] then
if close>open[1] then
long2=1
endif
endif
endif
if iRange>UpWick or LoWick>UpWick then
long3 = 1
endif
//if close>close[1] and close[2]>close[1] then
//long4 = 1
//endif
if high>high[1] or low>low[1] then
long5=1
endif
if (long1 or long2) and long3 and long5 and close>swingline then
Long=1
endif
// SHORT
if close<open then
if close[1]>open[1] then
if close<open[1] then
short1=1
endif
endif
endif
if close<open then
if close[1]<open[1] then
if close<close[1] then
short2=1
endif
endif
endif
if iRange>LoWick or LoWick<UpWick then
short3 = 1
endif
//if close<close[1] and close[2]<close[1] then
//short4 = 1
//endif
if high<high[1] or low<low[1] then
short5=1
endif
if (Short1 or short2) and short3 and short5 and close<swingline then
Short=-1
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SR PP Fractal Lines by Vonasi
//BarsBefore = 1
//BarsAfter = 1
Support = 1
Resistance = 1
Points = 1
//Make sure all settings are valid ones
BarsBefore = max(BarsBefore,1)
BarsAfter = max(BarsAfter,1)
StartBack = max(0,startback)
if barindex >= barsbefore + barsafter then
//Look for a low fractal
BarLookBack = BarsAfter + 1
if low[BarsAfter] < lowest[BarsBefore](low)[BarLookBack] THEN
if low[BarsAfter] = lowest[BarLookBack](low) THEN
if a<99999 then
a = a + 1
endif
$supportbar[a] = barindex[barsafter]
$supportvalue[a] = low[barsafter]
endif
endif
//Look for a high fractal
if high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THEN
if high[BarsAfter] = highest[BarLookBack](high) THEN
if b<99999 then
b = b + 1
endif
$resistancebar[b] = barindex[barsafter]
$resistancevalue[b] = high[barsafter]
endif
endif
if islastbarupdate then
//support line
if a >= 2 then
if support then
flag = 0
zz = 0
for z = a-zz downto 1
for xx = 1 to a
if z-xx < 1 then
break
endif
if $supportvalue[z] > $supportvalue[z-xx] then
if points then
endif
flag = 1
break
endif
if zz<99999 then
zz = zz + 1
endif
next
if flag = 1 then
break
endif
zz = 0
next
endif
endif
//resistance line
if b >= 2 then
if resistance then
flag = 0
zz = 0
for z = b-zz downto 1
for xx = 1 to b
if z-xx < 1 then
break
endif
if $resistancevalue[z] < $resistancevalue[z-xx] then
if points then
endif
flag = 1
break
endif
if zz<99999 then
zz = zz + 1
endif
next
if flag = 1 then
break
endif
zz = 0
next
endif
endif
endif
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LongConso = long=1 and close > $resistancevalue[z]
ShortConso = short=-1 and close < $supportvalue[z]
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TIMEFRAME(5 minutes, UPDATEONCLOSE)
nLots = min(10,round((2000+STRATEGYPROFIT)/(close*.5*.1),1))
IF NOT LongOnMarket AND LongConso THEN
BUY nLots CONTRACTS AT MARKET
ENDIF
IF NOT ShortOnMarket AND ShortConso THEN
SELLSHORT nLots CONTRACTS AT MARKET
ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
If LongOnMarket AND ShortConso THEN
SELL AT MARKET
SELLSHORT nLots CONTRACTS AT MARKET
ENDIF
IF ShortOnMarket AND LongConso THEN
EXITSHORT AT MARKET
BUY nLots CONTRACTS AT MARKET
ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TIMEFRAME(1 minute)
SET STOP %LOSS .3 //SL
SET TARGET %PROFIT 1.6 //TP
Ok, so arrays are not useful anymore, there was useful in case of plotting them on the chart in the past.
Here is the code, not a real breakout, your condition is testing a price superior or inferior.
DEFPARAM CUMULATEORDERS = FALSE
TIMEFRAME(60 minutes)
LongConso=0
ShortConso= 0
Long=0
Short=0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PRC_SwingLine Ron Black | indicator by Nicolas
if upsw=1 then
if high>hH then
hH=high
endif
if low>hL then
hL=low
endif
if high<hL then
upsw=0
lL=low
lH=high
endif
endif
if upsw=0 then
if low<lL then
lL=low
endif
if high<lH then
lH=high
endif
if low>lH then
upsw=1
hH=high
hL=low
endif
endif
if upsw=1 then
swingline=hL
else
swingline=lH
endif
if close>open then
iRange = abs(close-open)
elsif close<open then
iRange = abs(open-close)
endif
if close>open then
UpWick = high - close
LoWick = open-low
elsif close<open then
UpWick = high-open
LoWick = close-low
endif
// LONG
if close>open then
if close[1]>open[1] then
if close>close[1] then
long1=1
endif
endif
endif
if close>open then
if close[1]<open[1] then
if close>open[1] then
long2=1
endif
endif
endif
if iRange>UpWick or LoWick>UpWick then
long3 = 1
endif
//if close>close[1] and close[2]>close[1] then
//long4 = 1
//endif
if high>high[1] or low>low[1] then
long5=1
endif
if (long1 or long2) and long3 and long5 and close>swingline then
Long=1
endif
// SHORT
if close<open then
if close[1]>open[1] then
if close<open[1] then
short1=1
endif
endif
endif
if close<open then
if close[1]<open[1] then
if close<close[1] then
short2=1
endif
endif
endif
if iRange>LoWick or LoWick<UpWick then
short3 = 1
endif
//if close<close[1] and close[2]<close[1] then
//short4 = 1
//endif
if high<high[1] or low<low[1] then
short5=1
endif
if (Short1 or short2) and short3 and short5 and close<swingline then
Short=-1
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SR PP Fractal Lines by Vonasi
//BarsBefore = 1
//BarsAfter = 1
Support = 1
Resistance = 1
Points = 1
//Make sure all settings are valid ones
BarsBefore = max(BarsBefore,1)
BarsAfter = max(BarsAfter,1)
StartBack = max(0,startback)
if barindex >= barsbefore + barsafter then
//Look for a low fractal
BarLookBack = BarsAfter + 1
if low[BarsAfter] < lowest[BarsBefore](low)[BarLookBack] THEN
if low[BarsAfter] = lowest[BarLookBack](low) THEN
//if a<99999 then
//a = a + 1
//endif
//$supportbar[a] = barindex[barsafter]
//$supportvalue[a] = low[barsafter]
supportvalue = low[barsafter]
endif
endif
//Look for a high fractal
if high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THEN
if high[BarsAfter] = highest[BarLookBack](high) THEN
//if b<99999 then
//b = b + 1
//endif
//$resistancebar[b] = barindex[barsafter]
//$resistancevalue[b] = high[barsafter]
resistancevalue = high[barsafter]
endif
endif
//if islastbarupdate then
////support line
//if a >= 2 then
//if support then
//flag = 0
//zz = 0
//for z = a-zz downto 1
//for xx = 1 to a
//if z-xx < 1 then
//break
//endif
//if $supportvalue[z] > $supportvalue[z-xx] then
//if points then
//endif
//flag = 1
//break
//endif
//if zz<99999 then
//zz = zz + 1
//endif
//next
//if flag = 1 then
//break
//endif
//zz = 0
//next
//endif
//endif
//
////resistance line
//if b >= 2 then
//if resistance then
//flag = 0
//zz = 0
//for z = b-zz downto 1
//for xx = 1 to b
//if z-xx < 1 then
//break
//endif
//if $resistancevalue[z] < $resistancevalue[z-xx] then
//if points then
//endif
//flag = 1
//break
//endif
//if zz<99999 then
//zz = zz + 1
//endif
//next
//if flag = 1 then
//break
//endif
//zz = 0
//next
//endif
//endif
//endif
endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LongConso = long=1 and close > resistancevalue//$resistancevalue[z]
ShortConso = short=-1 and close < supportvalue//$supportvalue[z]
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TIMEFRAME(5 minutes, UPDATEONCLOSE)
nLots = min(10,round((2000+STRATEGYPROFIT)/(close*.5*.1),1))
IF NOT LongOnMarket AND LongConso THEN
BUY nLots CONTRACTS AT MARKET
ENDIF
IF NOT ShortOnMarket AND ShortConso THEN
SELLSHORT nLots CONTRACTS AT MARKET
ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
If LongOnMarket AND ShortConso THEN
SELL AT MARKET
SELLSHORT nLots CONTRACTS AT MARKET
ENDIF
IF ShortOnMarket AND LongConso THEN
EXITSHORT AT MARKET
BUY nLots CONTRACTS AT MARKET
ENDIF
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TIMEFRAME(1 minute)
SET STOP %LOSS .3 //SL
SET TARGET %PROFIT 1.6 //TP
Thank you Nicolas.
The code I provided generates in backtest a net gain of 5,328 with a WinRate of 25% and a Drawdown of -2500.
Without changing parameters such as SL, TP, Barsbefore, Barsafter, the code with your changes generates in backtest over the same period a net loss of -1,806 with a WinRate of 23% and a Drawdown of -1897.
So there is something in the original code that was certainly useful.
How can we please just overcome the problem of 1,000,000 values in the Array of the first code?
Much appreciated.
Hi Khaled,
What did you mean “it works one time” ? One trade only like you see below ?
Otherwise I copied your code given to Nicoalas and this is the result. Can I be doing something wrong ?
All right. There is is. It required the correct 1euro instrument.
But no error messages (yet), and I removed the If 99999 WHICH btw has one 9 too few (I suggested 999999).
What’s next ?
🙂
In case you want to pursue this further : It doesn’t seem to be resilient to more normal markets (pre-Inflation – this is 200K).
N.b.: 1M fails on the “500” error @nonetheless also receives. This is not related to the arrays, as it seems.
Peter, thanks for taking the time.
What I meant by “worked one time”, the Algo took live 4 LONG trades in a row (entry and exit properly with small profit), then at the 5th Signal, I had again the same error message. I tried again and again and it’s the same error message.
The Backtest works fine.
The error appears only when I put it Live.
I suspect the solution is what you suggested earlier, limit the number of values in the Array table. May be it should be at the very beginning of the PP Fractals code so that no calculation is performed beyond 999,999
Much appreciated
limit the number of values in the Array table.
Because I don’t understand what it (the arrays) is doing there anyway, I suggest that we better interpret what @Nicolas is saying. So to me it now seems that he (from his own code ever back ?) tells that the arrays were only there for graphing, while you don’t graph anything. So just eliminate the code concerned (?).
Otherwise your error in Live (I missed that one – apologies) could be related to the 500-error I receive with the 1M backtest.
PP Fractals // Error message
This topic contains 28 replies,
has 4 voices, and was last updated by PeterSt
3 years, 11 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 02/28/2022 |
| Status: | Active |
| Attachments: | 15 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.