Morun Astro Trend MAs cross Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © citlacom
// @version=4
// Strategy developed by the Financial Astrology Research Group.

strategy("Financial Astrology Research MA Strategy", 
     overlay=true, linktoseries=true,
     currency="USD", pyramiding=0, initial_capital=10000,
     default_qty_type=strategy.percent_of_equity, default_qty_value=25,
     commission_type=strategy.commission.percent, commission_value=0.1)

// Signals indicators.
var int masterCycleLength = input(40, minval=30, step=10, title="Master cycle length")
var int minCrossConsolidationPeriod = input(0, minval=0, step=5, title="Minimum MA cross consolidation period")
var int leadShiftHours = input(0, type=input.integer, minval=0, step=4, title="Hours shift for leading effect")
var int futureWeeksNumber = timeframe.isminutes ? 1 : 2

// Risk control settings.
float trailingStopPercent = input(10, title="Trailing Stop Distance(%)", type=input.float, minval=0.0, step=1) * 0.01
float trailingStopTriggerPercent = input(1, title="Trailing Stop Trigger Distance(%)", type=input.float, minval=0.0, step=1) * 0.01
float stopLossPercent = input(5, title="Stop Loss (%)", type=input.float, minval=0.0, step=1) * 0.01
bool plotTrailingStop = input(false, title="Plot trailing stop prices.", type=input.bool)
string orderType = "market"

// Order signals controls.
bool enableEntryShortOrder = input(true, title="Enable entry short orders", type=input.bool)
bool enableEntryLongOrder = input(true, title="Enable entry long orders", type=input.bool)
bool ignoreEarlyReverseSignal = input(false, title="Ignore exit signal when change is lower than stop loss", type=input.bool)
string zignalyProviderEnvKey = input("", title="Zignaly provider key environment variable", type=input.string)
bool skipProcessingFilters = true
bool exitOnReverseSignal = true

int fastMAPeriod = masterCycleLength / 2
int slowMAPeriod = masterCycleLength

// Position information.
float currentPositionSize = strategy.position_size
float currentPositionEntryPrice = strategy.position_avg_price
string positionSymbol = syminfo.ticker
string positionSymbolId = syminfo.tickerid
float positionSymbolMinTick = syminfo.mintick
string exchangeId = syminfo.prefix
string entryName = strategy.position_entry_name
bool ignoreNewSignal = currentPositionSize != 0

// Trailing stop trigger checks.
float entryPriceLongDiff = 1 - (currentPositionEntryPrice[1] / high)
float entryPriceShortDiff = 1 - (low / currentPositionEntryPrice[1])
bool trailingStopLongTrigger = entryPriceLongDiff > trailingStopTriggerPercent
bool trailingStopShortTrigger = entryPriceShortDiff > trailingStopTriggerPercent

// Trailing stop calculation base price.
float baseStopPrice = trailingStopLongTrigger or trailingStopShortTrigger ? close : currentPositionEntryPrice

// Due to TradingView limitations to integrate external signals from financial astrology ML models
// we needed to hardcode the buy/sell signals here in the code as PineScript array with start Date index at 2021-01-01
// and end index at 2022-12-31, this signal is based on the correlation of planets cycles and price trend for each research
// asset historical data detected through machine learning methods, once models are trained can forecast future daily trend.
varip int[] ADA = array.from(
	 1,0,1,1,1,1,1,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,0,1,0,0,1,1,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,1,1,0,0,1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,1,1,1,0,0,0,1,1,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,1,1,1,1,0,1,0,1,0,0,0,1,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,0,
	 1,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,1,0,1,0,1,1,0,0,0,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,1,1,0,1,1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0,1,1,0,1,0,1,1,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,0,0,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,0,0,0,0,1,0,0,0,0,1,1,1,1,0,0,1,1,0,0,1,0,0,1,1,0,1,1,1,0,0,0,1,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0,1,0,1,1,1,0,1,1,1,1,1,0,0,1,0,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,1,1,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,
	 0,0,1,1,1,1,1,1,0,1,0,1,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,1,1,1,0,1,1,0,0,0,1,1,0,1,0,1,1,1,0,0,1,0,0,1,1,0,1,1,1,0,0,1,1,1,0,0,1,1,1,1,1,0,0)

var mlSignal = if (syminfo.ticker == "ADAUSDT")
    ADA
else if (syminfo.ticker == "BATUSDT")
    BAT
else if (syminfo.ticker == "BNBUSDT")
    BNB
else if (syminfo.ticker == "BTCUSDT")
    BTC
else if (syminfo.ticker == "DASHUSDT")
    DASH
else if (syminfo.ticker == "EOSUSDT")
    EOS
else if (syminfo.ticker == "ETCUSDT")
    ETC
else if (syminfo.ticker == "ETHUSDT")
    ETH
else if (syminfo.ticker == "LINKUSDT")
    LINK
else if (syminfo.ticker == "LTCUSDT")
    LTC
else if (syminfo.ticker == "XLMUSDT")
    XLM
else if (syminfo.ticker == "XRPUSDT")
    XRP
else if (syminfo.ticker == "ZECUSDT")
    ZEC
else if (syminfo.ticker == "ZRXUSDT")
    ZRX
else
    array.from(0)
    
scaleBetween(unscaledNum, minAllowed, maxAllowed, min, max) =>
  (maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed

calculateDayBarsCount() =>
    // Daily resolution
    if (timeframe.period == "D")
        1
    // 4 hours
    else if (timeframe.period == "240")
        6
    // 3 hours
    else if (timeframe.period == "180")
        8
    // 2 hours
    else if (timeframe.period == "120")
        12
    // 1 hour
    else if (timeframe.period == "60")
        24
    // 45 minutes
    else if (timeframe.period == "45")
        32
    // 30 minutes
    else if (timeframe.period == "30")
        48
    // 15 minutes
    else if (timeframe.period == "15")
        96
    // 10 minutes
    else if (timeframe.period == "10")
        144
    // 5 minutes
    else if (timeframe.period == "5")
        288
    // For other resolutions don't plot future predictions.
    else
        0

calculateWeekBarsCount(numWeeks) =>
    dayBarsCount = calculateDayBarsCount()
    numWeeks * 7 * dayBarsCount

calculateCandleTimeDiff(futureWeekOffset) =>
    // 2021-01-01 00:00 ML signal day time serie start.
    leadShiftSeconds = leadShiftHours * 3600
    futureOffsetSeconds = calculateWeekBarsCount(futureWeekOffset) > 0
         ? futureWeekOffset * 7 * 86400
         : 0
    referenceUnixTime = 1609459200 - futureOffsetSeconds - leadShiftSeconds
    candleUnixTime = (time / 1000) + 1
    timeDiff = candleUnixTime - referenceUnixTime
    iff(timeDiff < 0, na, timeDiff)

getMLSignalCandleIndex(futureWeekOffset) =>
    timeDiff = calculateCandleTimeDiff(futureWeekOffset)
    // Day index, days count elapsed from reference date.
    candleIndex = floor(timeDiff / 86400)
    iff(candleIndex < 0, na, candleIndex)

getMLSignal(futureWeekOffset) =>
    // Map array data items indexes to candles.
    int candleIndex = getMLSignalCandleIndex(futureWeekOffset)
    int itemsCount = array.size(mlSignal)
    // Return na for candles where indicator data is not available.
    int index = candleIndex > itemsCount ? na : candleIndex
    signal = if (index >= 0 and itemsCount > 1)
        array.get(mlSignal, index)
    else
        na

calculateSmoothSignal(mlSignalSerie) =>
    int smoothPeriod = calculateWeekBarsCount(1)
    if (smoothPeriod > 0)
        sma(mlSignalSerie, smoothPeriod)
    else
        na

getCurrentDayMLSignal(mlSignal, dayOffset) =>
    futureWeekBarsOffset = calculateWeekBarsCount(futureWeeksNumber)
    dayBarsOffset = calculateDayBarsCount() * dayOffset
    dayIndex = futureWeekBarsOffset - dayBarsOffset
    mlSignal[dayIndex]

// Compose signal time serie from array data, N weaks lead signals for future projection (plot offset).
int mlSignalLeadSerie = getMLSignal(futureWeeksNumber)
// Scale smooth signal into price -/+ 20% price range.
float mlSignalSerieSmooth = scaleBetween(calculateSmoothSignal(mlSignalLeadSerie),  0.8, 1.2, 0, 1)
int todayMLSignal = getCurrentDayMLSignal(mlSignalLeadSerie, 0)
int tomorrowMLSignal = getCurrentDayMLSignal(mlSignalLeadSerie, 1)

calculateFastMA() =>
    sma(hl2, fastMAPeriod)

calculateSlowMA() =>
    src = hl2
    smma = 0.0
    smma := na(smma[1]) ? sma(src, slowMAPeriod) : (smma[1] * (slowMAPeriod - 1) + src) / slowMAPeriod
    // vwma(hl2, slowMAPeriod)

currentDate() =>
    tostring(year) + '-' + tostring(month) + '-' + tostring(dayofmonth)
    
currentTime() =>
    tostring(hour) + ':' + tostring(minute) + ":" + "00"
    
currentTimezone() =>
    syminfo.timezone

composeSignalData(action, side, type) =>
    string skipProcessingFiltersString = skipProcessingFilters ? "true" : "false"
    string signalData = '{' +
         '"date":"' + currentDate() + '"' + "," +
         '"hour":"' + currentTime() + '"' + "," +
         '"timezone":"' + currentTimezone() + '"' + "," +
         '"orderType":"' + orderType + '"' + "," +
         '"action":"' + action + '"' + "," +
         '"side":"' + side + '"' + "," +
         '"symbolCode":"' + positionSymbol + '"' + "," +
         '"symbolId":"' + positionSymbolId + '"' + "," +
         '"symbolMinTick":' + tostring(positionSymbolMinTick) + "," +
         '"exchangeId":"' + exchangeId + '"' + "," +
         '"signalPrice":' + tostring(open) + "," +
         '"indicatorType":"' + type + '"' + "," +
         '"indicatorPeriod":' + tostring(masterCycleLength) + "," +
         '"trailingStopTriggerPercent":' + tostring(trailingStopTriggerPercent * 100) + "," +
         '"trailingStopPercent":' + tostring(trailingStopPercent * 100) + "," +
         '"trailingStopLongPercent":' + tostring(trailingStopPercent * 100) + "," +
         '"stopLossPercent":' + tostring(stopLossPercent * 100) + "," +
         '"skipProcessingFilters":' + skipProcessingFiltersString + "," +
         '"providerEnvKey":"' + zignalyProviderEnvKey + '"' +
         '}'

entryLongPosition(type) =>
    string alertMessageEntry = composeSignalData("entry", "long", type)
    strategy.entry("long_entry", strategy.long, comment=type + "EntryLong",
         alert_message=alertMessageEntry)

entryShortPosition(type) =>
    string alertMessageEntry = composeSignalData("entry", "short", type)
    strategy.entry("short_entry", strategy.short, comment=type + "EntryShort",
         alert_message=alertMessageEntry)
    
closeLongPosition(type) =>
    string alertMessage = composeSignalData("exit", "long", type)
    bool executeExit = ignoreEarlyReverseSignal ? (entryPriceShortDiff >= stopLossPercent or entryPriceLongDiff >= trailingStopTriggerPercent) : true
    if (executeExit)
        strategy.close("long_entry", comment= type + "ExitLong", alert_message=alertMessage)

closeShortPosition(type) =>
    string alertMessage = composeSignalData("exit", "short", type)
    bool executeExit = ignoreEarlyReverseSignal ? (entryPriceLongDiff >= stopLossPercent or entryPriceShortDiff >= trailingStopTriggerPercent) : true
    if (executeExit)
        strategy.close("short_entry", comment=type + "ExitShort", alert_message=alertMessage)

// Calculate long trailing stop.
calculateTrailingStopLong() =>
    longStopPrice = 0.0
    stopFactor = trailingStopLongTrigger ? trailingStopPercent : stopLossPercent
    longStopPrice := if (currentPositionSize > 0)
        stopValue = baseStopPrice * (1 - stopFactor)
        max(stopValue, longStopPrice[1])
    else
        0
    longStopPrice

// Calculate short trailing stop.
calculateTrailingStopShort() =>
    shortStopPrice = 0.0
    stopFactor = trailingStopShortTrigger ? trailingStopPercent : stopLossPercent
    shortStopPrice := if (currentPositionSize < 0)
        stopValue = baseStopPrice * (1 + stopFactor)
        min(stopValue, shortStopPrice[1])
    else
        9999999
    shortStopPrice

checkMACrossUpper(fastMAValues, slowMAValues) =>
    bool maCross = crossover(fastMAValues, slowMAValues)
    int underCrossConsolidationPeriod = barssince(crossunder(fastMAValues, slowMAValues))
    bool minCrossConsolidationPass = underCrossConsolidationPeriod >= minCrossConsolidationPeriod
    bool mlTrendLong = todayMLSignal == 1 and tomorrowMLSignal >= 1

    if (exitOnReverseSignal and maCross)
        closeShortPosition("MA")

    if (enableEntryLongOrder and maCross and minCrossConsolidationPass and mlTrendLong)
        if (not ignoreNewSignal)
            entryLongPosition("MA")

checkMACrossLower(fastMAValues, slowMAValues) =>
    bool maCross = crossunder(fastMAValues, slowMAValues)
    int overCrossConsolidationPeriod = barssince(crossover(fastMAValues, slowMAValues))
    bool minCrossConsolidationPass = overCrossConsolidationPeriod >= minCrossConsolidationPeriod
    bool mlTrendShort = todayMLSignal == 0 and tomorrowMLSignal == 0

    if (exitOnReverseSignal and maCross)
        closeLongPosition("MA")
    
    if (enableEntryShortOrder and maCross and minCrossConsolidationPass and mlTrendShort)
        if (not ignoreNewSignal)
            entryShortPosition("MA")

// Strategy MAs line plots.
fastMAValues = calculateFastMA()
slowMAValues = calculateSlowMA()
plot(fastMAValues, color=color.lime, style=plot.style_line, linewidth=3)
plot(slowMAValues, color=color.orange, style=plot.style_line, linewidth=2)

checkMACrossUpper(fastMAValues, slowMAValues)
checkMACrossLower(fastMAValues, slowMAValues)

// Plot trailing stop price marks.
longStopPrice = calculateTrailingStopLong()
plot(series=(currentPositionSize > 0 and plotTrailingStop) ? longStopPrice: na,
     color=color.fuchsia, style=plot.style_cross,
     linewidth=2, title="Long Trail Stop")

shortStopPrice = calculateTrailingStopShort()
plot(series=(currentPositionSize < 0 and plotTrailingStop) ? shortStopPrice : na,
     color=color.fuchsia, style=plot.style_cross,
     linewidth=2, title="Short Trail Stop")

// ISSUE NOTE: When strategy.exit is invoked through a function the alert_message 
// results in empty data. Keep the call at main script level.
if (currentPositionSize > 0)
    string alertMessage = composeSignalData("exit", "long", "SL")
    strategy.exit("long_exit", "long_entry", comment="TSLExitLong",
         alert_message=alertMessage, stop=longStopPrice)

// Submit exit orders for short position trailing stop.
if (currentPositionSize < 0)
    string alertMessage = composeSignalData("exit", "short", "SL")
    strategy.exit("short_exit", "short_entry", comment="TSLExitShort",
         alert_message=alertMessage, stop=shortStopPrice)

// Thanks to "Sol" trader that contributed the idea of rescaling ML daily trend signal to price.
realOHLC = avg(open, high, low, close)
priceSignalSmoothPeriod = calculateDayBarsCount() * 2
smoothRealPrice = priceSignalSmoothPeriod > 0 ? sma(realOHLC, priceSignalSmoothPeriod) : na
priceSignal = smoothRealPrice * mlSignalSerieSmooth

int plotOffset = calculateWeekBarsCount(futureWeeksNumber)
plot(priceSignal, color=color.aqua, style=plot.style_line, linewidth=2, offset=plotOffset)
//plot(todayMLSignal, color=color.silver, style=plot.style_cross, linewidth=1)

// Mark future predictions boundary.
bgcolor(barstate.islast ? color.new(color.silver, 60) : na)