pds1:=
Input
(
"HHV (long) breakout periods"
, 1,252,21);
pds2:=
Input
(
"LLV (short) breakout periods"
, 1,252,10);
display:=
Input
(
"display: signals=1, in-trade binary=2"
,1,2,1);
x:=
Input
(
"use Open=1 High=2 Low=3 Close=4 Volume=5 P=6"
,1,6,4);
delay:=
Input
(
"Entry and Exit delay"
,0,3,0);
x:=
If
(x=1,
O
,
If
(x=2,
H
,
If
(x=3,
L
,
If
(x=5,
V
,
If
(x=6,P,
C
)))));
In:=x>
Ref
(
HHV
(x,pds1),-1);
Out:=x<
Ref
(
LLV
(x,pds2),-1);
Init:=
Cum
(In+Out>-1)=1;
InInit:=
Cum
(In)=1;
Flag:=
BarsSince
(Init
OR
In) <
BarsSince
(Init
OR
Out)+InInit;
In1:=
Cum
(
Cum
(In))=1;
Out1:=
Cum
(
Cum
(Out))=1;
If
(display=1,
Ref
(
Cum
(
Cum
(In))=1,-delay),0);
If
(display=1,-
Ref
(Out1
AND
BarsSince
(In1)>=
BarsSince
(Out1),-delay),0);
If
(display=1,
Ref
((InInit
AND
Alert
(InInit=0,2)
OR
Flag
AND
Alert
(Flag=0,2)) - (Flag=0
AND
Alert
(Flag,2)),-delay),Flag)