Робот для стопа и тейка
- 04 февраля 2023, 21:02
- |
- Vasya
Друзья, добрый вечер.
Подскажите, пожалуйста, на просторах интернета есть смысл искать бесплатного робота для автоматизации стопов и тейков, или проще купить и забыть?
373
Читайте на SMART-LAB:
Эталон-Финанс сегодня проведет сбор заявок на облигации серии 002Р-05, насколько интересен выпуск?
Эталон-Финанс сегодня с 11:00 до 15:00 мск проводит сбор заявок на биржевые облигации серии 002Р-05. Техническое размещение бумаг на бирже...
Трейдинг по ролям: права и контроль доступа в командах
Утечка конфиденциальных стратегий, перегрузка системы, доступ к чужим ордерам без разрешения, изменение данных в алгоритмах и ботах коллег —...
Валютные облигации: время для накопления
Аналитики БКС ожидают, что давление на курс иностранных валют в II квартале сохранится. И это хорошая возможность увеличить долю валютных...
Ваш любимый Мозговой штурм спешит на помощь! Мнение по текущему рынку простыми словами
В нашем рейтинге акций знаменательное событие! Рекордное число акций с рейтингом 4 — 14 штук!!!
И, вероятно, будет еще больше!
Сегодня я...
Принцип прост, некое количество пунктов от позиции.
Вот лови:
— Function to calculate the simple moving average function sma(period, data) local sum = 0 for i = 1, period do sum = sum + data[i] end return sum / period end — Define the two moving average periods shortPeriod = 10 longPeriod = 50 — Define the stop loss and take profit levels stopLoss = -5 takeProfit = 10 — Initialize the moving average arrays shortMA = {} longMA = {} — Loop through the data to calculate the moving averages for i = 1, #data do — Calculate the short moving average if i >= shortPeriod then shortMA[i] = sma(shortPeriod, data[i — shortPeriod + 1, i]) end — Calculate the long moving average if i >= longPeriod then longMA[i] = sma(longPeriod, data[i — longPeriod + 1, i]) end — Check if a trade should be opened if shortMA[i] and longMA[i] and shortMA[i] > longMA[i] then — Buy the asset position = «long» — Set the stop loss and take profit levels stopLossPrice = data[i] * (1 + stopLoss / 100) takeProfitPrice = data[i] * (1 + takeProfit / 100) end — Check if the stop loss or take profit levels have been reached if position == «long» then if data[i] <= stopLossPrice then — Sell the asset to exit the trade position = nil end if data[i] >= takeProfitPrice then — Sell the asset to exit the trade position = nil end end end
— Function to calculate the simple moving average
function sma(period, data)
local sum = 0
for i = 1, period do
sum = sum + data[i]
end
return sum / period
end
— Define the two moving average periods
shortPeriod = 10
longPeriod = 50
— Define the stop loss and take profit levels
stopLoss = -5
takeProfit = 10
— Initialize the moving average arrays
shortMA = {}
longMA = {}
— Loop through the data to calculate the moving averages
for i = 1, #data do
— Calculate the short moving average
if i >= shortPeriod then
shortMA[i] = sma(shortPeriod, data[i — shortPeriod + 1, i])
end
— Calculate the long moving average
if i >= longPeriod then
longMA[i] = sma(longPeriod, data[i — longPeriod + 1, i])
end
— Check if a trade should be opened
if shortMA[i] and longMA[i] and shortMA[i] > longMA[i] then
— Buy the asset
position = «long»
— Set the stop loss and take profit levels
stopLossPrice = data[i] * (1 + stopLoss / 100)
takeProfitPrice = data[i] * (1 + takeProfit / 100)
end
— Check if the stop loss or take profit levels have been reached
if position == «long» then
if data[i] <= stopLossPrice then
— Sell the asset to exit the trade
position = nil
end
if data[i] >= takeProfitPrice then
— Sell the asset to exit the trade
position = nil
end
end
end