ProRealTime - Probacktest

Revolutionary

Junior member
Messages
23
Likes
0
Hi everyone,

I got a question about Probacktest. It seems like signals are given 1 bar too late each time.

This is my code:
IF (DOpen(1) < DClose(1)) Then
BUY 1 SHARES AT MARKET
ENDIF

IF (DOpen(0) >= DClose(0)) OR (DOpen(0) <= DClose(0)) THEN
SELL AT MARKET THISBARONCLOSE
ENDIF

IF (DOpen(1) > DClose(1)) Then
SELLSHORT 1 SHARES AT MARKET
ENDIF

IF (DOpen(0) >= DClose(0)) or (DOpen(0) <= DClose(0)) Then
EXITSHORT AT MARKET THISBARONCLOSE
ENDIF

This system should go LONG when the previous day candle was green and should go SHORT when the previous day candle was red. The trade should be exited at the end of the day.

When I test this simple code the signals are executed 1 bar too late...

I hope someone can show me the error in this code.

Tim
 
Another question: does anybody know a forum with a lot of ProRealTime users? I'm new to PRT and I like to share experience with other users.

Thanks in advance!

Tim
 
You need to contact them. Aparently on the last update they changed the data provider an f*cked up a lot of strategies using dates and similar strategies.

Anyway, you can try this that will work better :) :

IF (dClose(0)>dOpen(0)) Then
BUY 1 SHARES AT market
ENDIF


if longonmarket then
sell at market thisbaronclose
endif


IF (DOpen(0) > DClose(0)) Then
SELLSHORT 1 SHARES AT MARKET
ENDIF

if shortonmarket then
exitshort at market thisbaronclose
endif


Hi everyone,

I got a question about Probacktest. It seems like signals are given 1 bar too late each time.

This is my code:
IF (DOpen(1) < DClose(1)) Then
BUY 1 SHARES AT MARKET
ENDIF

IF (DOpen(0) >= DClose(0)) OR (DOpen(0) <= DClose(0)) THEN
SELL AT MARKET THISBARONCLOSE
ENDIF

IF (DOpen(1) > DClose(1)) Then
SELLSHORT 1 SHARES AT MARKET
ENDIF

IF (DOpen(0) >= DClose(0)) or (DOpen(0) <= DClose(0)) Then
EXITSHORT AT MARKET THISBARONCLOSE
ENDIF

This system should go LONG when the previous day candle was green and should go SHORT when the previous day candle was red. The trade should be exited at the end of the day.

When I test this simple code the signals are executed 1 bar too late...

I hope someone can show me the error in this code.

Tim
 
Horace, I checked your code and it works :)

Somehow dOpen(0) refers to yesterday instead of today.. strange

But now I got trouble making a code that refers to today, I tried dOpen(-1) but obviously that didn't work..

If for example I want to go Long when today's open is higher than yesterday's close and want to go Short when today's open is lower than yesterday's close. How would that code look like?

Thanks for any help!
 
Why don't you just use OPEN and CLOSE? is this what you want?

IF (Open[1] < Close[1]) Then
BUY 1 SHARES AT MARKET
ENDIF
IF (Open[0] >= Close[0]) OR (Open[0] <= Close[0]) THEN
SELL AT MARKET THISBARONCLOSE
ENDIF
IF (Open[1] > Close[1]) Then
SELLSHORT 1 SHARES AT MARKET
ENDIF
IF (Open[0] >= Close[0]) or (Open[0] <= Close[0]) Then
EXITSHORT AT MARKET THISBARONCLOSE
ENDIF
 
Shakone, the code you posted is exactly the same as the code I posted in my first post. With that code signals get executed 1 day too late.

The problem is that dOpen(0) refers to the opening price of yesterday instead of today, dOpen(1) refers to the day before yesterday instead of yesterday and so on...

My question is if dOpen(0) refers to yesterday then what code refers to the opening price of today?
 
No it's not the same code, it's using open and close rather than Dopen and Dclose. And it works just fine for me.
 
You are right Shakone, I didn't notice the difference between Open[1] in your code and dOpen(1) in my code.

However, your code also executes trades 1 bar too late. I have attached a screenshot that shows the problem.

As you can see in the screenshot there was a red candle on December 28th, therefore the system should go Short on December 29th but instead the system goes Long on the 29th and goes Short on the 30th.

errorcode.png
 
Hi Revolutonary,

The problem is it is impossible to do what you want to do.

PRT (or any other sw btw) evaluates all conditions after the bar has closed. There is no other way of approaching this programming as far as I know.

Hence you need to take than into account for your programming and backtesting. The code will "know" that today's open is higher than yesterdays close after today's close. And the code only "knows" that today has closed once it receves the open of tomorrow.

So, at that point in time, you are evaluating not the present bar but two bars behind when you try to capture yesterdays close.

My explanation has been a bit messi, but english is not my mother tounge so that is my best. :)

Maybe this code can help:


REM Long if open today is > yesterday close. Sell on market close same day

IF (dopen(1) >dclose(2)) Then
BUY 1 SHARES AT market
ENDIF


if longonmarket then
sell at market thisbaronclose
endif

Good luck




Horace, I checked your code and it works :)

Somehow dOpen(0) refers to yesterday instead of today.. strange

But now I got trouble making a code that refers to today, I tried dOpen(-1) but obviously that didn't work..

If for example I want to go Long when today's open is higher than yesterday's close and want to go Short when today's open is lower than yesterday's close. How would that code look like?

Thanks for any help!
 
Thank you very much Horace!

This is the best answer I got till now, unfortunalety it is not what I hoped for.
But I'm glad that I now know the reason why my code doesn't work.

Still I find it strange that the backtesting software doesn't just leave today's bar out of the calculations.

I'm going to try your codes today!

Thanks again!
 
Horace,

I've tested your last code and unfortunatelly this code is even 2 bars too late in the execution.
I think I'm going to try some other platform.

Tim
 
Hi Revo,

Course, I told you.

As I explained before, it's not a problem with the platform. Markets simply work like that, you can't possibly know the bar close untill the next bar has opened.

Except, of course, you code in the market closing hour. The problem is this is not a very "clean" solution because it won't work on other markets or even on the same market if closing time has changed in the backtest history.

The code I provided is usefull for backtest but not for real time trading of course.

Best regards,

Horacio



Horace,

I've tested your last code and unfortunatelly this code is even 2 bars too late in the execution.
I think I'm going to try some other platform.

Tim
 
"The code I provided is usefull for backtest but not for real time trading of course."

How do you mean that the code is usefull for backtesting? When I try to backtest it the trades are executed too late and therefore it isn't usefull for backtesting.. Or am I missing something?

Thanks for your help!
 
When you backtest you analyze hundreds or even thousands of historical trades. Your results won't be affected by the last trade you are missing from yesterday. And if you cant live without it, just run the backtest again tomorrow.



"The code I provided is usefull for backtest but not for real time trading of course."

How do you mean that the code is usefull for backtesting? When I try to backtest it the trades are executed too late and therefore it isn't usefull for backtesting.. Or am I missing something?

Thanks for your help!
 
The more I think about it the more I find it strange that the platform doesn't calculates the code in the right way.

When using EOD I can imagine the code doesn't work on today's bar, but when I activate real time data in PRT, the platform exactly knows the open of today and the close of yesterday. So it should have calculated if the system must go Long on the opening or not..

Tim
 
Of course not, but writing in plain english is not a trading platform. :)

I haven't checked the link you posted, and maybe that is the simplest, but I know A LOT of trading platforms and PRT is not by any means the more complex to code. Actually, imho, it is not complex at all in comparison to most of the others.

Easier than simply start writing in plan english?, with no programming skills?
 
Top