← กลับหน้ารายการ

Moon Phases Long/Short Strategy

Strategy ผู้เขียน: saurabhmishrra11 Profit Factor: 1.613

ลิงก์ TradingView

เปิดใน TradingView

Equity Chart

Equity chart

เปิดรูปเต็มขนาด

คำอธิบาย

This is an experiment of Moon Phases, likely buy when full moon and sell when new moon with few changes, like it would buy a day ahead or sometimes sell a day post these events, with Stop loss and take profits, 50% profitable so sounds good to me
Long only good for bitcoin gold, both modes(L+S) better for stocks and alt coins

รูป Preview

Preview

Pine Script Source

//@version=5
strategy("Moon Phases Long/Short Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === Input Settings ===
tradingMode = input.string(title="Trading Mode", defval="Long Only (Research)", options=["Long Only (Research)", "Long + Short (Full Cycle)"])
stopLossPercent = input.float(title="Stop Loss %", defval=5.0, minval=1.0, maxval=20.0)
takeProfitPercent = input.float(title="Take Profit %", defval=10.0, minval=2.0, maxval=50.0)

// === Moon Phase Calculation ===
lunarCycleDays = 29.530588853
referenceNewMoon = timestamp(2000, 1, 6, 0, 0, 0)
daysSinceReference = (time - referenceNewMoon) / (24 * 60 * 60 * 1000)
currentLunarDay = math.floor((daysSinceReference % lunarCycleDays) + 0.5)

// Determine moon phase
isNewMoon = currentLunarDay >= 0 and currentLunarDay <= 1
isFullMoon = currentLunarDay >= 13 and currentLunarDay <= 15
isFirstQuarter = currentLunarDay >= 6 and currentLunarDay <= 8
isLastQuarter = currentLunarDay >= 20 and currentLunarDay <= 22

// Detect phase changes
newMoonStart = isNewMoon and not isNewMoon[1]
fullMoonStart = isFullMoon and not isFullMoon[1]

// Moon phase name
var string moonPhaseName = na
if isNewMoon
    moonPhaseName := "New Moon"
else if isFullMoon
    moonPhaseName := "Full Moon"
else if isFirstQuarter
    moonPhaseName := "First Quarter"
else if isLastQuarter
    moonPhaseName := "Last Quarter"
else if currentLunarDay < 7
    moonPhaseName := "Waxing Crescent"
else if currentLunarDay < 13
    moonPhaseName := "Waxing Gibbous"
else if currentLunarDay < 20
    moonPhaseName := "Waning Gibbous"
else
    moonPhaseName := "Waning Crescent"

// === Entry/Exit Conditions ===
longCondition = fullMoonStart
shortCondition = newMoonStart

// === Stop Loss and Take Profit ===
var float longSL = na
var float longTP = na
var float shortSL = na
var float shortTP = na

if longCondition
    longSL := close * (1 - stopLossPercent / 100)
    longTP := close * (1 + takeProfitPercent / 100)

if shortCondition
    shortSL := close * (1 + stopLossPercent / 100)
    shortTP := close * (1 - takeProfitPercent / 100)

// === Execute Trades Based on Mode ===
if tradingMode == "Long Only (Research)"
    // Original research strategy - Long only
    if longCondition
        strategy.entry("Long", strategy.long)
        strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)
    
    if shortCondition and strategy.position_size > 0
        strategy.close("Long", comment="New Moon Exit")

else if tradingMode == "Long + Short (Full Cycle)"
    // Full cycle - always in position
    if longCondition
        if strategy.position_size < 0
            strategy.close("Short", comment="Close Short")
        strategy.entry("Long", strategy.long)
        strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)
    
    if shortCondition
        if strategy.position_size > 0
            strategy.close("Long", comment="Close Long")
        strategy.entry("Short", strategy.short)
        strategy.exit("Exit Short", from_entry="Short", stop=shortSL, limit=shortTP)

// === Visual Elements ===
bgcolor(isNewMoon ? color.new(color.blue, 90) : na, title="New Moon BG")
bgcolor(isFullMoon ? color.new(color.yellow, 90) : na, title="Full Moon BG")

plotshape(newMoonStart, style=shape.circle, location=location.bottom, color=color.blue, size=size.tiny, title="New Moon")
plotshape(fullMoonStart, style=shape.circle, location=location.top, color=color.yellow, size=size.tiny, title="Full Moon")

plotshape(longCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.normal, text="LONG")
plotshape(shortCondition and tradingMode == "Long + Short (Full Cycle)", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal, text="SHORT")

// Plot SL/TP
plot(strategy.position_size > 0 ? longSL : strategy.position_size < 0 ? shortSL : na, "Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr)
plot(strategy.position_size > 0 ? longTP : strategy.position_size < 0 ? shortTP : na, "Take Profit", color=color.lime, linewidth=2, style=plot.style_linebr)

// === Info Table ===
var table info = table.new(position.top_right, 2, 8, bgcolor=color.white, border_width=1)

if barstate.islast
    table.cell(info, 0, 0, "Moon Phase", text_color=color.black, bgcolor=color.gray)
    table.cell(info, 1, 0, moonPhaseName, text_color=color.black)
    
    table.cell(info, 0, 1, "Lunar Day", text_color=color.black)
    table.cell(info, 1, 1, str.tostring(currentLunarDay) + "/29.5", text_color=color.black)
    
    table.cell(info, 0, 2, "Mode", text_color=color.black)
    table.cell(info, 1, 2, tradingMode == "Long Only (Research)" ? "Long Only" : "Long+Short", text_color=color.blue)
    
    table.cell(info, 0, 3, "Position", text_color=color.black)
    posText = strategy.position_size > 0 ? "LONG" : strategy.position_size < 0 ? "SHORT" : "NONE"
    posColor = strategy.position_size > 0 ? color.green : strategy.position_size < 0 ? color.red : color.gray
    table.cell(info, 1, 3, posText, text_color=posColor)
    
    table.cell(info, 0, 4, "Total Trades", text_color=color.black)
    table.cell(info, 1, 4, str.tostring(strategy.closedtrades), text_color=color.black)
    
    table.cell(info, 0, 5, "Win Rate", text_color=color.black)
    wr = strategy.closedtrades > 0 ? (strategy.wintrades / strategy.closedtrades * 100) : 0
    table.cell(info, 1, 5, str.tostring(wr, "#.#") + "%", text_color=color.black)
    
    table.cell(info, 0, 6, "Profit Factor", text_color=color.black)
    pf = strategy.grossprofit > 0 ? (strategy.grossprofit / math.abs(strategy.grossloss)) : 0
    table.cell(info, 1, 6, str.tostring(pf, "#.##"), text_color=color.black)
    
    table.cell(info, 0, 7, "Net Profit", text_color=color.black)
    table.cell(info, 1, 7, str.tostring(strategy.netprofit, "#") + " USD", text_color=strategy.netprofit > 0 ? color.green : color.red)

alertcondition(longCondition, "Full Moon Long", "LONG on Full Moon")
alertcondition(shortCondition, "New Moon Short", "SHORT on New Moon")