简体   繁体   中英

Pinescript strategy alert not triggered

I have a very simple strategy written for in PineScript for TradingView The strategy does show Buy and Sell signals on chart, however the alert are not being triggered for some reason.

Here is the code and I have also attached an image of the Buy/Sell on chart and the alert setup. If you see something I am missing please let me know @PineCoders-LucF @PineCoders

//@version=4

strategy("PreHaltAlgo", overlay=true, pyramiding = 1, calc_on_every_tick = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 2, currency = currency.USD)

stratbull = input(title="Enter longs ?", group = "General Settings", type = input.bool, defval=true)
stratbear = input(title="Enter shorts ?", type = input.bool, defval=false)

stratyear = input(2016, title = "Strategy Start Year")
stratmonth = input(1, title = "Strategy Start Month")
stratday = input(1, title = "Strategy Start Day")
stratstart = timestamp(stratyear,stratmonth,stratday,0,0)

timebull = stratbull and time > stratstart
timebear = stratbear and time > stratstart

tier1 = security(syminfo.tickerid,"D",close[1]) >= 0.75 and security(syminfo.tickerid,"D",close[1]) <= 3.00
tier2 = security(syminfo.tickerid,"D",close[1]) > 3.00
perc_change = ((high[0] - open[0]) / open[0]) * 100
limit_up = perc_change > 9.5

min_vol = security(syminfo.tickerid,"D",volume[0]) > sma(security(syminfo.tickerid,"D",volume[0]),30)

// longCondition = limit_up  

if timebull and limit_up and min_vol
    strategy.entry("Long", true, alert_message="{\"ticker\": \"{{ticker}}\", \"action\": \"buy\", \"quantity\":\"100\"}")
if strategy.position_size > 0    
    strategy.close("Long", when = open[0], alert_message="{\"ticker\": \"{{ticker}}\", \"action\": \"sell\", \"quantity\":\"100\"}")

图 1

图 2

Do you also use {{strategy.order.alert_message}} in the message? I'm experiencing the same issues with a strategy. To be honest, I can't seem to figure it out.

Did you solve it already by any chance?

Try with version5 of Pinescript, the alert from the strategy are better handled

I guess the problem is due to repaint problem. This could happen because you are using security method that evaluate real time data. this could fix the problem: security(syminfo.tickerid,"D",volume[barstate.isrealtime?1:0]) and also you could protect the entry by check: barstate.isconfirmed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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