簡體   English   中英

如何根據超趨勢策略和時間開多/空單?

[英]How to open a long/short order based on supertrend strategy and time?

我是 Pine 的新手,正在嘗試回測。

我想編寫一個腳本,我想根據超級趨勢策略在下午 3:00 買入/賣出。

例如,如果 supertrend 建議賣出,它應該僅在下午 3 點觸發帶有 SL/TGT 的賣出訂單。 請幫忙

我會讓你調整下面的 SL/TGT 邏輯你需要使用hour內置變量

//@version=5

// # ========================================================================= #
// #                   |   Strategy  |
// # ========================================================================= #

SystemName = "Supertrend Strategy"
// These values are used both in the strategy() header and in the script's relevant inputs as default values so they match.
// Unless these values match in the script's Inputs and the TV backtesting Properties, results between them cannot be compared.
InitCapital = 1000000
InitPosition = 2
InitCommission = 0.075
InitPyramidMax = 1
CalcOnorderFills = false
ProcessOrdersOnClose = true
CalcOnEveryTick = false
//CloseEntriesRule = "ANY"

strategy(title=SystemName, shorttitle=SystemName, 
 overlay=true, pyramiding=InitPyramidMax, initial_capital=InitCapital, default_qty_type=strategy.fixed, process_orders_on_close=ProcessOrdersOnClose,
 default_qty_value=InitPosition, commission_type=strategy.commission.percent, commission_value=InitCommission, calc_on_order_fills=CalcOnorderFills, 
 calc_on_every_tick=CalcOnEveryTick, 
 precision=6, max_lines_count=500, max_labels_count=500)

[supertrend, direction] = ta.supertrend(3, 10)
plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)

bull = direction < 0 and hour == 15
bear = direction > 0 and hour == 15

if bull
   strategy.entry(id = "Long", direction =  strategy.long, comment = "Long")

else if bear
   strategy.entry(id = "Short", direction =  strategy.short, comment = "Short")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM