Manually webhook is triggering the order but from pine script order is not triggering at all

Manually webhook is triggering the order but from pine script order is not triggering at all


(I have proper balance I don’t know why this is failing)

but both I got alert logs and massage properly


dynamic (pine script) not triggering the order only getting only alert


Where I am doing mistake please help

@Subhajitpanja

The alert message needs to have only this place holder - {{strategy.order.alert_message}}

OK thank you sir I am checking with this

1 Like


@t7support
Perfectly working sir
thank you so much sir
Now I need to explore more

1 Like
//@version=5
strategy("Supertrend Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)

var bool tradeCompleted = false

atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)

[st, direction] = ta.supertrend(factor, atrPeriod)

buy = ta.change(direction) < 0
sell = ta.change(direction) > 0
short = sell
cover = buy

buyjson ='{"secret":"8IVNO","alertType":"multi_leg_order","order_legs":[{"transactionType":"B","orderType":"MKT","quantity":"1","exchange":"MCX","symbol":"GOLDPETAL1!","instrument":"FUT","productType":"M","sort_order":"1","price":"0"}]}'
shortjson ='{"secret":"8IVNO","alertType":"multi_leg_order","order_legs":[{"transactionType":"S","orderType":"MKT","quantity":"1","exchange":"MCX","symbol":"GOLDPETAL1!","instrument":"FUT","productType":"M","sort_order":"1","price":"0"}]}'

if (not tradeCompleted)
    if (strategy.position_size == 0)
        if (buy)
            strategy.order("buy", strategy.long, alert_message = buyjson)
        if (short)
            strategy.order("short", strategy.short, alert_message = shortjson)

    if (strategy.position_size > 0)
        if (sell)
            strategy.order("sell", strategy.short, alert_message = shortjson)
            tradeCompleted := true
        if (buy)
            strategy.order("cover", strategy.long, alert_message = buyjson)
            tradeCompleted := true

plot(st, color = direction == -1 ? color.green : color.red)

@t7support
Sir I have modified the code for one time execution

var bool tradeCompleted = false

entering the trade when

if (not tradeCompleted)

just before exit making it true

I will check on live trading day

Is it Okey Sir ?

@Subhajitpanja I am assuming you want to place only one closed trade (buy and sell once each) everyday and not just one trade throughout the life time of the set alert. Correct ?

U r code simply won’t work. This is because execution model and variable state persistence is different than a normal software program.

If you want to limit the number of intraday trades then simply use this function with trade count set to 2 (for one closed trade).

strategy.risk.max_intraday_filled_orders(2)

@t7support Thank you sir for reply. Be honest I did not think much. I thought that I will enter the trade on Supertrend(/50EMA,200EMA) crossover signal and exit also only based on the signal. But entry and exit should be one time.
Means single trade entry and square it off.
If I need to take next trade then I need to run the strategy again. Beyond any time frame like Day, Hour, etc.

Now I am thinking trade can be execute three way

  1. strategy without any specific period.
  2. intraday
  3. date and time (EX: Thursday 3:15 all square off ).

Sir, I will read pine script execution model. I got your point also intraday basis.
If I want to do positional basis still it will not work my code right ?

I didn’t get u. U r taking only one closed trade - buy + sell. Then if you want both entry buy and exit sell at the same time it is as good as no trade except for the incidence of transaction charges.:slightly_smiling_face:

If on the contrary the intention is to just have one buy and sell in a day u can just use this function I suggested earlier

One complete trade = entry + exit

  1. strategy without any specific period.
    ( I have asked you sir : If I want to do positional basis still it will not work my code right ?)
    Sir, Please reply point 1 also I am thinking wrong way or not

    1. intraday(one buy and one sell or vice-versa)
      I think (You have answered that one as strategy.risk.max_intraday_filled_orders(2))
  2. date and time (EX: Thursday 3:15 all square off ).
    Yes, point no 3 is confusing I know.
    Let me try put an example
    Suppose I want to take Bull call spread trade tomorrow (24-09-2024 after 9:30AM) and want exit based some indicator condition if fulfill the condition otherwise next week Thursday 3:15 PM I will square it off.

@t7support
Don’t worry what I am thinking. Just tell me what is right what is wrong.
I want to learn that’s all. Sir

Strategy always runs based on the timeframe of your chart. It executes once every closed historical candle and on every tick for a real time bar. U can do positional if u code accordingly.

Time and day based signals can also be generated in tandem with risk management functions TV provides. It all depends on how u code with pine.

:+1

https://www.tradingcode.net/tradingview/risk-management/

1 Like