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 avatarLeo.
Viewing 15 posts - 1 through 15 (of 29 total)
  • #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 :

    but unfortunately this does not work and it does not open any position at any time.

    This works :

    It 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

    is 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 ?

    #65757

    At 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.

    1 user thanked author for this post.
    #65758

    I tried something with “If barindex = 1”, but it did not work. Maybe in conjunction with tradeindex ? I will try. Thank you, GraHal.

    #65759

    Also, I am not sure that barindex = 1 in the very first bar, because I think that the pre-loaded bars are also counted.

    #65761

    At 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 :

    This opens a position in the DAX 1 minute chart immediately after the start of the system ! Thank you, GraHal, again !

    #65763

    This works, but you have to exit the next bar!

     

    #65765

    This 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.

    #65766

    Verdi55 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?

     

    #65767

    I think the problem are the pre-loaded bars. The reason why

    does 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.

    #65768

    Verdi55 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.
    #65770

    I think the problem are the pre-loaded bars. The reason why

    does 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

    are 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.

    #65771
    Leo

    What if you use a condition like

    It will cheating the preload bars.

    1 user thanked author for this post.
    #65772

    So the system now opened a new short position immediately. But I forgot to change the stops and limits, because of course the entry price will be different from the regular original position. It is a little more complicated.

    #65773

    What if you use a condition like

    It 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.

    #65783
    Leo

    Needs 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

Viewing 15 posts - 1 through 15 (of 29 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login