— 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
Стратегия на II квартал 2026 года. Акции с высокими дивидендами
Алексей Девятов Аналитики Альфа-Инвестиций представили инвестиционную стратегию на II квартал 2026 года : прогнозы для российской экономики и отдельных отраслей, актуальные тренды и наиболее...
Мы заставили ИИ-модели торговать на бирже. И вот что из этого вышло
Могут ли языковые модели торговать на бирже — и не слить, а реально заработать? «Финам» завершил первый этап «Финам Арены» — эксперимента, в котором шесть ведущих языковых моделей...
EUR/GBP: Последнее танго в треугольнике — кто первый сорвется в штопор?
На дневном таймфрейме кросс-курс EUR/GBP сформировал довольно широкий треугольник. На данный момент покупатели нацелены на пробой верхней границы фигуры (через точки B и D), рассчитывая на...
Астра: где зарыты кроты в отчете 2025? Сравнение с BAZA, DATA, DIAS, IVAT
На прошлой неделе компания Астра представила отчет за 2025 год: ✅ отчет МСФО 2025 ✅ презентация ✅ пресс-релиз В этой заметке мы разберем: 👉насколько инвест привлекательна Астра по текущим...
МОЛНИЯ
08.04.2026 19:12:17
ТРАМП: СУЩЕСТВУЕТ ЛИШЬ ОДИН СПИСОК ПРЕДЛОЖЕНИЙ ПО УРЕГУЛИРОВАНИЮ, И ИХ БУДУТ ОБСУЖДАТЬ В ЗАКРЫТОМ ФОРМАТЕ С ИРАНОМ, ОСТАЛЬНЫЕ ВЕРСИИ ЯВЛЯЮТСЯ ДОМЫСЛАМИ
ИНТЕРФАКС
any_to_real, так это же не Олег Владимирович, а Геннадий ОбдрищенкО предложил — шестидневку по 12 часов(и наверно перерыв на обед сократить до 30 минут)
— Вот кого — в будущие президенты надо.
...
⚛️ Атомэнергопром – Обзор облигаций и эмитента
📌 Вчера Атомэнергопром опубликовал отчёт по МСФО за 2025 год, поэтому смотрим, что изменилось в фин. устойчивости компании и привлекательны ли её обли...
Роспотребнадзор примет меры из-за крема La Roche-Posay с бензолом
Olha Kozachenko / Shutterstock
Фото: Olha Kozachenko / Shutterstock
Роспотребнадзор принимает меры в связи с появлением ин...
Дмитрий Г., у Самолет сверхприбыль намечается — тут надо быть совсем идиотом что бы шортить
и все раскупается
Самолет сейчас возводит 50 % всего жилого фонда за весь период с 2013 по 2026 и пр...
Всем привет
Добрые люди расскажите что с племзаводом? У них ТД? Аресты на всех счетах, где верховодит депутат?
Информация во всех источниках разная, надеюсь поможете разобраться что за ситуация
Принцип прост, некое количество пунктов от позиции.
Вот лови:
— 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