Heloo Naman sir
I m placing order via web hook one time order is fine but how to exit from position
Heloo Naman sir
I m placing order via web hook one time order is fine but how to exit from position
Hello,
I have a question regarding a scenario:
Letâs say I create a basket comprising top high-volume and high-momentum stocks and generate a webhook URL associated with this basket.
Next, I create a custom Pine Script alert for both entry and exit separately.
Suppose, upon the alert triggering for entry, I automatically enter a long position with 100 quantity of any stock from the basket.
Now, for the exit, can I utilize a custom exit alert that is distinct from the entry alert? The exit criteria might involve combining EMA and RSI indicators.
However, the concern arises regarding defining profit targets and trailing stop-loss. Should these parameters be defined in the entry position itself when creating the webhook URL for entry?
Additionally, will there be a separate webhook URL for exiting the same position?
Things i am confused about
HI Admin
Can u Plz Help Me automation Of flowing Indicator
This is My Indicator (Pinescriptcode)
// @version=5
// Open-Range-Breakout strategy
// No license. Free and Open Source.
strategy(âStrategy: ORBâ, shorttitle=âORBâ, overlay=true , currency=currency.NONE, initial_capital=100000)
// Inputs
period = input.int(defval=15, title=âTimeRangeâ, tooltip=âThe range in minutes (default: 15m)â)
sessionInput = input.session(defval=â0915-0930â, title=âTime Rangeâ, group=âORB settingsâ, tooltip=âWhat is the timeperiod (default 9:15AM to 9:30AM, exchange timezoneâ)
hide = input.bool(defval = false, title=âHide ORB Rangeâ, group=âORB settingâ, tooltip = âHide the ORB range drawingâ)
// SL Related
slAtrLen = input.int(defval=14, title=âATR Period for placing SLâ, group=âStopLoss settingsâ)
showSLLines = input.bool(defval=false, title=âShow SL lines in chartâ, tooltip=âShow SL lines also as dotted lines in chart. Note: chart may look untidy.â, group=âStopLoss settingsâ)
// Further Filtering
ignoreMementumVolume = input.bool(defval=false, title=âIgnore Momentum & Volumeâ, tooltip=âIgnore Momentum & Volume to find out tradesâ, group=âStrengh Settingsâ)
rsiLen = input.int(defval=14, title=âMomentum Periodâ, group=âStrengh Settingsâ, tooltip = âTo determine the momentum, RSI period is set default to 100â)
rsiBullish = input.int(defval=50, step=1, title=âBullish Momentumâ, group=âStrengh Settingsâ, tooltip = âBullish Momentum, default set to RSI as 50â)
rsiBearish = input.int(defval=50, step=1, title=âBearish Momentumâ, group=âStrengh Settingsâ, tooltip = âBearish Momentum, default set to RSI as 50â)
volAvg = input.int(defval=20, step=1, title=âVolume Average Periodâ, group=âStrengh Settingsâ, tooltip = âTo calculate average volume, how many historical bars are considered. Default: 20.â)
volThreshold = input.float(defval=1, step=0.1, title=âVolume Strenghâ, group=âStrengh Settingsâ, tooltip = âMultiplier: How big the current bar volume compared to average of last 20â)
trendPeriod = input.int(defval=200, step=1, title=âTrend Periodâ, group=âTrend Settingsâ, tooltip = âTo calculate trend, what period is considered. Default: 200.â)
hideTrend = input.bool(defval = false, title=âHide the trend lineâ, group=âTrend Settingsâ, tooltip = âHide the trendâ)
hidePDHCL = input.bool(defval = false, title=âHide the PDHCL (prev day High Close Low range) & VWAPâ, tooltip = âHide the Previous Day High, Close, Low lines, including VWAPâ)
hideTable = input.bool(defval = false, title=âHide the Summary Tableâ, tooltip = âHide the summary table.â)
// Trade related
rrRatio = input.float(title=âRisk:Rewardâ, step=0.1, defval=2.0, group=âTrade settingsâ)
endOfDay = input.int(defval=1500, title=âClose all trades, default is 3:00 PM, 1500 hours (integer)â, group=âTrade settingsâ)
mktAlwaysOn = input.bool(defval=true, title=âMarkets that never closed (Crypto, Forex, Commodity)â, tooltip=âSome markers never closes. For those cases, make this checked.â, group=âTrade settingsâ)
lotSize = input.int(title=âLot Sizeâ, step=1, defval=1, group=âTrade settingsâ)
// Util method
is_newbar(res) =>
timeframe.change(time(res)) != 0
annotatePlots(txt, val, hide) =>
if (not hide)
var l1 = label.new(bar_index, hidePDHCL ? na : val, txt, style=label.style_label_left, size = size.tiny, textcolor = color.white, tooltip = txt)
label.set_xy(l1, bar_index, hidePDHCL ? na : val)
// print table
printTable(txt) =>
var table t = table.new(position.bottom_right, 1, 1)
table.cell(t, 0, 0, txt, text_halign = text.align_left, bgcolor = color.lime)
// globals
t = time(timeframe.period, sessionInput + â:1234567â) // everyday
in_session = not na(t)
is_first = in_session and not in_session[1]
is_end_session = in_session[1] and not in_session
green(open, close) => close > open ? true : false
red(open, close) => close < open ? true : false
var float orb_high = na
var float orb_low = na
if is_first
orb_high := high
orb_low := low
else
orb_high := orb_high[1]
orb_low := orb_low[1]
if high > orb_high and in_session
orb_high := high
if low < orb_low and in_session
orb_low := low
plot(hide ? na : orb_high, style=plot.style_line, color=orb_high[1] != orb_high ? na : color.green, title=âORB Highâ, linewidth=2)
annotatePlots(âORB-Hâ, orb_high, hide)
plot(hide ? na : orb_low, style=plot.style_line, color=orb_low[1] != orb_low ? na : color.red, title=âORB Lowâ, linewidth=2)
annotatePlots(âORB-Lâ, orb_low, hide)
// PDHCL (Previous Day High Close Low)
[dh,dl,dc] = request.security(syminfo.ticker, âDâ, [high[1],low[1], close[1]], lookahead=barmerge.lookahead_on)
plot(hidePDHCL ? na : dh, title=âPrev Highâ, color=color.red, linewidth=2, trackprice=true, show_last = 1)
annotatePlots(âPDHâ, dh, hidePDHCL)
plot(hidePDHCL ? na : dl, title=âPrev Lowâ, color=color.green, linewidth=2, trackprice=true, show_last = 1)
annotatePlots(âPDLâ, dl, hidePDHCL)
plot(hidePDHCL ? na : dc, title=âPrev Closeâ, color=color.black, linewidth=2, trackprice=true, show_last = 1)
annotatePlots(âPDCâ, dc, hidePDHCL)
plot(hidePDHCL ? na : ta.vwap(close), title=âVWAPâ, color=color.fuchsia, linewidth=2, trackprice=true, show_last = 1)
annotatePlots(âVWAPâ, ta.vwap(close), hidePDHCL)
// For SL calculation
atr = ta.atr(slAtrLen)
highestHigh = ta.highest(high, 7)
lowestLow = ta.lowest(low, 7)
longStop = showSLLines ? lowestLow - (atr * 1) : na
shortStop = showSLLines ? highestHigh + (atr * 1) : na
plot(longStop, title=âBuy SLâ, color=color.green, style=plot.style_cross)
plot(shortStop, title=âSell SLâ, color=color.red, style=plot.style_cross)
annotatePlots(âSL-Longâ, longStop, showSLLines)
annotatePlots(âSL-Shortâ, shortStop, showSLLines)
// Momentum: rsi
rsi = ta.rsi(close, rsiLen)
// trend: EMA200
ema = ta.ema(close, trendPeriod)
plot(hideTrend ? na : ema, âEMA Trendâ, color=close > ema ? color.green : color.red, linewidth = 1)
annotatePlots(âTrendlineâ, ema, hideTrend)
// Volume-Weighed Moving Average calculation
vwmaAvg = ta.vwma(close, volAvg)
vwma_latest = volume
// plotshape((barstate.isconfirmed and (vwma_latest > (vwmaAvg * volThreshold))), title=âVolumeDataâ, text=ââ, location=location.abovebar, style=shape.diamond, color=color.gray, textcolor=color.gray, size=size.tiny)
// Trade signals
longCond = barstate.isconfirmed and (ta.crossover(close, orb_high) or ta.crossover(close, dh)) and green(open, close) and (ignoreMementumVolume ? true : rsi > rsiBullish and (vwma_latest > (vwmaAvg * volThreshold)))
shortCond = barstate.isconfirmed and (ta.crossunder(close, orb_low) or ta.crossunder(close, dl)) and red(open, close) and (ignoreMementumVolume ? true : rsi < rsiBearish and (vwma_latest > (vwmaAvg * volThreshold)))
plotshape(longCond, title=âBreakoutâ, text=âBOâ, location=location.belowbar, style=shape.triangleup, color=color.green, textcolor=color.green)
plotshape(shortCond, title=âBreakoutâ, text=âBDâ, location=location.abovebar, style=shape.triangledown, color=color.red, textcolor=color.red)
// Trade execute
h = hour(time(â1â), syminfo.timezone)
m = minute(time(â1â), syminfo.timezone)
hourVal = h * 100 + m
totalTrades = strategy.opentrades + strategy.closedtrades
if (mktAlwaysOn or (hourVal < endOfDay))
// Entry
var float sl = na
var float target = na
if (longCond)
strategy.entry(âenter longâ, strategy.long, lotSize, limit=na, stop=na, comment=âEnter Longâ)
sl := longStop
target := close + ((close - longStop) * rrRatio)
alert(âBuy:â + syminfo.ticker + â ,SL:â + str.tostring(math.floor(sl)) + â, Target:â + str.tostring(target), alert.freq_once_per_bar)
if (shortCond)
strategy.entry(âenter shortâ, strategy.short, lotSize, limit=na, stop=na, comment=âEnter Shortâ)
sl := shortStop
target := close - ((shortStop - close) * rrRatio)
alert(âSell:â + syminfo.ticker + â ,SL:â + str.tostring(math.floor(sl)) + â, Target:â + str.tostring(target), alert.freq_once_per_bar)
// Exit: target or SL
if ((close >= target) or (close <= sl))
strategy.close("enter long", comment=close < sl ? "Long SL hit" : "Long target hit")
if ((close <= target) or (close >= sl))
strategy.close("enter short", comment=close > sl ? "Short SL hit" : "Short target hit")
else if (not mktAlwaysOn)
// Close all open position at the end if Day
strategy.close_all(comment = âClose all entries at end of day.â)
// Plotting table
if (not hideTable and is_end_session)
message = syminfo.ticker + " :\n\nORB Upper: " + str.tostring(math.round(orb_high)) + "\nORB Lower: " + str.tostring(math.round(orb_low)) + "\nPDH: " + str.tostring(math.round(dh)) + "\nPDC: " + str.tostring(math.round(dc)) + "\nPDL: " + str.tostring(math.round(dl)) + "\nVWAP: " + str.tostring(math.round(ta.vwap(close)))
printTable(message)
alert(message, alert.freq_once_per_bar_close)
And This Is Json Message
{
âsecretâ: âwnflAâ,
âalertTypeâ: âmulti_leg_orderâ,
âorder_legsâ: [
{
âtransactionTypeâ: â{{strategy.order.alert_message}}â,
âorderTypeâ: âMKTâ,
âquantityâ: â{{strategy.order.contracts}}â,
âexchangeâ: âNSEâ,
âsymbolâ: âHCLTECHâ,
âinstrumentâ: âEQâ,
âproductTypeâ: âIâ,
âsort_orderâ: â1â,
âpriceâ: â0â
}
]
}
I M getting alert in trading view but not Placing order on dhan via webhook plz helpme with that
Hi, team - I am using webhooks to place an order via Tradingview.
Now, I need to understand how I can use webhooks to exit out of the trade as well.
Example: I have a horizontal line at 200, and the webhooks place a buy order for 10 lots when the candles cross that line.
Now, how can I use webhooks to exit when the price crosses 210? I can create a line at 210 to specify my target. Thanks!
Hello @PravinJ @Naman @RahulDeshpande - Need your support here. I and many on this thread have raised a query about how to exit from an open position using webhooks. Can you please provide your views on this? Thanks much!
Hi @LotOfOptions Exit can also be triggered the same way via webhooks via alerts. Many users have automated this completely with Dhan + TradingView.
Thanks for the reply. Itâs good to get the confirmation that itâs possible. If you can direct me to a post that describes how itâs done, it would be great.
Thanks again.
@LotOfOptions u can get a sample code here.
Iâm facing problem in placing order with DHAN Webhook system as webhook is only makes entry position and not exit due to target or SL.
My trading view strategy is making both position, entry and exit but dhan is taking only one, please guide me.
@Arpit_Gupta the code shared here shows how u can exit as well
Hello @Hardik ,
I am reaching out if the bracket order is available in Dhan webhook, If not is there any timeline for the implementation.
Hello @jayaraman
Not right now. We are coming up with some updates on orders and post that, will iterate on webhook orders as well.
I have created webhook url, its active. configured in tradingview as explained in documentation. alerts generated are not received at dhan. what could be wrong?
how to create json for strategy? example if supertrend buy and sell triged
automatically order place ⌠in one alert
@RahulDeshpande @Naman @PravinJ what is the rate limit for webhook orders? Currently I am seeing there is lag of 1-2 seconds in execution if 4-5 orders are executed by webhook.
Also I would like to know the impact of sebi regulations on webhook orders. Does it come under API based algo trading?
Hello @Rajendra
Good to see you after so long. There is no rate limits on Webhook Orders, as it is coming from TradingView itself. If you are seeing lag in execution, would request you to kindly share the Client ID and time when you faced this lag, will monitor response times.
On the SEBI regulation, Webhook Orders will not fall under API based algo trading, as the mechanism of this is very different. First of all, the source of all orders remains TradingView.com, when you are using webhooks, making sure we know the source.
Second, TradingView itself does not allow automation of trading, meaning you cannot simply connect Dhan on TV and try automating your strategies.
Dhan Webhooks are inherently alert based execution, which is not in purview of algo trading as of now, as it is semi-automation at best.
Hi Hardik, Thanks for your wonderful explanation. I am 1-2 seconds lag but thatâs still ok I believe. If I see further issues, I will definitely connect with you guys.