fractalP = 10 //fractal period
percent = 0.030 //maximum percent change between the 2 points
barlimit = 100 //maximum bars between 2 points
//fractals
cp=fractalP
if high[cp] >= highest[(cp)*2+1](high) then //new fractal high found
$TOPy[lastset($TOPy)+1] = high[cp] //store fractal value
$TOPx[lastset($TOPx)+1] = barindex[cp] //store fractal barindex
//COND=Summation[fractalP](Close>$topy[i])=1
endif
if low[cp] <= lowest[(cp)*2+1](low) then //new fractal low found
$BOTy[lastset($BOTy)+1] = low[cp] //store fractal value
$BOTx[lastset($BOTx)+1] = barindex[cp] //stire fractal barindex
endif
if(islastbarupdate and isset($topy[0]) and isset($boty[0])) then
//check points in a range of X percent
for i = 0 to lastset($TOPy) do //loop through the tops
for y = 0 to lastset($TOPy) do //check first top with other tops
change=abs(($topy[y]-$topy[i])/$topy[i]) //percent range between the 2 tops
bardiff=abs($TOPx[i]-$TOPx[y]) //how many bars between the 2 points?
Dtop= change<=percent/100 and bardiff<barlimit and bardiff>=fractalP and $topx[i]<>$topx[y]
next
next
for i = 0 to lastset($BOTy) do //loop through the bottoms
for y = 0 to lastset($BOTy) do //check first bottom with other bottoms
change=abs(($boty[y]-$boty[i])/$boty[i]) //percent range between the 2 bottoms
bardiff=abs($botx[i]-$botx[y]) //how many bars between the 2 points?
Dbot= change<=percent/100 and bardiff<barlimit and bardiff>=fractalP and $BOTx[i]<>$BOTx[y]
next
next
endif
if not LONGONMARKET and Dbot then
buy 1 shares AT MARKET
ENDIF
Set Stop loss 30
Set Target profit 60
hello to all, I’ve got a simple request. I’m studying the double top-bottom made by Nicolas, I’m trying to make a strategy, just for study. I’d like to go long when the second bottom at the condition Dbot) is identified, and go short when the second top is identifed. Strategy I’ve tryed does not give any result. can someone give me a tip? thank’0s in advance
Alessio
Strategy I’ve tryed does not give any result
No result in backtest or in Live trading?
What Instrument, TF are you testing on?
I can comfirm that the above code does run on Daily TF on DJI, but results in zero trades.
Please can you provide a link to the source of the above code? I have searched the Library with no success.
JSParticipant
Senior
Hi GraHal,
It’s example 6 from the array examples…
This indicator was not set up as a trading system but perhaps it is possible to turn it into a trading system…
Hi Grahal, did you find it? code is a little modified but it’s the same in the end. if you load the indicator, you can set it as it’s set in the strategy. I cannot explain why that condition does not work, I’ve graphed it and condition never shows.
I’ve graphed it and condition never shows.
My conclusion (maybe wrongly?) was that the coincident conditions (x AND y AND z etc) do not occur coincident with each other?
Also it is frustrating Algo to play with (for me) as, on less than Daily TF, it takes ages to run / optimise etc?
conditions occur in the indicator, they have to occur in the strategy as well, I guess. you can test with less candles.
maybe Nicolas or Robertogozzi could help us?
I guess. you can test with less candles.
I was down to 1k bars, but I still lost interest as it took so long … due to the arrays I would think?
it doesn’t take so long for me, perhaps your personal computer isn’t powerful enough?
It was quick on Daily but no results so I was trying 1 hour and 5 mins etc and optimising the variables … then it seemd like it had stalled! 🙂
Optimisation is executed remotely on the PRT servers, our PC do very little so we don’t need super fast PC.
It’s a pity that no one can help to understand. It could have a big potential.
Do you understand arrays enough to manipulate the code for better results? Are you able to state exactly what you want to be changed in the code you posted?
I think there are very few on here who can code arrays successfully?
Maybe choose a simpler Algo and start a separate Thread?
FWIW :
I tried the original code (it is an Indicator), and this works (as indicator indeed). But there it stops because it is wayyyyyy too slow to be workable.
Copying the code into the program itself does not help, except for that you can see that it won’t trade indeed. This is most probably because the trade points – as shown by the indicator – don’t fall on the bar-ends (the close of them) so while there would exist a moment that this coincides, in practice you can’t find his because 1000 bars already take 15 minutes to backtest over here and in these 1K bars (of 1 minute) the situation does not occur or it is too tedious to try a few things.
The solution, in my view, would be to enumerate the arrays one time per backtest (Optimization Parameters combination), so all the array-filling work can be done one time only, instead of 1000 times for testing over 1000 bars (or 200,000 times for 200K bars). But there it stopped to be funny, and I quit this case.
I did not make screenshots, but they would tell that for the intention of this indicator – trade on the 2nd top etc. – it requires refinement. Read : there would be too many false alarms because the shapes / fractals are not always caught correctly. On the other hand, notice that Nicolas just used this for a rough “arrays” example, which was a nice job to begin with.
Now if someone could cause that arrays are being dealt with smarter by PRT (like 10,000 times more efficient), “we” could all try to work on the improvement of such a really working DT/DB indicator. This one really has a good base (says me 😉 ).
I understand how to manipulate arrays and also create new ones in other indicators. What I do not understand is how to use in a strategy because what I think is correct in conditions of buy and sell does not work