Creating new Pinescript data

Hello Everyone!

I would like to create an alert bot on Tradingview with the following details.

I would like to have a 50 Exponential Moving Average on the chart and I would like to have notification from tradingview when the price is crossing the ema and the next candle is going to make a bullish or bearish engulfing candle pattern.

I have got this far yet:

// Step One: Initial Setting
strategy("SSL Channel and 50 EMA",overlay= true)

// Step Two: Parameter Setting
ma50 = ema(close,50)
bullishEC= close >= open[1] and close[1] < open[1]
bearishEC= close <= open[1] and close[1] > open[1]

//Step Three: Signals

longSignal= (crossover(ma50) and bullishEC)
shortSignal= (crossover(ma50) and bearishEC)


//Step Four: Entries

strategy.entry(id="longPosition", long=true, when=longSignal)
strategy.entry(id="shortPosition",long=false,when=shortSignal)

//Step Five: Alert!

alertcondition(longSignal, title="bull signal", message="long signal detected for{{ticker}}")
alertcondition(shortSignal, title="bear signal", message="short signal detected for{{ticker}}")

When I would like to add this to chart I am getting following errors:

[line 13: Cannot call 'crossover' with arguments (series[float]); available overloads: crossover(series[float], series[float]) => series[bool]; ](https://in.tradingview.com/chart/5E5fO6EQ/#)

[line 14: Cannot call 'crossover' with arguments (series[float]); available overloads: crossover(series[float], series[float]) => series[bool];](https://in.tradingview.com/chart/5E5fO6EQ/#)

Can someone please help me out?

Thank you!

1 Like

Hey @Riki

crossover use two parameters to run the method.
Here is one of the examples from the course:

//DEFINITIONS
shortMa = sma(close, 50)
longMa = sma(close, 200)
longCross = crossover(shortMa, longMa)
shortCross = crossover(longMa, shortMa)

Also here is the documentation for it: https://www.tradingview.com/pine-script-reference/#fun_crossover

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

hey @thecil

Finall got everything, or as I hope I do because if I see the plots what i have entered in tradingview it shows me the entries only I want to see.

My only issue is with the alert now.

Here is what I am having at the moment:

strategy(title="50EMA + SSL Channel",overlay=true)

src = input(close, title="Source")
price = security(syminfo.tickerid, timeframe.period, src)
fiftyMA = ema(close, 50)
bullishEC= close >= open[1] and close[1] < open[1]
bearishEC= close <= open[1] and close[1] > open[1]

longSignal=(cross(price,fiftyMA) and bullishEC)
shortSignal=(cross(price,fiftyMA) and bearishEC)
tradeSignal=(longSignal or shortSignal)
//Plot Signals to chart

plot(price) 
plotshape(longSignal, title="bullish",location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, text="buy")
plotshape(shortSignal, title="bearish",location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, text="sell")

alertcondition(tradeSignal, title="Time to get in", message="50 EMA and SSL Channel Signal detected for {{ticker}}")

If I save this or add this to chart I am getting following error:

[line 21: 'alertcondition()' has no effect inside strategies.](https://in.tradingview.com/chart/5E5fO6EQ/#)

the line 21 is the alertcondition line, this is the only thing I do not understand now.

1 Like

:face_with_monocle:

Please note, that alertcondition does NOT create an alert, it just gives you more options in Create Alert dialog. Also, alertcondition effect is invisible on chart.

https://www.tradingview.com/pine-script-reference/#fun_alertcondition

Maybe you want to try with alert instead of alertcondition.

Carlos Z

Hi again Thecil!

Yes I think I finally made it, took a while but now I understand much more things!

Of course I have tremendous more questions and if I am not boring you with mine I would appreciate your answers going on :slight_smile:

So I was successfully able to make 2 scripts which now almost working correctly.

So let’s say I have a script ready everything is okay. I put it into the tradingview chart, set the alert, everything is set. But what if I want to make another script, is it possible to have two in tradingview (if yes, how?) or not?

Thank you again.

1 Like

From my understanding of the tradingview platform, its one per chart, free account just let you have 1 chart.

Carlos Z