本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Skyrexio
//@version=6
//_______ <licence>
strategy(title = "Triple CCI Strategy MFI Confirmed [Skyrexio]",
shorttitle = "Triple CCI",
overlay = true,
format = format.inherit,
pyramiding = 1,
calc_on_order_fills = false,
calc_on_every_tick = false,
default_qty_type = strategy.percent_of_equity,
default_qty_value = 50,
initial_capital = 10000,
currency = currency.NONE,
commission_type = strategy.commission.percent,
commission_value = 0.1,
slippage = 5,
use_bar_magnifier = true)
//_______ <constant_declarations>
var const color skyrexGreen = color.new(#2ECD99, 0)
var const color skyrexGray = color.new(#F2F2F2, 0)
var const color skyrexWhite = color.new(#FFFFFF, 0)
//________<variables declarations>
var float stopLossLevel = na
var float takeProfitLevel = na
var float tralingProfitActivationLevel = na
//_______ <inputs>
// Trading bot settings
sourceUuid = input.string(title = "sourceUuid:", defval = "yourBotSourceUuid", group = "🤖Trading Bot Settings🤖")
secretToken = input.string(title = "secretToken:", defval = "yourBotSecretToken", group = "🤖Trading Bot Settings🤖")
// Trading period settings
lookBackPeriodStart = input.time(title = "Trade Start Date/Time", defval = timestamp('2023-01-01T00:00:00'), group = "🕐Trading Period Settings🕐")
lookBackPeriodStop = input.time(title = "Trade Stop Date/Time", defval = timestamp('2025-01-01T00:00:00'), group = "🕐Trading Period Settings🕐")
// Strategy settings
stopLossAtrNum = input.float(defval = 1.75, title = "ATR Stop Loss", step = 0.25, group = "📈Strategy settings📈")
tralingProfitActivationNum = input.float(defval = 2.25, title = "ATR Traling Profit Activation Level", step = 0.25, group = "📈Strategy settings📈")
cciFastPeriod = input.int(title = "CCI Fast Length", defval = 14, minval = 1, group = "📈Strategy settings📈")
cciMiddlePeriod = input.int(title = "CCI Middle Length", defval = 25, minval = 1, group = "📈Strategy settings📈")
cciSlowPeriod = input.int(title = "CCI Slow Length", defval = 50, minval = 1, group = "📈Strategy settings📈")
MFIlength = input.int(title = "MFI Length", defval=14, minval=1, maxval=2000, group = "📈Strategy settings📈")
EMaLength = input.int(50, minval = 10, title = "EMA Length", group = "📈Strategy settings📈")
trailingEmaLength = input.int(20, minval = 10, title = "Trailing EMA Length", group = "📈Strategy settings📈")
//_______ <function_declarations>
//_______ <calculations>
//Calculating fast, middle and slow CCI
fastCci = ta.cci(hlc3, cciFastPeriod)
middleCci = ta.cci(hlc3, cciMiddlePeriod)
slowCci = ta.cci(hlc3, cciSlowPeriod)
//Calculating Money Flow Index (MFI)
mfi = ta.mfi(hlc3, MFIlength)
//Average true range (ATR) calculations
ATR = ta.atr(14)
//Calculating EMA
trailingEma = ta.ema(close, trailingEmaLength)
//Calculating exponential moving average
ema = ta.ema(close, EMaLength)
//Calculating stop loss level
stopLossLevel := strategy.position_avg_price - stopLossAtrNum * ATR
//Calculating traling profit activation level
tralingProfitActivationLevel := strategy.position_avg_price + tralingProfitActivationNum * ATR
//Calculating dynamic traling take profit level
condition1 = ta.barssince(strategy.opentrades == 1 and strategy.opentrades[1] == 0) < ta.barssince((high[1] < tralingProfitActivationLevel[1] or na(tralingProfitActivationLevel[1])) and high > tralingProfitActivationLevel)
condition2 = na(ta.barssince((high[1] < tralingProfitActivationLevel[1] or na(tralingProfitActivationLevel[1])) and high > tralingProfitActivationLevel))
if strategy.opentrades == 0 or condition1 or condition2
takeProfitLevel := na
else
takeProfitLevel := trailingEma
//_______ <strategy_calls>
//Defining long condition
longCondition = ta.crossover(fastCci, 0) and close > ema and middleCci > 0 and slowCci > 0 and mfi > 50
//Defining trade close condition
closeCondition = close < takeProfitLevel or low <= stopLossLevel
//Strategy entry
//Scrip places the stop order at the upFractalActivationLevel if longCondition is true
if (longCondition and time >= lookBackPeriodStart and time <= lookBackPeriodStop)
strategy.entry(id = "entry1", direction = strategy.long, alert_message = '{\n"base": "' + syminfo.basecurrency + '",\n"quote": "' + syminfo.currency + '",\n"position": "entry1",\n"price": "' + str.tostring(close) + '",\n"sourceUuid": "' + sourceUuid + '",\n"secretToken": "' + secretToken + '",\n"timestamp": "' + str.tostring(timenow) + '"\n}')
//Strategy exit
if (closeCondition)
strategy.close(id = "entry1",immediately = true , alert_message = '{\n"base": "' + syminfo.basecurrency + '",\n"quote": "' + syminfo.currency + '",\n"position": "close",\n"price": "' + str.tostring(close) + '",\n"sourceUuid": "' + sourceUuid + '",\n"secretToken": "' + secretToken + '",\n"timestamp": "' + str.tostring(timenow) + '"\n}')
//_______ <visuals>
pricePlot = plot(close, title="Price", color=color.new(color.blue, 100))
emaPlot = plot(takeProfitLevel, title="EMA", color=skyrexGreen, style=plot.style_linebr, linewidth = 3)
plot(not na(takeProfitLevel) and na(takeProfitLevel[1]) ? takeProfitLevel : na, title="EMA", color=skyrexGreen, join = false, style=plot.style_circles, linewidth = 6)
fill(pricePlot, emaPlot, color=color.new(skyrexGreen, 70))
plotshape(not na(takeProfitLevel) and na(takeProfitLevel[1]) ? true: false,text="Trailing Activated",size=size.small,offset=0,color=color.new(skyrexGreen, 0),textcolor=skyrexWhite,style=shape.triangleup,location=location.belowbar)
//_______ <alerts>