简体   繁体   English

strategy.entry 上的 Tradingview 松树脚本警报条件

[英]Tradingview pine script alertcondition on strategy.entry

I have problem with alertcondition in strategy.我对策略中的警报条件有alertcondition

I want to have alert condition when I go LONG and exit LONG.当我 go LONG 并退出 LONG 时,我想有警报条件。

alert signals like this像这样的警报信号

I dont know how to write a script in strategy.我不知道如何编写策略脚本。

my script:我的脚本:

strategy.entry('LONG1', strategy.long, when=testPeriod() and jlong1 and jtest1 and jlong1_5min and jtest_rsi1)

alertcondition(condition=??????, title='LONG')

stopPer = input(1.0, title='Stop Loss %') / 100
takePer = input(1.0, title='Take Profit %') / 100
trail_inp = input(1.0, title='Trailing %') / 100


longStop = strategy.position_avg_price * (1 - stopPer)
longTake = strategy.position_avg_price * (1 + takePer)

trail_level = strategy.position_avg_price * (1 - trail_inp)
trail_offset1 = int(close * trail_inp / syminfo.mintick)


if strategy.position_size > 0
    strategy.exit(id='Close Long1', stop=longStop, trail_price=longTake, 
trail_offset=trail_offset1)
alertcondition(condition=??????, title='exitLONG')

You actually don't need the alertcondition() function.您实际上不需要alertcondition() function。 Both strategy.entry() and strategy.exit() functions have the alert_message parameter which you can use. strategy.entry()strategy.exit()函数都有你可以使用的alert_message参数。

More information here and here .更多信息在这里这里

Here is an example:这是一个例子:

//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)

longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long, alert_message="Going Long")

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short, alert_message="Going Short")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM