xatr = averagetruerange[c](close)
nLoss = a * xatr
if heikin then
src = (open+close+high+low)/4
else
src = close
endif
if barindex < c then
xatrTrailingStop = undefined
pos = 0
else
if src > xatrTrailingStop[1] and src[1] > xatrTrailingStop[1] then
xAtrTrailingStop = max(xatrTrailingStop[1],src-nLoss)
else
if src < xatrTrailingStop[1] and src[1] < xatrTrailingStop[1] then
xAtrTrailingStop = min(xatrTrailingStop[1],src+nLoss)
else
if src > xatrTrailingStop[1] then
xAtrTrailingStop = src-nLoss
else
xAtrTrailingStop = src+nLoss
endif
endif
endif
if src[1] < xatrTrailingStop[1] and src > xAtrTrailingStop[1] then
pos = 1
r=250
g=0
b=0
else
if src[1] > xatrTrailingStop[1] and src < xatrTrailingStop[1] then
pos = -1
r=0
g=0
b=250
else
pos = pos[1]
endif
endif
endif
///////Trading conditions
ema = average[1](src)
above = ema crosses over xatrTrailingStop
below = ema crosses under xatrTrailingStop
buy1 = src > xatrTrailingStop and above
sell1 = src < xatrTrailingStop and below
barbuy = src > xatrTrailingStop
barsell = src < xatrTrailingStop
//////Plot signals and candles
if drawsignals then
if buy1 then
drawarrowup(barindex,low-0.15*averagetruerange[10])coloured(“green”)
elsif sell1 then
drawarrowdown(barindex,high+0.15*averagetruerange[10])coloured(“red”)
endif
endif
if colorcandles then
if barbuy then
rbar=0
gbar=250
bbar=0
elsif barsell then
rbar=250
gbar=0
bbar=0
else
rbar=125
gbar=125
bbar=125
endif
DRAWCANDLE(open, high, low, close)coloured(rbar,gbar,bbar)
endif
return xatrTrailingStop as “Trailing Stop” coloured(r,g,b)style(line,2)
Hi. Next time you share a code please define all variables (a, c, heikin, etc)
Here you have the code:
a=2
c=100
heikin=1
xatr = averagetruerange[c](close)
nLoss = a * xatr
if heikin then
src = (open+close+high+low)/4
else
src = close
endif
if barindex < c then
xatrTrailingStop = undefined
pos = 0
else
if src > xatrTrailingStop[1] and src[1] > xatrTrailingStop[1] then
xAtrTrailingStop = max(xatrTrailingStop[1],src-nLoss)
else
if src < xatrTrailingStop[1] and src[1] < xatrTrailingStop[1] then
xAtrTrailingStop = min(xatrTrailingStop[1],src+nLoss)
else
if src > xatrTrailingStop[1] then
xAtrTrailingStop = src-nLoss
else
xAtrTrailingStop = src+nLoss
endif
endif
endif
if src[1] < xatrTrailingStop[1] and src > xAtrTrailingStop[1] then
pos = 1
r=250
g=0
b=0
else
if src[1] > xatrTrailingStop[1] and src < xatrTrailingStop[1] then
pos = -1
r=0
g=0
b=250
else
pos = pos[1]
endif
endif
endif
///////Trading conditions
ema = average[1](src)
above = ema crosses over xatrTrailingStop
below = ema crosses under xatrTrailingStop
buy1 = src > xatrTrailingStop and above
sell1 = src < xatrTrailingStop and below
barbuy = src > xatrTrailingStop
barsell = src < xatrTrailingStop
//////Plot signals and candles
if buy1 then
buy 1 contract at market
endif
if sell1 then
sellshort 1 contract at market
endif
@IVAN
Hi, I’m testing the above bot.
Please clarify what is heikin at third row and why you put 1.
It’s not a PRT command.
Many thanks in advance
Hi
Heikin is a boolean variable (1/0 or true/false).
It gives you the way to calculate the src variable (check rows 8-12).
هل يمكنك جعله فعالا على مؤشر ناسداك في فترة 5 دقائق والتوافق مع حركة الشموع في استراتيجية تنبيهات UT bot؟
Can you make it effective on Nasdaq in 5 minutes period and match the candle movement in UT bot alerts strategy?
JSParticipant
Senior
Hi @Iván
I think line 50 is wrong, shouldn’t there be a “period” here…?
@
Haidar ali
Only post in the
language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Thanks 🙂
Hi!
I didn’t check it. I just copied code from Haidar.
Anyway, average[1](src) equals src. Maybe somebody has checked average[period](src) and the best is period=1…
I don’t know 🙂
JSParticipant
Senior
Hi,
I think the 1 was used for the EMA…
EMA=Average[Period,1](scr)