Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
backtester for system'cRe5520'
//@version=3
strategy(
title='Channel breakout trading strategy',
shorttitle='cRe5520',
overlay=true,
initial_capital=1000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
commission_type=strategy.commission.percent,
commission_value=0.075,
pyramiding=0,
slippage=5,
currency=currency.USD
)
OH = input(
high,
'high or open',
type=source
)
CL = input(
low,
'low or close',
type=source
)
entry_sticks = input(
50,
'1st period'
)
exit_sticks = input(
10,
'2nd period'
)
offset = input(
0.5,
'offset',
minval=-0.5,
maxval=3.5,
step=0.5
)
entry_long = highest(
max(OH, CL),
entry_sticks
)
entry_short = lowest(
min(OH, CL),
entry_sticks
)
exit_short = highest(
max(OH, CL),
exit_sticks
)
exit_long = lowest(
min(OH, CL),
exit_sticks
)
plot(entry_long, color=#6699ff, linewidth=2)
plot(entry_short, color=#66ccff, linewidth=2)
plot(exit_short, color=#ff99cc, linewidth=2)
plot(exit_long, color=#ff6699, linewidth=2)
from_year = input(
2018,
'from year',
minval=2017,
maxval=9999
)
from_month = input(
10,
'from month',
minval=01,
maxval=12
)
from_day = input(
01,
'from day',
minval=01,
maxval=31
)
to_year = input(
2020,
'to year',
minval=2017,
maxval=9999
)
to_month = input(
12,
'to month',
minval=01,
maxval=12
)
to_day = input(
31,
'to day',
minval=01,
maxval=31
)
start_time = timestamp(
from_year,
from_month,
from_day,
00,
00
)
end_time = timestamp(
to_year,
to_month,
to_day,
23,
59
)
// end_time = timenow
is_work = start_time <= time and time <= end_time
if (is_work)
current_position = strategy.position_size
if current_position < 0
strategy.exit(
'exit',
stop=exit_short+offset
)
if current_position > 0
strategy.exit(
'exit',
stop=exit_long-offset
)
if current_position == 0
strategy.entry(
'long',
true,
stop=entry_long+offset
)
strategy.entry(
'short',
false,
stop=entry_short-offset
)
// EOF
@nonkimista
Copy link
Author

nonkimista commented Apr 25, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment