I have a question about the behavior of SessionLastBar during live trading, specifically with regards to sessions whose duration is reduced compared to the theoretical session on the chart, for example during holidays when the market may close a few hours earlier.
I saw a similar question being asked in viewtopic.php?t=50358, but I didn't solve my doubt entirely.
I can see that in backtest, the behavior of SessionLastBar is correct, even for shorter-than-normal sessions, but during backtest MultiCharts knows when the new session started, so in retrospect it can fix the value of SessionLastBar. I guess it doesn't have this information during live trading though, at least until the new session starts.
During live trading, does SessionLastBar really reflect the fact that the session has already ended, sooner than intended?
Example:
- let's assume IOG is disabled
- @ES future's session ends at 16:00 exchange time
- during holidays, the session may end sooner, say 13:00
- say I have a 15 minute chart, will SessionLastBar be correctly set to true when my strategy/indicator code is evaluated at the close of the bar that started at 12:45 and ended at 13:00?
SessionLastBar in live trading [SOLVED]
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
I read that thread but it doesn't fully clarify. Does that mean that my code will read the correct value in live trading when the session ends sooner? If so, how does MC know that the session has finished prematurely? Does it wait to see if it get data before evaluating my code? How about issues with the data feed? Wouldn't that either cause delays in evaluating my code and/or false positives in SLB being true when it's deemed to be false?
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
Please read the last reply by Angelina MultiСharts.I read that thread but it doesn't fully clarify. Does that mean that my code will read the correct value in live trading when the session ends sooner? If so, how does MC know that the session has finished prematurely? Does it wait to see if it get data before evaluating my code? How about issues with the data feed? Wouldn't that either cause delays in evaluating my code and/or false positives in SLB being true when it's deemed to be false?
@tj would you be so kind as to answer with an answer, if you know the answer? I've already mentioned that that post doesn't clarify it for me, and my question is whether this works in live, and if so, how.
More specifically, I understand that there is a timeout mechanism, but that post doesn't clarify if the timeout happens before or after my code is evaluated.
Ultimately my question is whether this works in live, and that post doesn't seem to answer the question.
More specifically, I understand that there is a timeout mechanism, but that post doesn't clarify if the timeout happens before or after my code is evaluated.
Ultimately my question is whether this works in live, and that post doesn't seem to answer the question.
- Vlada MultiCharts
- Posts: 301
- Joined: Apr 22 2020
- Has thanked: 8 times
- Been thanked: 78 times
Hello simoneb,
Here is more information about SessionLastBar and its restrictions in real-time.
It does not work if the last bar closes before the end of the session and the symbol no longer ticks (for example, it never works on 1 tick resolution).
It works with a delay of 5 minutes, and an order may be rejected, if the bar is not closed before the end of the session and the symbol is not ticking. The exit will be sent after the bar closes by 5 minutes CloseBarTimeout*.
Bar close timeout value is configured in the registry the following way:
1. Close MultiCharts and all its applications. Make sure that all processes are finished in Task Manager -> Details tab:
https://www.multicharts.com/trading-sof ... _Processes
2. Go to Windows Start menu and launch Regedit.exe (type in Regedit.exe and press Enter).
Please go to this path:
HKEY_CURRENT_USER\Software\TS Support\MultiCharts64 (your MultiCharts version) \Shaper
Double click CloseBarTimeout and set its value in seconds.
3. Start MultiCharts.
Note: The changes will be applied to all bars of all data series.
Here are possible ways to solve it.
1) If the symbol ticks well (at least once a minute until the very end of the real session)
One can reduce sessions by 1 minute and use SessionLastBar.
2) If the symbol ticks rarely (less than once a minute)
One can reduce sessions by 6 minutes and use SessionLastBar.
3) Use the following in the script
[AllowSendOrdersAlways = true]
[IntrabarOrderGeneration = true]
RecalcLastBarAfter(1)
SessionLastBar; // or your own exit
The drawback of this method is that IOG loads CPU and it cannot be used in Portfolio Trader.
4) Close a position at the end of the day by analyzing the time in your script. Ensure that the position is closed a little before the end of the session, otherwise the order may be not sent or rejected the broker.
Here is more information about SessionLastBar and its restrictions in real-time.
It does not work if the last bar closes before the end of the session and the symbol no longer ticks (for example, it never works on 1 tick resolution).
It works with a delay of 5 minutes, and an order may be rejected, if the bar is not closed before the end of the session and the symbol is not ticking. The exit will be sent after the bar closes by 5 minutes CloseBarTimeout*.
Bar close timeout value is configured in the registry the following way:
1. Close MultiCharts and all its applications. Make sure that all processes are finished in Task Manager -> Details tab:
https://www.multicharts.com/trading-sof ... _Processes
2. Go to Windows Start menu and launch Regedit.exe (type in Regedit.exe and press Enter).
Please go to this path:
HKEY_CURRENT_USER\Software\TS Support\MultiCharts64 (your MultiCharts version) \Shaper
Double click CloseBarTimeout and set its value in seconds.
3. Start MultiCharts.
Note: The changes will be applied to all bars of all data series.
Here are possible ways to solve it.
1) If the symbol ticks well (at least once a minute until the very end of the real session)
One can reduce sessions by 1 minute and use SessionLastBar.
2) If the symbol ticks rarely (less than once a minute)
One can reduce sessions by 6 minutes and use SessionLastBar.
3) Use the following in the script
[AllowSendOrdersAlways = true]
[IntrabarOrderGeneration = true]
RecalcLastBarAfter(1)
SessionLastBar; // or your own exit
The drawback of this method is that IOG loads CPU and it cannot be used in Portfolio Trader.
4) Close a position at the end of the day by analyzing the time in your script. Ensure that the position is closed a little before the end of the session, otherwise the order may be not sent or rejected the broker.
@Vlada thanks for your answer. The circumstance I'm describing is one whereby the symbol stops ticking, I believe, for example because it's a bank holiday and the session's duration is shortened by a few hours.
I am not sure, without having this knowledge in advance, how I can detect that the session is finishing earlier.
I do understand, as I would expect, that SessionLastBar will not work in this scenario, so I assume there also isn't a way to tell that the session is finishing earlier in my signal code and, in case I wanted to exit before the end of the session, I have no way to know that.
Is this correct?
I am not sure, without having this knowledge in advance, how I can detect that the session is finishing earlier.
I do understand, as I would expect, that SessionLastBar will not work in this scenario, so I assume there also isn't a way to tell that the session is finishing earlier in my signal code and, in case I wanted to exit before the end of the session, I have no way to know that.
Is this correct?
- Vlada MultiCharts
- Posts: 301
- Joined: Apr 22 2020
- Has thanked: 8 times
- Been thanked: 78 times
simoneb,@Vlada thanks for your answer. The circumstance I'm describing is one whereby the symbol stops ticking, I believe, for example because it's a bank holiday and the session's duration is shortened by a few hours.
I am not sure, without having this knowledge in advance, how I can detect that the session is finishing earlier.
I do understand, as I would expect, that SessionLastBar will not work in this scenario, so I assume there also isn't a way to tell that the session is finishing earlier in my signal code and, in case I wanted to exit before the end of the session, I have no way to know that.
Is this correct?
Yes, that is correct.