It is fully configurable, which means you can set the bars for calculation, the offset and sources for trigger and calculation.
The original purpose for me was to send a command to my bot. If you like it please comment and check out my other scripts.
I created a script which is working flawlessly on Tradingview so I wanted to create alert notifications. Buy order is coming after certain conditions get satisfied and I'm creating an alter through alertcondition() function, as follows
Buy = condition1 and condition2 and testrange
alertcondition(BuyCond, title = "Buy Signal", message = "Buy Signal Alert")
I'm stuck in the sell order alert notification as I'm using strategy.exit() which has stop, trail_points and trail_offset. So the strategy either hits stop-loss or it starts trailing from a certain percentage with an offset.
strategy.exit("TP/SL", "Enter Long", stop=StopLoss * (1 - sl_inp),
trail_points = close * TrailPer / syminfo.mintick,
trail_offset = close * TrailOffset / syminfo.mintick)
I can't use alertfunction() here as the trailing stoploss and offset are both defined in strategy.exit function. So how can I set up an alert notification for the exit? Please help!
However, by adding this code to my simple script I get an error message "Add to Chart operation failed, reason: The script must have one study() or strategy() function call"
I'm new to pinescript, trying to learn step by step so I'd much appreciate some help :)
I believe there should be an exit() command in order to backtest with the trailing stop, right?
Here is my code, a simple EMA crossover.. I
short_ema = ema(close, 9)
long_ema = ema(close, 30)
plot(short_ema, color =red)
plot(short_ema, color =green)
entry() => crossover( short_ema, long_ema)
exit() => crossunder( short_ema, long_ema)
strategy.entry(id = "long_ma", long = true, when = entry())
strategy.close(id = "long_ma", when = exit())