0
votes

Hi I'm currently in the process of learning to write a script. Here's a very basic SMA 34/4 crossover script I've done so far. Is somebody able to help me with learning to add the following functions to the script.

  1. Add an alert and indicator to close a short or long trade whenever any candle (price) touches the SMA 34 line?

  2. When a SMA 34/4 Crossover has been executed (a Short Trade condition) add an alert/indicator (Titled “Add”) every time a Green bullish candle has closed.

  3. When a SMA 34/4 Crossunder has been executed (a Long Trade condition) add an alert/indicator (Titled “Add) every time a Red bearish candle has closed.

  4. To used on 15m/30m/1hr/2hr/4hr/1D/1W timeframe charts?

Demo script so far;

strategy("SMA Crossover demo", overlay=true)

shortCondition = crossover(sma(close, 34), sma(close, 4))
if (shortCondition)
    strategy.entry("Sell/Short", strategy.short)

longCondition = crossunder(sma(close, 34), sma(close, 4))
if (longCondition)
    strategy.entry("Buy/Long", strategy.long)
1
This is a very broad question. be specific.Anantha Raju C
Sorry for the broad question. 1. Add a (marker/cross/flag) on the chart with text next to the marker stating “Close Short Trade”whenever a green candle touches the SMA 34 line? 2. Add a (marker/cross/flag) on the chart with text next to the marker stating “Close Long Trade”whenever a red candle touches the SMA 34 line?RFranks
3. When a SMA 34/4 Crossover has been executed (a Short Trade condition) add a (marker/cross/flag) on the chart with text next to the market stating “Add” every time a Green bullish candle has closed. 4. When a SMA 34/4 Crossunder has been executed (a Long Trade condition) add (marker/cross/flag) on the chart with text next to the market stating “Add” every time a Red bearish candle has closed. 5. All markers (Close Short Trade, Close Long Trade and Add) could used on a 15m/30m/1hr/2hr/4hr/1D/1W timeframe chart?RFranks

1 Answers

0
votes

First of all, that you must know is that pine doesn't allow to add an allert from the code. So you have to add it manually.

To implement behaviour of an alert you desire, you can make a variable which would have a value 1 when alert must fire.

A small example:

valToFire = 0
if shortCondition and close > open // and more conditions that you want...
    valToFire := 0 // note an := operator instead of regular =
plot(valToFire)

then you can add manually an alert for this plot