Блог им. raxat

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// This strategy has been created for illustration purposes only and should not be relied upon as a basis for buying, selling, or holding any asset or security.
// © Diamond
//@version=4
strategy("SMA Golden Cross Strategy", overlay = true, calc_on_every_tick = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_value = 0.04, commission_type = strategy.commission.percent)Доступно редактирование 4 переменных: период быстрой средней, период медленной средней, даты начала и конца бэктеста: //Inputs
smaFast = input(title = "Fast SMA", type = input.integer, defval = 50, minval = 1)
smaSlow = input(title = "Slow SMA", type = input.integer, defval = 200, minval = 1)
//Options to configure backtest trade range
startDate = input(title = "Start Date", type=input.time, defval=timestamp("01 Jan 1998 00:00"))
endDate = input(title = "End Date", type=input.time, defval=timestamp("31 Dec 2070 23:59"))SMA вычисляется по цене закрытия://Calculations fastSMA = sma(close, smaFast) slowSMA = sma(close, smaSlow)Затем они отображаются на графике с помощью Plot(), где можно задать цвет (Color) и толщину линии (linewidth):
//Plot plot(series = fastSMA, color = color.orange, linewidth = 2) plot(series = slowSMA, color = color.blue, linewidth = 3)У торговой системы всего 3 условия для работы.
inDateRange = (time >= startDate) and (time < endDate)2. Позиция открывается в тот момент, когда быстрая средняя fastSMA пересекает медленную slowSMA снизу вверх:
longOpenCondition = crossover(fastSMA, slowSMA)3. Позиция закрывается при обратном условии:
longCloseCondition = crossunder(fastSMA, slowSMA)Эта логика отражена в коде для трейдинга. Для открытия позиции используется strategy.entry(), а для закрытия strategy.exit()
//Trading
if(longOpenCondition and inDateRange)
strategy.entry(id = "long", long = true, comment = "Long Open")
if(strategy.position_size > 0 and longCloseCondition)
strategy.exit(id = "long", stop = close, comment = "Long Close")Стоп-лосса и тейк-профита нет, это ваша первая торговая система и она должна быть максимально простой для понимания.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// This strategy has been created for illustration purposes only and should not be relied upon as a basis for buying, selling, or holding any asset or security.
// © Diamond
//@version=4
strategy("SMA Golden Cross Strategy", overlay = true, calc_on_every_tick = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_value = 0.04, commission_type = strategy.commission.percent)
//Inputs
smaFast = input(title = "Fast SMA", type = input.integer, defval = 50, minval = 1)
smaSlow = input(title = "Slow SMA", type = input.integer, defval = 200, minval = 1)
//Options to configure backtest trade range
startDate = input(title = "Start Date", type=input.time, defval=timestamp("01 Jan 1998 00:00"))
endDate = input(title = "End Date", type=input.time, defval=timestamp("31 Dec 2070 23:59"))
//Calculations
fastSMA = sma(close, smaFast)
slowSMA = sma(close, smaSlow)
//Plot
plot(series = fastSMA, color = color.orange, linewidth = 2)
plot(series = slowSMA, color = color.blue, linewidth = 3)
//Conditions
inDateRange = (time >= startDate) and (time < endDate)
longOpenCondition = crossover(fastSMA, slowSMA)
longCloseCondition = crossunder(fastSMA, slowSMA)
//Trading
if(longOpenCondition and inDateRange)
strategy.entry(id = "long", long = true, comment = "Long Open")
if(strategy.position_size > 0 and longCloseCondition)
strategy.exit(id = "long", stop = close, comment = "Long Close")
Переставьте калк_он_еври_тик в фальс и добавьте условие проверки, что случилось реальное пересечение, а не «переплетение». Уверен, результат теста будет иным. И скорее с минусом…
Да, для фильтрации. Не совсем боковики, а когда СМА совпадают.
Как насчет 100000 на минутках?