1
votes

Ok, so I'm testing a strategy and I need to get the strategy entry and exit correct.

In my example, I want an order to be placed with a fixed stop loss and limit price.

If there's another buy (or sell) signal whilst there is and open position, I want a second entry with it's own fixed stop loss and limit price.

Currently, I'm able to take multiple positions using strategy.entry() and I can set exit conditions using strategy.exit()

However, when the next buy/sell signal is generated, the exit position calculates for the new trade AND also changes the exit condition for the already open trade(s)

Here's the statement that triggers the entry and exit

//Strategy Entry Signals
if (showBuySig)
    BuyStopPrice = atrSell[1]
    BuyLimitPrice = open + ((open - atrSell[1])*1.5)
    strategy.entry("HildayBuy", strategy.long, comment="HildaBuy")
    strategy.exit("HildaBuy", stop = BuyStopPrice, limit = BuyLimitPrice, comment="SL/TP")

Simply, if a buy signal is generated, then it creates an entry and sets (updates existing) exit prices

Pyramiding is set to 10 to allow multiple positions.

Now, I just need to understand how to set individual exits points for each position, but really struggling to work out how.

UPDATE

I used TIME to create a unique string reference for each order:

    IDnumBuy = tostring(time)
    BuyStopPrice = close - (close - atrSell)
    BuyLimitPrice = close + ((close - atrSell)*1.5)
    strategy.entry(IDnumBuy, strategy.long, comment="Buy Entry: "+tostring(close)+" TP:"+tostring(BuyLimitPrice)+ " SL:"+tostring(BuyStopPrice)+" ID:"+IDnumBuy)
    strategy.exit("Exit", IDnumBuy, stop = BuyStopPrice, limit = BuyLimitPrice, comment="SL/TP ")```
1

1 Answers

0
votes

Try this:

//Strategy Entry Signals
if (showBuySig)
    BuyStopPrice = atrSell[1]
    BuyLimitPrice = open + ((open - atrSell[1])*1.5)
    strategy.entry("HildayBuy", strategy.long, comment="HildaBuy")
    strategy.exit("HildaSell" + tostring(bar_index), stop = BuyStopPrice, limit = BuyLimitPrice, comment="SL/TP")