Buongiorno a tutti,
oggi ho provato a utilizzare la strategia automatica che ho trovato in questo topic (https://www.prorealcode.com/topic/strategie-avec-indicateur-asctrand/#post-159634),
ma al momento di entrare in posizione (ore 9:00 nel backtest) , si è bloccato con la motivazione:
“Il sistema di trading è stato interrotto a causa di una divisione per zero durante la valutazione dell’ultima candela. Può aggiungere delle protezioni al suo codice per evitare le divisioni per zero e poi ricontrollare il sistema per verificare la correzione.”
Questo è il codice :
//————————————————————————-
// Codice principale : ASCtrend strategy
//————————————————————————-
defparam cumulateorders=false
ONCE a = -1.0
ONCE b = 3.0
ONCE e = 5.0
TIMEFRAME(1minute, updateonclose)
ONCE c = 0.0
// ================
RISK = a //RISK setting of the ASCtrend indicator
size = 1 //size of orders
takeprofit = b //takeprofit in points (set to 0 to disable takeprofit, order will close at next signal inversion)
stoploss = c //stoploss in points (set to 0 to disable takeprofit, order will close at next signal inversion)
// ================
TradingDay = opendayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5
TradingTime = time = 090000 or time = 120000 or time = 150000 or time = 180000
buysig, sellsig = CALL “ASCtrend indi comp strategy”[RISK]
if not longonmarket and buysig[e] and tradingtime then
buy size contract at market
endif
if not shortonmarket and sellsig[e] and tradingtime then
sellshort size contract at market
endif
if stoploss>0 then
set stop ploss stoploss
endif
if takeprofit>0 then
set target pprofit takeprofit
endif
//graph buysig coloured(0,200,0)
//graph sellsig coloured(200,0,0)
SET STOP pTRAILING 0
//————————————————————————-
// Funzione : ASCtrend indi comp strategy
//————————————————————————-
// — settings
//RISK=3
// — end of settings
value10=3+RISK*2
x1=67+RISK
x2=33-RISK
value11=value10
shift=0//CountBars-11-1
buysig=0
sellsig = 0
Counter=shift
iRange=0.0
AvgRange=0.0
for Counter=shift to shift+9 do
AvgRange=AvgRange+Abs(High[Counter]-Low[Counter])
next
iRange=AvgRange/10
Counter=shift
TrueCount=0
while (Counter<shift+9 and TrueCount<1) do if (Abs(Open[Counter]-Close[Counter+1])>=iRange*2.0) then
TrueCount=TrueCount+1
endif
Counter=Counter+1
wend
if (TrueCount>=1) then
MRO1=Counter
else
MRO1=-1
endif
Counter=shift
TrueCount=0
while (Counter<shift+6 and TrueCount<1) do if (Abs(Close[Counter+3]-Close[Counter])>=iRange*4.6) then
TrueCount=TrueCount+1
endif
Counter=Counter+1
wend
if (TrueCount>=1) then
MRO2=Counter
else
MRO2=-1
endif
if (MRO1>-1) then
value11=3
else
value11=value10
endif
if (MRO2>-1) then
value11=4
else
value11=value10
endif
value2=100-Abs(Williams[value11](close)[shift]) // PercentR(value11=9)
$Tablevalue2[shift]=value2
$val1[shift]=0
$val2[shift]=0
value3=0
if (value2<x2) then //signals if value2[1]>x2[1] and lastsig>=0 then
sellsig = 1
lastsig = -1
endif
endif
if (value2>x1) then
//signals
if value2[1]<x1[1] and lastsig<=0 then
buysig = 1
lastsig = 1
endif
endif
//————————————————————————-
Grazie in anticipo del vostro aiuto!!