How do I open a position in the first bar of a newly started trading system ?
Forums › ProRealTime English forum › ProOrder support › How do I open a position in the first bar of a newly started trading system ?
- This topic has 28 replies, 5 voices, and was last updated 6 years ago by Leo.
-
-
03/19/2018 at 10:00 PM #65755
but never again later, even when the system is “not onmarket” ?
So, I would like to open a position immediately after the start of a trading system (in demo mode), only once at the end of the first bar.
I tried :
123456ONCE flag = 0If flag = 0 thenbuy 1 contract at marketflag = 1endifbut unfortunately this does not work and it does not open any position at any time.
This works :
123If not onmarket thenbuy 1 contract at marketendifIt buys 1 contract immediately after the start of the system, at the end of the first bar. But this code would also buy later on again, when there is no position open, not only once.
The simplest code
1ONCE buy 1 contract at marketis not allowed and recognized as a syntax error.
My rationale is that I would like to restart a trading system that has been stopped erroneously, by some external interaction or error, for example.
So, when I know that the normal regular system is currently long, but the long position has been erroneously closed because the system stopped, I would like to restart the system and open this long position immediately at the end of the first bar and treat it as the regular long position that was open before. But of course, such a “manual” position should never be opened later on again, and the system should just continue on its regular path. Has anyone any ideas ? Or do I not see the simplest solution ?
03/19/2018 at 10:19 PM #6575703/19/2018 at 10:21 PM #6575803/19/2018 at 10:26 PM #6575903/19/2018 at 10:38 PM #65761At the close of the first bar then barindex = 1 so work barindex into the code somehow? Also at barindex = 1 then tradeindex = 1 but never will again.
Haha, the following works :
12345defparam preloadbars = 1000If barindex = 1000 thenbuy 1 contract at marketendifThis opens a position in the DAX 1 minute chart immediately after the start of the system ! Thank you, GraHal, again !
03/19/2018 at 10:38 PM #65763This works, but you have to exit the next bar!
12345678910ONCE Flag = 0if OnMarket thensell at marketflag = 1endifIf not OnMarket and Flag = 0 thenbuy 1 contracts at marketendif03/19/2018 at 10:41 PM #65765This works, but you have to exit the next bar!
Well, this is what I don’t want, I want to treat the position just as a regular position of a complete trading system. Maybe with the barindex trick, it will work.
03/19/2018 at 10:47 PM #6576603/19/2018 at 10:47 PM #65767I think the problem are the pre-loaded bars. The reason why
123456ONCE flag = 0If flag = 0 thenbuy 1 contract at marketflag = 1endifdoes not work, is that the ONCE commands are not executed at the beginning of the trading system, but at barindex = 1, which is the first of the pre-loaded bars in the past.
03/19/2018 at 10:50 PM #65768Verdi55 are you going to work the code so it caters for where a Long or a Short was the Trade type when external interaction or error stopped the system?
Yes. One of my demo systems was stopped today (or I stopped it erroneously because I used the new IG platform I was not familiar with), with a short position open and a gain of 145 points. So I wanted to restart the whole system 5 minutes later just by adding some lines at the beginning, saying, please open this short position immediately again. But it did not. I’ll try again with the barindex commands, I think it should work then.
1 user thanked author for this post.
03/19/2018 at 10:58 PM #65770I think the problem are the pre-loaded bars. The reason why
123456ONCE flag = 0If flag = 0 thenbuy 1 contract at marketflag = 1endifdoes not work, is that the ONCE commands are not executed at the beginning of the trading system, but at barindex = 1, which is the first of the pre-loaded bars in the past.
I think even the lines
1234If flag = 0 thenbuy 1 contract at marketflag = 1endifare being executed on the pre-loaded bars before the start of the trading system. This is why flag = 1 is always true before the first real bar, and so no position is ever opened.
We need to know the number of preloaded bars and count the first bar after opening as this number.
03/19/2018 at 11:07 PM #6577103/19/2018 at 11:09 PM #6577203/19/2018 at 11:09 PM #65773What if you use a condition like
1if CurrentMinute=time thenIt will cheating the preload bars.
good idea, thank you. Needs to be combined with today’s date, too, and time must be the time of the first bar.
03/20/2018 at 5:42 AM #65783Needs to be combined with today’s date, too, and time must be the time of the first bar.
not at all, you need to create a varible, like robertogozzi ‘s code.
CurrentMinute=time will be true for every bar except the preloaded bars
-
AuthorPosts
Find exclusive trading pro-tools on