有没有办法允许 strategy.risk.max_intraday_filled_orders() 函数进入 IF 语句?
Is there a way to allow for strategy.risk.max_intraday_filled_orders() Function into an IF statement?
我试图每天只触发一笔交易。但是,当我的长条件为真时,无论脚本中是否具有 strategy.risk.max_intraday_filled_orders() 函数,警报始终会激活。
我想知道是否有办法将此函数合并到 IF 语句中。
完整代码见下:
//@version=4
strategy("Test" , shorttitle="Test - V2", overlay=true, initial_capital =100000, default_qty_value = 8000, pyramiding =0, default_qty_type = strategy.fixed, currency=currency.USD)
//Settings
pc_prefix = input(title="Symbol Prefix", defval="", type=input.string, group="Settings")
//Generate Alert String
symbol = pc_prefix + syminfo.ticker
pc_entry_alert(direction, sl, tp) =>
direction + "," + symbol + "," + "sl=" +tostring(sl) + ",tp=" + tostring(tp)
// Get user input
pipStop = input(title="Pip Stop Amount", defval = 10.0, type=input.float, step=1, group ="PIP Values")
pipTP2 = input(title="Pip Take Profit 2", defval = 20.0, type=input.float, step=1, group="PIP Values")
//Strategy maximum number of intraday trades
strategy.risk.max_intraday_filled_orders(2)
//Getting Previous Session High/Low
rp_function(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? 1:0])
dHigh = rp_function(syminfo.ticker, "D", high[1])
dLow = rp_function(syminfo.ticker, "D", low[1])
plot(dHigh, color=color.blue)
plot(dLow, color=color.orange)
//Defining the Trade
goLongCondition1 = close> dHigh
// Entry Condition for setup
validLong = strategy.position_size == 0 and goLongCondition1
// Calculate our stop distance & size for the current bar
longStopPrice = close - pipStop
longStopDistance = close - longStopPrice
longTargetPrice2 = close + pipTP2
longEntryPrice = validLong? close:na
// Save trade stop & target & position size if a valid setup is detected
var tradeLongStopPrice = 0.0
var tradeLongTargetPrice2 = 0.0
var tradeLongEntryPrice = 0.0
// Detect valid long setups & trigger alert
if validLong
tradeLongStopPrice := longStopPrice
tradeLongTargetPrice2 := longTargetPrice2
tradeLongEntryPrice := longEntryPrice
//Alerts
if validLong
alert_string = pc_entry_alert("buy",tradeLongStopPrice, tradeLongTargetPrice2)
alert(alert_string, alert.freq_all)
strategy.entry(id="Long", long=strategy.long)
// Exit trades whenever our stop or target is hit
strategy.exit(id="LTP1", from_entry="Long", limit=tradeLongTargetPrice2, stop=tradeLongStopPrice, when=strategy.position_size > 0, qty_percent = 100)
//Strategy maximum number of intraday trades
strategy.risk.max_intraday_filled_orders(2)
当您设置提醒时,select“仅订单成交”。
否则,每次 validLong
变为 true
时,您都会收到警报,因为您在那个 if 块中使用了 alert()
函数。
编辑:
您可以使用 strategy.entry()
和 strategy.exit()
调用的 alert_message
属性。这样,您只会在执行这些 strategy
调用时收到警报消息。
改变这个:
//Alerts
if validLong
alert_string = pc_entry_alert("buy",tradeLongStopPrice, tradeLongTargetPrice2)
alert(alert_string, alert.freq_all)
strategy.entry(id="Long", long=strategy.long)
对此:
alert_string = pc_entry_alert("buy",tradeLongStopPrice, tradeLongTargetPrice2)
strategy.entry(id="Long", long=strategy.long, when=validLong, alert_message=alert_string)
如果你想在 strategy.exit()
调用时有不同的消息,你可以定义一个新字符串并使用 strategy.exit()
的 alert_message
属性。
我试图每天只触发一笔交易。但是,当我的长条件为真时,无论脚本中是否具有 strategy.risk.max_intraday_filled_orders() 函数,警报始终会激活。 我想知道是否有办法将此函数合并到 IF 语句中。
完整代码见下:
//@version=4
strategy("Test" , shorttitle="Test - V2", overlay=true, initial_capital =100000, default_qty_value = 8000, pyramiding =0, default_qty_type = strategy.fixed, currency=currency.USD)
//Settings
pc_prefix = input(title="Symbol Prefix", defval="", type=input.string, group="Settings")
//Generate Alert String
symbol = pc_prefix + syminfo.ticker
pc_entry_alert(direction, sl, tp) =>
direction + "," + symbol + "," + "sl=" +tostring(sl) + ",tp=" + tostring(tp)
// Get user input
pipStop = input(title="Pip Stop Amount", defval = 10.0, type=input.float, step=1, group ="PIP Values")
pipTP2 = input(title="Pip Take Profit 2", defval = 20.0, type=input.float, step=1, group="PIP Values")
//Strategy maximum number of intraday trades
strategy.risk.max_intraday_filled_orders(2)
//Getting Previous Session High/Low
rp_function(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? 1:0])
dHigh = rp_function(syminfo.ticker, "D", high[1])
dLow = rp_function(syminfo.ticker, "D", low[1])
plot(dHigh, color=color.blue)
plot(dLow, color=color.orange)
//Defining the Trade
goLongCondition1 = close> dHigh
// Entry Condition for setup
validLong = strategy.position_size == 0 and goLongCondition1
// Calculate our stop distance & size for the current bar
longStopPrice = close - pipStop
longStopDistance = close - longStopPrice
longTargetPrice2 = close + pipTP2
longEntryPrice = validLong? close:na
// Save trade stop & target & position size if a valid setup is detected
var tradeLongStopPrice = 0.0
var tradeLongTargetPrice2 = 0.0
var tradeLongEntryPrice = 0.0
// Detect valid long setups & trigger alert
if validLong
tradeLongStopPrice := longStopPrice
tradeLongTargetPrice2 := longTargetPrice2
tradeLongEntryPrice := longEntryPrice
//Alerts
if validLong
alert_string = pc_entry_alert("buy",tradeLongStopPrice, tradeLongTargetPrice2)
alert(alert_string, alert.freq_all)
strategy.entry(id="Long", long=strategy.long)
// Exit trades whenever our stop or target is hit
strategy.exit(id="LTP1", from_entry="Long", limit=tradeLongTargetPrice2, stop=tradeLongStopPrice, when=strategy.position_size > 0, qty_percent = 100)
//Strategy maximum number of intraday trades
strategy.risk.max_intraday_filled_orders(2)
当您设置提醒时,select“仅订单成交”。
否则,每次 validLong
变为 true
时,您都会收到警报,因为您在那个 if 块中使用了 alert()
函数。
编辑:
您可以使用 strategy.entry()
和 strategy.exit()
调用的 alert_message
属性。这样,您只会在执行这些 strategy
调用时收到警报消息。
改变这个:
//Alerts
if validLong
alert_string = pc_entry_alert("buy",tradeLongStopPrice, tradeLongTargetPrice2)
alert(alert_string, alert.freq_all)
strategy.entry(id="Long", long=strategy.long)
对此:
alert_string = pc_entry_alert("buy",tradeLongStopPrice, tradeLongTargetPrice2)
strategy.entry(id="Long", long=strategy.long, when=validLong, alert_message=alert_string)
如果你想在 strategy.exit()
调用时有不同的消息,你可以定义一个新字符串并使用 strategy.exit()
的 alert_message
属性。