Multiple orders in 1 candle
Forums › ProRealTime English forum › ProOrder support › Multiple orders in 1 candle
- This topic has 7 replies, 3 voices, and was last updated 6 years ago by MaoRai54.
-
-
01/22/2018 at 9:35 AM #60127
Hi:
I have a problem in which the back-test takes multiple orders in one bar. Mt system is a pyramiding strategy that takes additional positions every time price goes up by 2ATR however, it seems to take on multiple orders on the same bar every time there is a large candle and/or ATR goes up significantly. From the code, it should be taking one position per candle only.
Can anyone tell me what’s wrong? Thank you.
Ruben
01/22/2018 at 9:44 AM #6012901/22/2018 at 12:32 PM #60156Not quite because there is no problem on the previous 3 transactions (in the attachment). It happens on other instruments as well, the code works well unless there is a large candle, it is only on the large candles that it does this, it executes multiple orders at exactly the same price. However, from the code, it should be recording the close of the candle as a reference for the next transaction. It should also be processing every candle only once.
Even if all conditions were the same you would see trades on every candle, not multiple transactions on the same candle at the same price. The IF/ENDIF conditions should prevent that shouldn’t it?
Here’s the code.
Has anyone seen this before? Thanks in advance
CODE123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions activatedDEFPARAM NoCashUpdate = False //For backtest only - pg 22// Conditions to enter long positionsindicator1 = ExponentialAverage[8](close)indicator2 = ExponentialAverage[50](close)c1 = (indicator1 CROSSES OVER indicator2)Equity = 50000Risk = Equity*0.01FXinAUD=1.50 //Exchange rate for quote currency in to AUD (1 equals = ??AUD)FXrate = 1/FXinAUD //Add line ABOVE for non-AUD contracts with the FX rate of quote currency in AUDContractSize = 10000ATRdistance = AverageTrueRange[14](close)*2Risk1 = ATRdistance*ContractSize //Risk per contract in quote currencyContractRisk = Risk1*FxratePos1 = Risk/ContractRiskIF Not OnMarket THENTransactions = 0ENDIF//Long entryIF Not LongOnMarket AND c1 THENInitialStop = lowBuyPrice = OpenBUY Pos1 CONTRACT AT MARKETTransactions = Transactions + 1ENDIF//PyramidingIF Transactions=1 AND Close>=(BuyPrice+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice2 = OpenTransactions = Transactions + 1ENDIFIF Transactions=2 AND Close>=(BuyPrice2+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice3 = OpenTransactions = Transactions + 1ENDIFIF Transactions=3 AND Close>=(BuyPrice3+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice4 = OpenTransactions = Transactions + 1ENDIFIF Transactions=4 AND Close>=(BuyPrice4+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice5 = OpenTransactions = Transactions + 1ENDIFIF Transactions=5 AND Close>=(BuyPrice5+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice6 = OpenTransactions = Transactions + 1ENDIFIF Transactions=6 AND Close>=(BuyPrice6+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice7 = OpenTransactions = Transactions + 1ENDIFIF Transactions=7 AND Close>=(BuyPrice7+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice8 = OpenTransactions = Transactions + 1ENDIFIF Transactions=8 AND Close>=(BuyPrice8+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice9 = CloseTransactions = Transactions + 1ENDIFIF Transactions=9 AND Close>=(BuyPrice9+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice10 = CloseTransactions = Transactions + 1ENDIFIF Transactions=10 AND Close>=(BuyPrice10+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice11 = CloseTransactions = Transactions + 1ENDIFIF Transactions=11 AND Close>=(BuyPrice11+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice12 = CloseTransactions = Transactions + 1ENDIFIF Transactions=12 AND Close>=(BuyPrice12+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice13 = CloseTransactions = Transactions + 1ENDIFIF Transactions=13 AND Close>=(BuyPrice13+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice14 = CloseTransactions = Transactions + 1ENDIFIF Transactions=14 AND Close>=(BuyPrice14+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETBuyPrice15 = CloseTransactions = Transactions + 1ENDIFIF Transactions=15 AND Close>=(BuyPrice15+AverageTrueRange[14](close)*2) AND LongOnMarket THENBUY Pos1 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsATRx = AverageTrueRange[14](close)*2StopLoss = CALL "2ATR trailing stop"IF LongOnMarket AND close <= Buyprice + ATRx AND InitialStop>StopLoss THENSELL AT InitialStop STOPELSESELL AT StopLoss STOPENDIF01/22/2018 at 1:27 PM #60161Yes , it appears on large candle, when the Close is superior to previous “BuyPrice” with 2 ATR, so it never happens on small candle (because ATR is small).
The problem is that each time you open an order you increase the “transactions” variable and this is the only variable tested to open a new order (because your Close>Buyprice+ATR*2 condition is always the same) and since the code is read from to to bottom, you add continuously new order (from line 32 to 119).
01/22/2018 at 1:51 PM #60167Hi Nicholas:
The “BuyPrice” is also supposed to change after every pyramid trade: Buyprice2…Buyprice3… is this variable being ignored?
BTW, thanks for your reply. Is there a way to make it execute each pyramid only once? (I tried “ONCE” in combination with IF but it doesn’t work)
01/22/2018 at 2:22 PM #60171Nicholas:
Don’t worry, I solved it.
Cheers.
01/22/2018 at 3:34 PM #60183No, the BuyPrice don’t change because you are constantly storing the same value on the same candle. You can use TRADEPRICE instead, which refer to the real open price of the last N order.
01/25/2018 at 7:20 PM #60531 -
AuthorPosts
Find exclusive trading pro-tools on