
Эта стратегия является стратегией пересечения средних линий, основанной на простых движущихся средних. Она использует простые движущиеся средние длиной 1 и длиной 5.
Эта стратегия рассчитывает 1-дневную простую подвижную среднююsma1 и 5-дневную простую подвижную среднююsma5 для цены закрытия. Заполняется при использованииsma5 на sma1 и закрывается при использованииsma5.
Направление оптимизации:
Эта стратегия представляет собой простую двухлинейную стратегию, с простыми и простыми в использовании характеристиками, которая позволяет быстро проверять стратегические идеи. Однако ее устойчивость и прибыльность ограничены, и параметры и условия фильтрации должны быть оптимизированы, чтобы адаптироваться к более широкой рыночной среде. Как первая количественная стратегия для начинающих, она содержит основные компоненты, которые могут быть итерационно улучшены в качестве простой структуры.
/*backtest
start: 2023-02-19 00:00:00
end: 2024-02-19 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Valeria 181 Bot Strategy Mejorado 2.21", overlay=true, margin_long=100, margin_short=100)
var float lastLongOrderPrice = na
var float lastShortOrderPrice = na
longCondition = ta.crossover(ta.sma(close, 1), ta.sma(close, 5))
if (longCondition)
strategy.entry("Long Entry", strategy.long) // Enter long
shortCondition = ta.crossunder(ta.sma(close, 1), ta.sma(close, 5))
if (shortCondition)
strategy.entry("Short Entry", strategy.short) // Enter short
if (longCondition)
lastLongOrderPrice := close
if (shortCondition)
lastShortOrderPrice := close
// Calculate stop loss and take profit based on the last executed order's price
stopLossLong = lastLongOrderPrice - 5 // 10 USDT lower than the last long order price
takeProfitLong = lastLongOrderPrice + 151 // 100 USDT higher than the last long order price
stopLossShort = lastShortOrderPrice + 5 // 10 USDT higher than the last short order price
takeProfitShort = lastShortOrderPrice - 150 // 100 USDT lower than the last short order price
// Apply stop loss and take profit to long positions
strategy.exit("Long Exit", from_entry="Long Entry", stop=stopLossLong, limit=takeProfitLong)
// Apply stop loss and take profit to short positions
strategy.exit("Short Exit", from_entry="Short Entry", stop=stopLossShort, limit=takeProfitShort)