— 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
EUR/USD: котировки прощупывают дно в попытке возобновить рост
Европейская валюта закрыла пятницу выше уровня поддержки 1.1807, сформировав при этом свечную модель «бычье поглощение». Сигнал для покупателей подан. При реализации восходящего сценария первой...
Обновление кредитных рейтингов в ВДО и розничных облигациях (ООО «КОНТРОЛ лизинг» понижен до ruBB-, ПАО «ГК «САМОЛЕТ» присвоен статус "Под наблюдением", АО «ВЕРАТЕК» понижен до СС.ru)
⚪️ГУП ЖКХ РС(Я)
Эксперт РА продлил статус «под наблюдением» по рейтингу, что означает высокую вероятность рейтинговых действий в ближайшее время. Рейтинг компании продолжает действовать на...
Астра купила долю в компании у своего контролирующего акционера😢
В среду 4 февраля на сайте раскрытия вышли сущфакты от Астры о совершении сделки с заинтересованностью.
Ссылки на сущфакты:
➡️ сделка с заинтересованностью
➡️ дочка Астры ООО...
С начала текущего года ситуация в рублевых корпоративных облигациях в целом довольно спокойная – пока не наблюдается какая-либо выраженная динамика по доходности. Вместе с тем сохраняются ожидания...
Агентства по найму начали организовывать центры обучения языку и профессии в странах, откуда могут быть привлечены работники. Так, «Интруд» вместе с Российской ассоциацией сварщиков создал в столице ю...
izaslav, отчет ждать с 23 фев по 2 марта, там и видно будет… весна покажет кто где с…л. А пока эта скотина и на 33, не удивлюсь, что дойдет… Учитывая что хитрожопый рост на выходных произошел, то л...
Фильм на выхи: Лицо со шрамом | Scarface (1983)
«Мир принадлежит тебе» – надпись, которая появляется в фильме дважды. Вначале на дирижабле. Тогда эти слова означали, что в жизни Тони наступила нова...
❗️❗️Стратегия «Комфорт» провалилась. Что теперь спасет Делимобиль от банкротства?
Коллеги, продолжаем следить за историей Делимобиля (Каршеринг Руссия). Компания опубликовала операционный отчёт ...
Руслан Шингирей, Руслан ну ты и идиот!!! В 25г. Оак выпустила только 1 гражданский самолёт и передала его заказчику и это ту — 214, остальные в статистике это может быть как кукурузники, так и бипл...
Принцип прост, некое количество пунктов от позиции.
Вот лови:
— 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