Error in strategy coding: open and closes signals are late one bar
Forums › ProRealTime English forum › ProOrder support › Error in strategy coding: open and closes signals are late one bar
- This topic has 7 replies, 3 voices, and was last updated 6 years ago by George65.
-
-
01/09/2018 at 5:14 PM #58696
Hi everyone,
I tried to code a very simple str in a simplified way. And when I pro backtest, I can see, that the open and closes signals are late one bar. Anyone experienced something similar? Any tips?
The strategy as follows (long):
Entry:
Price must be at or above 50 SMA (close ›= Average [50](close)
The setup bar’s close is lower, than the close of the bar two bar before (close[1]‹close[3])
entry bar’s high is higher than the setup’s bar high (high›high[1])
Exit:
when a bar’s high is lower than the previous bar’s high (high‹high[1])
And I can see the entry arrow not below the entry bar, but one bar later, and I can see the exit signal also one bar later than expected
Kind regards
George
01/09/2018 at 5:21 PM #58699For anyone to be of some help you should post your complete code.
Roberto
01/09/2018 at 5:27 PM #58701Sorry, Roberto. Here it is! Thank you!
12345678910111213141516171819202122// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[50](close)c1 = (close >= indicator1)c2 = (close[1] < close[3])c3 = (high > high[1])IF c1 AND c2 AND c3 THENBUY 2 CONTRACT AT MARKETENDIF// Conditions to exit long positionsc4 = (high < high[1])IF c4 THENSELL AT MARKETENDIF// Stops and targetsSET STOP pLOSS 601/09/2018 at 5:38 PM #5870301/09/2018 at 5:42 PM #5870701/09/2018 at 11:30 PM #58770I tested it on DAX, both 2-hour and 4-hour TF and it works perfectly as you can see from the attached pic.
I outlines the 4 setup bars:
- 0 = the current one (just closed, when the strategy is executed)
- 1 = previous bar
- 2 = second previous bar
- 3 = third previous bar
Next to them, on the right side, you’ll see the cyan arrow pointin yo the entry bar, yet
Your code means:
123c1 = (close >= indicator1) //Closing price of current bar > Averagec2 = (close[1] < close[3]) //Closing price of the previous bar < closing price of the third previous barc3 = (high > high[1]) //high current price > previous bar's highAll is fine.
You probably think the current bar (setup bar)= entry bar. NO, the setup bar is the current (identified by 0) bar, just closed, while the entry bar is the next one which will open afterwards and you cannot reference it until it closes.
Strategy are ALWAYS (no matter what TF) executed when each bar closes, BEFORE the next one is opened. So the current bar cannot be the next one (the entry bar) because it has not yet started.
01/10/2018 at 12:52 AM #5877701/10/2018 at 1:48 AM #58786Before your reply I noticed the “next bar open” in the “assisted ProBacktest creation” window. And it made clear, that its logic different from indicators. I created several indicators in the program, and it draws the arrow when the condition is met (on the entry bar and not one bar later). The strategy draws the arrow next bar open, so not below the entry bar. It is confusing, and may turn the profitability of the strategy upside down (not necessarily, but it can happen) .
An example (dax long):
The entry bar gives you the signal at 13.300. But it closes at 13.400. The next bar opens with a 20 point gap up. So, the strategy enters at 13.420. Your stop is 20 points. It pulls back 40 points, and you are stopped out, and realise a loss. If your trade triggered at 13.300 you are not stopped out, and you realise profit.
The higher high is such a condition which can be realised immediately, and activate the trade. If you trade 4 hour timeframe…a lot can happen till the next bar opens…
So, when I noticed the next bar open condition in the window, I understood why the signals are late one bar. So from this point of view, the program works fine. But from trading, or risk point of view it has to be considered. If you have the trigger now, but if your trade is activated on the next bar open, it is an unforeseen risk. It can also happen that the trade should be negated, and the program just activates it instead.
Is it possible to define the stop level below the setup bar? So with not a number, or %.
Thank you for your time, and patience.
Kind regards
George
-
AuthorPosts
Find exclusive trading pro-tools on