Problem with EntriesToday(Date)

Questions about MultiCharts and user contributed studies.
User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Problem with EntriesToday(Date)

Postby svopex » 19 Mar 2016

I found difference between real time trading and backtest.
EntriesToday(Date) work wrong by my opinion.

Log:
3/11/2016 friday - signal create order
3/13/2016 sunday - I restart portfolio trader
3/14/2016 monday - signal create trade on the first candle! It's wrong, because EntriesToday(Date) must be 1 (friday trade)!
...

When i run backtest, there is no 3/14/2016 trade...

I have session from 9:30 to 16:15.


Signal:

Code: Select all

...
...
...
if EntryCond and EntriesToday(Date) < 1 then
begin
buy next bar at EntrLong stop;
end;
...
...
...
Real time trading (start 3/13/2016):
0,1,1,Svp3,1,US Russ 2000,3/9/2016 10:15:00,1072.2940,3/9/2016 16:15:00,1073.9290,1,1,1.64,1
0,2,1,Svp3,1,US Russ 2000,3/10/2016 10:00:00,1076.6380,3/10/2016 11:30:00,1061.5790,1,1,-15.06,1
0,3,1,Svp3,1,US Russ 2000,3/11/2016 10:00:00,1075.3790,3/11/2016 16:15:00,1086.6190,1,1,11.24,1
0,1,1,Svp3,1,US Russ 2000,3/14/2016 9:45:00,1084.1600,3/14/2016 16:15:00,1082.5440,1,1,-1.62,1
0,2,1,Svp3,1,US Russ 2000,3/18/2016 10:00:00,1096.3180,3/18/2016 16:15:00,1101.4280,1,1,5.11,1

Backtest (start 3/13/2016):
0,1,1,Svp3,1,US Russ 2000,3/9/2016 10:15:00,1072.2940,3/9/2016 16:15:00,1073.9290,1,1,1.64,1
0,2,1,Svp3,1,US Russ 2000,3/10/2016 10:00:00,1076.6380,3/10/2016 11:30:00,1061.5790,1,1,-15.06,1
0,3,1,Svp3,1,US Russ 2000,3/11/2016 10:00:00,1075.3790,3/11/2016 16:15:00,1086.6190,1,1,11.24,1
0,2,1,Svp3,1,US Russ 2000,3/18/2016 10:00:00,1096.3180,3/18/2016 16:15:00,1101.4280,1,1,5.11,1
Attachments
2016-03-19_1424.png
Wrong trade.
(60.18 KiB) Downloaded 1227 times
2016-03-19_1423.png
My session, EST, NewYork time. I have gap.
(7.76 KiB) Downloaded 1310 times

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Problem with EntriesToday(Date)

Postby rrams » 20 Mar 2016

Hi svopex! The EntriesToday function is correct as written, however; I think your code logic using SessionEndTime as an entry signal is problematic.

A backtest will ignore Sunday, since it is not within the session times, but real time trading might produce some quotes and your logic is looking back calendar days instead of trading days.

You should rewrite your code not to use functions that call other functions that may reference unintended lookback periods. Make it all inline and linear for debugging and the problem should be obvious. I hope this helps.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Problem with EntriesToday(Date)

Postby svopex » 25 Mar 2016

Realtrading - signal buy at 9:30am, backtest - signal buy at 9:45am...
There is difference between realtrading and backtest when I use EntriesToday(Date)...

You can test it, here is very very simple signal:

Code: Select all

if EntriesToday(Date) < 1 and MarketPosition = 0 then
begin
buy next bar market;
end;

setexitonclose;
1. realtrading, buy at first candle
Image

2. disable automatic trading (disable SA)

3. recalculation of strategy
Image

4. sim, buy at second candle
Image

My session, my computer time zone is EST (New York):
Image

In my opinion real trading taking only real trades and therefore EntriesToday(Date)=0 for real trading strategies and Multicharts purchase at the first candle. But it is wrong. Optimalization and backtest gives different results than real trading :-(

EntriesToday code:

Code: Select all

inputs: TargetDate_YYYMMDD( numericsimple ) ;

variables: var0( 0 ) ;

var0 = 0 ;

for Value1 = 0 to 10
begin
condition1 = EntryDate( Value1 ) = TargetDate_YYYMMDD ;
if condition1 then
var0 = var0 + 1 ;
end ;

EntriesToday = var0 ;
Attachments
picture three.png
(52.31 KiB) Downloaded 1304 times
picture two.png
(63.32 KiB) Downloaded 1308 times
picture one.png
(64.05 KiB) Downloaded 1304 times

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Problem with EntriesToday(Date)

Postby rrams » 26 Mar 2016

The code is simple but the different modes of operation need to be understood. You absolutely cannot use SetExitOnClose for real-time trading. You must use something like:

Code: Select all

if MarketPosition>0 and time>=1545 then sell next bar at Market;
onclose orders may or may not work with your broker but they won't equal backtested results.
See post #6
http://www.multicharts.com/discussion/v ... 16&t=10811

I don't know which Russell 2000 product OANDA offers, but make sure your session times are exactly correct. Is this the stock index, future or a CFD?

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Problem with EntriesToday(Date)

Postby svopex » 26 Mar 2016

Hello, i have problem with EntriesToday(Date) and not with SetExitOnClose.
I test SetExitOnClose with Oanda many times and this work perfectly.
Russell 2000 is CFD.

Please, discuss in this thread about EntriesToday(Date).

When I add to signal print (log):

Code: Select all

print(date, " ", time, " ", EntriesToday(Date));

if EntriesToday(Date) < 1 and MarketPosition = 0 then
begin
buy next bar market;
end;

setexitonclose;
When I run backtest (after click to recalculate strategy):
1160324.00 1500.00 1.00
1160324.00 1515.00 1.00
1160324.00 1530.00 1.00
1160324.00 1545.00 1.00
1160324.00 1600.00 1.00
1160324.00 1615.00 1.00

When i run automatic trading (after click to SA):
1160324.00 1500.00 0.00
1160324.00 1515.00 0.00
1160324.00 1530.00 0.00
1160324.00 1545.00 0.00
1160324.00 1600.00 0.00
1160324.00 1615.00 0.00

In realtime mode Multicharts don't get orders from backtest.
It's a problem for me, because backtest (and optimalization) have another results than real trading.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Problem with EntriesToday(Date)

Postby evdl » 26 Mar 2016

I use EntriesToday in my strategies and it works for me.

You probably should look into IOG and Barmagnifier settings of your strategy.

In realtime trading, every new tick will calculate your script unless you have coded "barstatus(1) = 2" in your logic. The same code in backtesting is calculating at barclose of the used chartresolution, unless you use IOG and Barmagnifier. That is why in backtest it will take the trade a bar later than in realtime.

I read that you use the portfolio trader(PFT), so the Barmagnifier is not an option, because this is unavailable in PFT. You could try IOG in the settings. This should get your backtest results closer to realtime. For the best accuracy you should use Barmagnifier on 1 tick with IOG. But you can not use PFT for this.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Problem with EntriesToday(Date)

Postby TJ » 26 Mar 2016

Hello, i have problem with EntriesToday(Date) and not with SetExitOnClose.
I test SetExitOnClose with Oanda many times and this work perfectly.
Russell 2000 is CFD.

Please, discuss in this thread about EntriesToday(Date).

When I add to signal print (log):

Code: Select all

print(date, " ", time, " ", EntriesToday(Date));

if EntriesToday(Date) < 1 and MarketPosition = 0 then
begin
buy next bar market;
end;

setexitonclose;
When I run backtest (after click to recalculate strategy):
1160324.00 1500.00 1.00
1160324.00 1515.00 1.00
1160324.00 1530.00 1.00
1160324.00 1545.00 1.00
1160324.00 1600.00 1.00
1160324.00 1615.00 1.00

When i run automatic trading (after click to SA):
1160324.00 1500.00 0.00
1160324.00 1515.00 0.00
1160324.00 1530.00 0.00
1160324.00 1545.00 0.00
1160324.00 1600.00 0.00
1160324.00 1615.00 0.00

In realtime mode Multicharts don't get orders from backtest.
It's a problem for me, because backtest (and optimalization) have another results than real trading.
EntriesToday(Date) is a function. You can open the code to see how it is written.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Problem with EntriesToday(Date)

Postby svopex » 26 Mar 2016

EntriesToday(Date) is a function. You can open the code to see how it is written.
Yes, I know.

EntriesToday code:

Code: Select all

:
inputs: TargetDate_YYYMMDD( numericsimple ) ;

variables: var0( 0 ) ;

var0 = 0 ;

for Value1 = 0 to 10
begin
condition1 = EntryDate( Value1 ) = TargetDate_YYYMMDD ;
if condition1 then
var0 = var0 + 1 ;
end ;

EntriesToday = var0 ;
Last edited by svopex on 26 Mar 2016, edited 3 times in total.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Problem with EntriesToday(Date)

Postby svopex » 26 Mar 2016

I use EntriesToday in my strategies and it works for me.

You probably should look into IOG and Barmagnifier settings of your strategy.

In realtime trading, every new tick will calculate your script unless you have coded "barstatus(1) = 2" in your logic. The same code in backtesting is calculating at barclose of the used chartresolution, unless you use IOG and Barmagnifier. That is why in backtest it will take the trade a bar later than in realtime.

I read that you use the portfolio trader(PFT), so the Barmagnifier is not an option, because this is unavailable in PFT. You could try IOG in the settings. This should get your backtest results closer to realtime. For the best accuracy you should use Barmagnifier on 1 tick with IOG. But you can not use PFT for this.
Hello, by my opinion problem is, that when I run Signal in real-time mode, EntriesToday calculate only with real-time orders. If I run strategy firstly (for example), there no-realtime orders and function return zero even if the backtest have order... IOG or Barmagnifier don't solve this.

I need function like "EntryDate", which returns backtest trades in real-time mode.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Problem with EntriesToday(Date)

Postby evdl » 26 Mar 2016

For what I can filter out of your posts, you describe two different issues.

- first issue: backtest results differ from realtime result.
- second issue: you see that "EntriesToday(date)" gives you different values in the print log with backtesting, compared to, the print log when you turned on the autotrader (SA button).

The first issue, I think, is due to the IOG and Barmagnifier settings.

The second "issue" is probably by design. Although I don't know why the function "EntriesToday(date)" is not updating the values in the print log of historical data, when SA modus is on (green). When SA modus is on, it will not display backtest results. And maybe some functions do not update on historical data when using the SA modus. Maybe MC support can say something about this. But in my opinion this is not the reason your backtest trades differ from realtime trades.

When debugging your code with print logs, do a normal backtest with the SA modus off.

Please try to turn on IOG. And do a backtest. Your will probably see that the trades are taking in the first bar, just like in realtime trading. IOG without Barmagnifier uses the OHLC values to calculate the strategy.

User avatar
svopex
Posts: 74
Joined: 16 Oct 2013
Has thanked: 7 times
Been thanked: 5 times
Contact:

Re: Problem with EntriesToday(Date)

Postby svopex » 26 Mar 2016

For what I can filter out of your posts, you describe two different issues.

- first issue: backtest results differ from realtime result.
- second issue: you see that "EntriesToday(date)" gives you different values in the print log with backtesting, compared to, the print log when you turned on the autotrader (SA button).

The first issue, I think, is due to the IOG and Barmagnifier settings.

The second "issue" is probably by design. Although I don't know why the function "EntriesToday(date)" is not updating the values in the print log of historical data, when SA modus is on (green). When SA modus is on, it will not display backtest results. And maybe some functions do not update on historical data when using the SA modus. Maybe MC support can say something about this. But in my opinion this is not the reason your backtest trades differ from realtime trades.

When debugging your code with print logs, do a normal backtest with the SA modus off.

Please try to turn on IOG. And do a backtest. Your will probably see that the trades are taking in the first bar, just like in realtime trading. IOG without Barmagnifier uses the OHLC values to calculate the strategy.
Yes, I 100% understand you.
When I use IOG, Multicharts can buy order inside first candle.
I test it and it works (backtest buy on the first candle).
Thanks, your explanation is perfect.

But I still have problem -
I have lot of strategies, which have been optimized with opposite functionality
- this strategies don't stop at the first candle... I must these strategies put in the trash... :-(


Return to “MultiCharts”