Scalping Strategy – P/L Chart misaligned with Optimisation report
10/11/2021 at 2:34 PM #179397
I am coding a simple entry/exit system, however when I try and optimise some variables I can see something odd..
The Gains on Optimization Report (on the left), are completely misaligned with what I see on the P/L curve (on the right). (this happens even when selecting the different optimised models.
In my past experience usign this platform I always beleived these figures were the final results of the strategy
Gabriel10/11/2021 at 4:35 PM #179407
Optimization had never used tick by tick (intrabar) precision while ordinary backtest do. That’s why there is a “Modalita tick by tick” column that shows you on how many bars some checking should be made in a normal backtest, more bars = more differences possible.10/11/2021 at 5:00 PM #17941010/12/2021 at 8:58 AM #179454
No trades are still open at the end of the strategy. But the difference between the results is rather significant.
@Nicolas – is it wise to not use tick by tick opt when coding a scalping strategy? If you don’t use tick by tick are you trading at each candle’s close?
Here is the code, if someone wants to try and run this to see their outcome…12345678910111213141516171819202122232425262728293031323334353637383940DEFPARAM cumulateorders = FalseDEFPARAM flatafter = 080600starthour = 073000endhour = 075950if time = starthour thenhh2 = hh1hh1 = hhhh = closell2 = ll1ll1 = llll = close * 1000endifif time >= starthour and time <= endhour thenhh = max(hh, high)ll = min(ll, low)endifif CurrentTime < 080000 thentot = 0Endif//x=5y = 20// Condizioni per entrare su posizioni shortIF NOT ShortOnMarket AND NOT LongOnMarket AND CurrentTime > 075900 and CurrentTime < 080200 and tot = 0 ThenSELLSHORT 1 CONTRACTS AT ll stopSet stop TRAILING xset target profit ytot = 1ENDIFIF NOT LongOnMarket AND NOT ShortOnMarket AND CurrentTime > 075900 and CurrentTime < 080200 and tot = 0 tHENBUY 1 CONTRACTS AT hh stopSet stop TRAILING xset target profit ytot = 1ENDIF10/12/2021 at 9:39 AM #179457
Your equity curve shows lots of trades opening and closing in the same bar and so do not show up as positions under the equity curve.
May be something weird in the code or could be those tight times result in trades open and close at 8 o’clock when there is high volatility?10/12/2021 at 9:49 AM #17945810/12/2021 at 9:57 AM #179462
thanks for the above.
The actual purpose of this code is to scalp a few points in the first two minutes at the opening. As the aim is to have trades opened and closed within minutes or seconds sometimes.
I shall try to change to Set Stop Loss and see what happens.
If I wanted a Trailing Stop for any strategy, should I code it from scratch? rather than use Set Stop Trailing? Do you think this would be ineffective for all the strategies or for this only?
Gabriel10/12/2021 at 9:58 AM #17946310/12/2021 at 10:01 AM #17946410/12/2021 at 11:14 AM #179469
What I am trying to do is to Buy Stop or Sell Stop above and below the trading range occurred in 30 minutes before the open.
I have reviewed the code as per your suggestion above (Thank you!!) and also noticed that the strategy was only selling. I fixed a couple of things and it should work as expected.Now with comments1234567891011121314151617endhour = 075950// getting high and lows for the last 30 mins of tradingif time = starthour thenhh = highll = lowendifif time >= starthour and time <= endhour thenhh = max(hh, high)ll = min(ll, low)endif//set total trades counter to 0 every morningif CurrentTime < 080000 thentot = 0Endif
However.. What I am still struggling to understand is how big the results are when backtesting tick-by-tick and when not!! The gains and the P/L curves are extremley different
Should we use tick-by_tick for scalping strategies? (in this strategy there is only 1 trade executed with trailing trailing and take profit after all)
Gabs10/12/2021 at 11:36 AM #179474
I’ll try the new code, but yes we always need to have tick by tick enabled … results are completely false without tick by tick enabled and would never be achieved in Realtime.
When I first started on here (never coded before) I thought, wow it’s this easy to code and become a millionaire! 🙂 That was before there was even a tick by tick option to enable.
I then spent loads of time testing testing testing as I didn’t know what was going on or why. Eventually I advised PRT of my findings. I guess it must have been early days for Auto-Trading on PRT. Anyway all history and behind us now, just feel in a chatty mood this morning! 🙂10/12/2021 at 11:46 AM #179475
haha 🙂 find below the full code.. I thought I found the best strategy in the world but with tick by tick that’s not really true haha
I tried playing around with different kinds of stops (trailing/loss). It’s a really basic strategy.. i was hoping it could be automated (succesfully)
But anyway I am back at square one. If I test my strategy using tick by tick and then try an optimise Stop loss and take profit.. the P/L values are completely off between the strategy and the optimisation report (feel free to give it a try)123456789101112131415161718192021222324252627282930313233343536373839404142434445// Condizioni per entrare su posizioni longDEFPARAM cumulateorders = FalseDEFPARAM flatafter = 080600starthour = 073000endhour = 075950// getting high and lows for the last 30 mins of tradingif time = starthour thenhh = highll = lowendifif time >= starthour and time <= endhour thenhh = max(hh, high)ll = min(ll, low)endif//set total trades counter to 0 every morningif CurrentTime < 080000 thentot = 0Endif// set stop loss x and take profit yx = 10y = 30// LongIF NOT LongOnMarket AND NOT ShortOnMarket AND CurrentTime > 075900 and CurrentTime < 080100 and tot = 0 tHENBUY 1 CONTRACTS AT hh stopSet stop trailing xset target profit yif longonmarket thentot = 1endifENDIF// ShortIF NOT ShortOnMarket AND NOT LongOnMarket AND CurrentTime > 075900 and CurrentTime < 080100 and tot = 0 ThenSELLSHORT 1 CONTRACTS AT ll stopSet stop trailing xset target profit yif shortonmarket thentot = 1ENDIFendif10/12/2021 at 12:43 PM #179480
P/L values are completely off between the strategy and the optimisation report
Please expand a bit more on what you mean by above?
Attached results on equity curve and Detail Report are the same as the optimisation results.
My changes in attached may not align fully with your overall strategy? I wanted to get some Long trades (to prove the code works).
I’m sure attached can be improved further. Feel free to reverse any changes I made, I tend to make changes and run them rather than sit there working out what I expect to happen.
Let’s keep at it. I like scalpers as that is mostly how I manual trade.
10/12/2021 at 12:52 PM #17948410/12/2021 at 2:39 PM #179490
I think Nicolas explained this above actually.. But I am not sure I fully understand.
If you look at the filed attached I have run an optimisation to find the best value for my Take Profit (y).
One of the best optimisation is with Y=17.. and as you can see the expected gains are EUR 395.90 (see on the left in ‘Rapporto Ottimizzazione’ the row highlighted in orange!)
Once I click on this, I would expect to see the latest equity value (on the equity line above) to be EUR 395.90 added to the starting capital… so I am expecting: EUR 1395.90, however this is not the case and the final equity value is EUR 1312.3 instead. There is a difference of EUR 83.6… why?
Optimization had never used tick by tick (intrabar) precision while ordinary backtest do. That’s why there is a “Modalita tick by tick” column that shows you on how many bars some checking should be made in a normal backtest, more bars = more differences possible.
But if this is the case, what would be the point of having optimized variables if these don’t apply to tick-by-tick mode.. I am rather confused.
Nice stuff – I can see you ran the code on DJI!! I wanted to test this too.. But I would adjust the times to the Dow opening (14:30)
Same as you I scalp manually, hence why I am interesting in building an simple code for scalping 😀