Username: Password:

Author Topic: Can someone help code my script to send Buy and sell alerts to GB?  (Read 11776 times)

Offline dhiren

  • Rookie
  • *
  • Posts: 1
    • View Profile
Hi I have a script which seems like it could work very well with tradingview and Gunbot. It does create many trades a day but looks like a safe way to make profits long term. The issue is that the alerts dont seem to relate to the buy and sell signals as the alert setting is a specific tradingview signal. This could help other people as well.

It might just be that i need to code something along the lines of the below for the script:

//alert triggers
alertcondition(histgood[1] and difgood and crossover(macd,micro),"Buying Condition", "BUY_BITTREX_BTC-")
alertcondition(histgood[1] and difgood and crossunder(macd,micro),"Selling Condition", "SELL_BITTREX_BTC-")

Here is the script below:


//@version=2
study("MACDgen", precision=7)
fast = 5, slow = 10
fastMA = ema(close, fast)
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, 9)
micro = sma(macd,2)
hist = macd - signal
plot(hist, title="a", color=hist>0 and hist[0]>hist[1]?#00ff00:hist<=0 and hist[0]<hist[1]?#f72e2e:hist>0 and hist[0]<hist[1]?#008000:hist<0 and hist[0]>hist[1]?#7f0000:white, style=histogram)
plot(macd, title="b", color=red, linewidth=2)
plot(signal, title="c", color=blue, linewidth=2)
plot(micro, title="micro", color=black, linewidth=2)

histgood = false
difgood = false
dif = 0

//Pulling out the average difference between black MACD and blue Signal to use for condition
if (barstate.isnew)
    for i=0 to 50
        dif := dif + abs(signal-micro)
    dif := dif/75

plot(dif,color=green)

if (barssince(cross(macd,micro)) > 2) //check for history of crossing to avoid volatile triggers
    histgood := true
else
    histgood := false
if (abs(signal-micro) > dif) //check for black MACD to have proper distance to the blue Signal, see above
    difgood := true
else
    difgood := false

//display the conditions
plotshape(histgood[1], style=shape.circle, location=location.bottom)
plotshape(difgood, style=shape.xcross, location=location.bottom)
plotshape(histgood[1] and difgood and crossunder(macd,micro), style=shape.arrowdown, location=location.top, color=red)
plotshape(histgood[1] and difgood and crossover(macd,micro), style=shape.arrowup, location=location.top, color=green)

//alert triggers
alertcondition(histgood[1] and difgood and crossover(macd,micro),"Buying Condition", "BUY_BITTREX_BTC-")
alertcondition(histgood[1] and difgood and crossunder(macd,micro),"Selling Condition", "SELL_BITTREX_BTC-")

Offline bkeizer

  • Rookie
  • *
  • Posts: 2
    • View Profile
Re: Can someone help code my script to send Buy and sell alerts to GB?
« Reply #1 on: June 04, 2018, 10:21:45 PM »
Add to Chart operation failed, reason: line 20: mismatched input 'for' expecting 'end of line without line continuation'