Why did my strategy open a position?
Forums › ProRealTime English forum › ProOrder support › Why did my strategy open a position?
- This topic has 4 replies, 3 voices, and was last updated 3 years ago by robertogozzi.
-
-
12/19/2020 at 8:39 AM #154380
Hi
My code below seemed to work previously so I cannot understand why it doesn’t work anymore. Has something changed in PRT or is there a coding error?
Backtesting based on Daily DJI. I have also attached screenshots of the trade day, trigger day and trigger day -1 values of the indicators to assist you. Why did backtesting open a new long position on 16th Dec 2020?
The issue seems to be specifically in relation to the code in lines 33 to 45. In this particular example (see screenshots), x[1] > y[1] AND x[1] > 70 AND x > y are all true so a = 1. If a = 1, then as per line 49, it should not enter into a long position on 16th Dec 2020.
x = AroonUp[10]
y = AroonDown[10]
Please advise. Let me know if you need any further information.
Thanks
Sachin
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedx = AroonUp[10]y = AroonDown[10]short = 12long = 26signal = 9EMAshort1 = exponentialaverage[short](close)EMAshort2 = exponentialaverage[short](EMAshort1)DifferenceShort = EMAshort1 - EMAshort2ZeroLagShort = EMAshort1 + DifferenceShortEMAlong1 = exponentialaverage[long](close)EMAlong2 = exponentialaverage[long](EMAlong1)DifferenceLong = EMAlong1 - EMAlong2ZeroLagLong = EMAlong1 + DifferenceLongZeroLagMACD = ZeroLagShort - ZeroLagLongsignal1 = ExponentialAverage[signal](ZEROLAGMACD)signal2 = ExponentialAverage[signal](signal1)DIFFERENCE2 = signal1 - signal2SignalMACD = signal1 + DIFFERENCE2z = Williams[8](close)ATR = AverageTrueRange[14](close)//POSITIONPERF(1) < 0 AND TRADEPRICE(2) > TRADEPRICE(1) ANDIF ZeroLagMACD[1] > SignalMACD[1] AND ZeroLagMACD > SignalMACD AND x[1] > y[1] AND x[1] > 70 AND x > y THENa = 1ELSEa = 0ENDIF//POSITIONPERF(1) < 0 AND TRADEPRICE(2) < TRADEPRICE(1) ANDIF ZeroLagMACD[1] < SignalMACD[1] AND ZeroLagMACD < SignalMACD AND x[1] < y[1] AND y[1] > 70 AND x < y THENb = 1ELSEb = 0ENDIF// Conditions to enter long positionsIF a = 0 AND ATR < 500 AND ZeroLagMACD > SignalMACD AND z > -80 AND x > y AND x > 70 THENBUY 0.2 PERPOINT AT MARKETSET STOP LOSS 1.5 * ATRENDIF// Conditions to exit long positionsIF (ZeroLagMACD CROSSES UNDER SignalMACD AND z < -20) OR y > x THENSELL AT MARKETENDIF// Conditions to enter short positionsIF b = 0 AND ATR < 500 AND ZeroLagMACD < SignalMACD AND z < -20 AND y > x AND y > 70 THENSELLSHORT 0.2 PERPOINT AT MARKETSET STOP LOSS 1.5 * ATRENDIF// Conditions to exit short positionsIF (ZeroLagMACD CROSSES OVER SignalMACD AND z > -80) OR x > y THENEXITSHORT AT MARKETENDIF//c = BARINDEX - TRADEINDEX//IF LONGONMARKET AND (highest[c](high) - TRADEPRICE) > 500 THEN//SET STOP TRAILING 100//ELSIF SHORTONMARKET AND (TRADEPRICE - lowest[c](low)) > 500 THEN//SET STOP TRAILING 100//ENDIF12/22/2020 at 4:03 AM #154815If you append this code to your strategy:
12345678graph agraph ATRgraph ZeroLagMACDgraph SignalMACDgraph zgraph xgraph ygraph (a = 0 AND ATR < 500 AND ZeroLagMACD > SignalMACD AND z > -80 AND x > y AND x > 70)you will be able to see that on Dec. 15th 2020 conditions at line 49 were met when the daily candle closed, so it immediately entered a trade (signaled with an arrow on Dec. 16th).
1 user thanked author for this post.
12/22/2020 at 9:37 AM #154854sulimaster – Please follow the forum rules and give any future topics a meaningful title otherwise we will end up with a forum full of ‘Code error’ topics. I have changed your topic title.
12/22/2020 at 4:14 PM #154899Thanks Roberto
Another thing I’m struggling with – in the live market (trading with IG), using the same strategy, why was a long trade opened on 18th Dec 2020 instead of 16th December 2020 as per the tick by tick back test (see attached)?
12/23/2020 at 1:42 AM #154937Mine was opened on Dec. 16th.
-
AuthorPosts
Find exclusive trading pro-tools on