Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

  • Forums
  • Pinescript
  • Possible to run 2 strategy.entry long orders simultaneously?

Possible to run 2 strategy.entry long orders simultaneously?

Dec 11, 2020 - 3:57 PM

Viewed 2605 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/21735 COPY
  • In tradingview Pine Script, I find that if I have two long orders in a strategy, it executes the 2nd strategy.entry long order only after the first one ends. Is it possible to have the 2nd long order run while the 1st long order is still open? How?

    Please advice.

    1
  • Hi @vijaynair

    I think you have to update the pyramiding value from your strategy() function
    https://www.tradingview.com/pine-script-reference/v4/#fun_strategy

    This is the strategy(...) function called at the very top of your script

    The documentation says this

    pyramiding (const integer): The maximum number of entries allowed in the same direction. If the value is 0, only one entry order in the same direction can be opened, and additional entry orders are rejected. The default value is 0.

    Setting a pyramiding greater to 1 allows your strategy to take multiple trades at once

    0

    Dave - Helping traders becoming the best version of themselves
  • I tried pyramiding. It does not do what I want. Let me explain

    Consider there are 2 different strategy.entry orders - BUY1 and BUY2.
    With pyramiding set to 1, it executes BUY2 only after the BUY1 order is closed, not while the latter is still open.

    Test scrip given below

    //@version=4

    strategy(title=Double Strategy Order Check, overlay=true, pyramiding=1)

    startDate = input(title=Start Date, type=input.integer, defval=1, minval=1, maxval=31)
    startMonth = input(title=Start Month, type=input.integer, defval=1, minval=1, maxval=12)
    startYear = input(title=Start Year, type=input.integer, defval=2010, minval=1800, maxval=2100)

    inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))

    rsi14 = rsi(close, 14)
    sma100 = sma(close, 100)
    sma200 = sma(close, 200)

    bought = strategy.position_size[0] > strategy.position_size[1]
    since_entry = barssince(bought)

    firstorder = close > sma100
    secondorder = close > sma200

    firstexit = rsi14 < 30
    secondexit = rsi14 > 70

    strategy.entry(id = BUY1, long = true, when = firstorder)
    strategy.entry(id = BUY2, long = true, when = secondorder)

    strategy.close(id = BUY1, when = firstexit)
    strategy.close(id = BUY2, when = secondexit)

    This post was edited Dec 12, 2020 09:45AM
    0
  • You can set pyramiding to 2

    1
CONTENTS