TradingView
SeaSide420
24 กันยา 2017 เวลา 20 นาฬิกา 55 นาที

Pivot Profit Taker Strategy 

Bitcoin / U.S. dollarBitstamp

คำอธิบาย

Entry by Pivot reversal. close by profit.
ความคิดเห็น
UnknownUnicorn1072410
Is it possible to set alerts when your indicator printed buy and sell?
joshatt
@TheLewis, I spent a lot of time trying to figure this one out. You can't have alerts on strategies. They have to be on studies. Also, I don't think there's a way to have the strategy.openprofit function recreated in a study. The best you can get is the open/close conditions to trigger an alert with something like this.

long = le ? 1 : 0
plot(long, title="Long")

But I haven't been able to get this to match what the strategy prints as you can see here


@SeaSide420, If you have any suggestions regarding this I'd appreciate it.
joshatt
Here is the study code for PT Long. Once you have this in there you can set an alert for greater than 0.99.

//@version=3
// Pivot Profit Taker Alert Long
// strategy("Pivot Profit Taker Strategy", shorttitle="PPTs < my script2",overlay=true,default_qty_type=strategy.percent_of_equity,max_bars_back=720,default_qty_value=25,calc_on_every_tick=true,pyramiding=2,calc_on_order_fills=true,initial_capital=40000)
study(title="profit taker", shorttitle="PT Long", overlay=false)

StopLoss = input(defval=-5000, title="Stop Loss in $", type=float, step=1)
TargetPoint = input(defval=57, title="Target Point in $", type=float, step=1)
price = input(ohlc4, type=source, title="Price data")
leftBars = input(1, title="Pivot LeftBars")
rightBars = input(1, title="Pivot RightBars")

// Checks for pivot high and low
// pivothigh/low returns a number for where the pivot is or NaN
swh = pivothigh(leftBars, rightBars)
swl = pivotlow(leftBars, rightBars)

swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice
le = false
le := swh_cond ? true : (le and high > hprice ? false : le)

long = le ? 1 : 0
plot(long, title="Long")
cultycove
@joshatt, I'm running into the same issue. Did you find a fix?
spinmaker
SeaSide420
//@version=3
// Pivot Profit Taker
strategy("Pivot Profit Taker Strategy", shorttitle="PPTs", overlay=true, default_qty_type=strategy.percent_of_equity, max_bars_back=720, default_qty_value=25, calc_on_order_fills= false, calc_on_every_tick=true, pyramiding=0)
//study("profit taker", shorttitle="PT", overlay=false)
SL = input(defval=-5000, title="Stop Loss in $", type=float, step=1)
TP = input(defval=5000, title="Target Point in $", type=float, step=1)
price = input(ohlc4,type=source,title="Price data")
leftBars = input(4, title="Pivot LeftBars")
rightBars = input(2, title="Pivot RightBars")
swh = pivothigh(leftBars, rightBars)
swl = pivotlow(leftBars, rightBars)
swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice[1]
le = false
le := swh_cond ? true : (le[1] and high > hprice ? false : le[1])
if (le)
strategy.entry("buy", strategy.long, comment="BUY", stop=hprice + syminfo.mintick)
swl_cond = not na(swl)
lprice = 0.0
lprice := swl_cond ? swl : lprice[1]
se = false
se := swl_cond ? true : (se[1] and low < lprice ? false : se[1])
if (se)
strategy.entry("sell", strategy.short, comment="SELL", stop=lprice - syminfo.mintick)
strategy.close_all(when = strategy.openprofit<SL or strategy.openprofit>TP)
//buy = price > price[1] and strategy.openprofit>0
//buy2 = price > price[1] and strategy.opentrades<1
//sell = price < price[1] and strategy.openprofit>0
//strategy.entry("buy", true, 1, when=buy2)
//strategy.entry("buy", true, 1, when=buy)
//strategy.entry("sell", false, 1, when=sell)
//alertlong = long?1:0
//alertshort = short?1:0
//plot(alertlong, color=green)
//plot(alertshort, color=red)
//alertcondition(long, "Long")
//alertcondition(short, "Short")
jratnieks
@SeaSide420, This doesn't want to compile

Add to Chart operation failed, reason: line 18: mismatched input 'strategy.entry' expecting 'end of line without line continuation'
SeaSide420
@jratnieks, i.gyazo.com/e5cc4dba7da918f57dc3f364835daaaf.png
mate, thats the code, im not sure what going on there
joshatt
@jratnieks, Not sure if you still want to get this running but I was able to fix it by tabbing in line 18 and 25 after the if statements.
เพิ่มเติม