Preventing re-entry
Forums › ProRealTime English forum › ProOrder support › Preventing re-entry
- This topic has 6 replies, 4 voices, and was last updated 5 years ago by
Nicolas.
-
-
01/30/2020 at 12:12 PM #118265
I’m sure this will be simple for any of the experts on here, so if you could spare a minute I’d be very grateful…
I have a program that only enters trades in pre-defined time zones. I want it to only enter once during each time zone. I’ve tried very hard to read the manual and understand ONCE statements but I can’t seem to make them work. I also think there might be a simple solution to make my “entered=1” flag work at the right times, without needing a ONCE.
I’ve attached a screengrab of what my entered flag is currently doing. In short, I want “entered” to remain at 1 until the end of the current time zone (in this case, until 100600). It currently dips to zero once the first entry is finished and allows another entry, which I don’t want. Or alternatively I’d be happy for it to remain at 1 and be reset by the new time zone (in this case, 155200).
Any ideas?
Current code123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111DEFPARAM CumulateOrders = Falsedaystart= 060000dayend= 160000longentry1= close crosses over SuperTrend[1.5,34]shortentry1= close crosses under SuperTrend[1.5,34]longexit1= close crosses under SuperTrend[1.5,34]shortexit1= close crosses over SuperTrend[1.5,34]tue1start=000000tue1end=004200tue2start=035200tue2end=044000tue3start=091800tue3end=100600tue4start=155200tue4end=164000tue5start=184600tue5end=193400tue6start=000000tue6end=000034tue7start=0tue7end=0tue8start=0tue8end=0wed1start=001200wed1end=001000wed2start=065000wed2end=073800wed3start=081200wed3end=085800wed4start=094600wed4end=103400wed5start=150400wed5end=155200wed6start=182800wed6end=191600wed7start=220800wed7end=224800wed8start=0wed8end=0entered=0tuesday=0wednesday=0timezone=0if onmarket thenentered=1endifif time >= daystart and time <= dayend thentimezone=1endifif timezone=1 thenif time >=tue1start and time <=tue1end or time >=tue2start and time <=tue2end or time >=tue3start and time <=tue3end or time >=tue4start and time <=tue4end or time >=tue5start and time <=tue5end or time >=tue6start and time <=tue6end or time >=tue7start and time <=tue7end or time >=tue8start and time <=tue8end thentuesday=1endifif not entered=1 and opendayofweek=2 and tuesday=1 and longentry1 thenBUY 1 PERPOINT AT MARKETentered=1endifendifif timezone=1 thenif time >=tue1start and time <=tue1end or time >=tue2start and time <=tue2end or time >=tue3start and time <=tue3end or time >=tue4start and time <=tue4end or time >=tue5start and time <=tue5end or time >=tue6start and time <=tue6end or time >=tue7start and time <=tue7end or time >=tue8start and time <=tue8end thentuesday=1endifif not entered=1 and opendayofweek=2 and tuesday=1 and shortentry1 thenSellshort 1 PERPOINT AT MARKETentered=1endifendifif timezone=1 thenif time >=wed1start and time <=wed1end or time >=wed2start and time <=wed2end or time >=wed3start and time <=wed3end or time >=wed4start and time <=wed4end or time >=wed5start and time <=wed5end or time >=wed6start and time <=wed6end or time >=wed7start and time <=wed7end or time >=wed8start and time <=wed8end thenwednesday=1endifif not entered=1 and wednesday=1 and opendayofweek=3 and longentry1 thenBUY 1 PERPOINT AT MARKETentered=1endifendifif timezone=1 thenif time >=wed1start and time <=wed1end or time >=wed2start and time <=wed2end or time >=wed3start and time <=wed3end or time >=wed4start and time <=wed4end or time >=wed5start and time <=wed5end or time >=wed6start and time <=wed6end or time >=wed7start and time <=wed7end or time >=wed8start and time <=wed8end and opendayofweek=3 thenwednesday=1endifif wednesday=1 and not entered=1 and opendayofweek=3 and shortentry1 thenSellshort 1 PERPOINT AT MARKETentered=1endifendifif longonmarket and longexit1 thensell at close stopendifif shortonmarket and shortexit1 thenexitshort at close stopendifgraph entered01/30/2020 at 12:36 PM #118270Lines 28-29 are a bit odd, starting time is AFTER ending time.
You should define a flag variable for each TZ, say tueFlag1, tueFlag2,… then wedFlag1, wedFlag2,… and set them to 1 each new day (when IntraDayBarIndex = 0).
Then whenever you enter a trade, be it Long or Short, set each one of them (according to correct TZ at that moment) to 0. You’ll have to use multiple IF…ENDIF blocks to achieve that.
Finally you’ll have to add each one of those flags to your conditions to open a trade.
You will have to add tens of lines of code (with IF…ENDIF) to your code to achieve that.
If you are patient enough to wait a few months you will take advantage of the upcoming ARRAY support (now in the works) which will make this job way too esier!
1 user thanked author for this post.
01/30/2020 at 5:31 PM #118287Thanks for the suggestion. I’ll try it out later.
Yes, I must say I was surprised that there wasn’t a specific array function when I first looked through the PRT manual. I think it will shorten a lot of our code once it comes out!
01/31/2020 at 3:10 PM #118360Roberto,
I’ve tried to follow your instructions but I still can’t get it right. I’ve simplified the code to be just one time zone so it is easier for us to understand.
As you can see from the screengrab, tueflag1 correctly becomes 1 at the beginning of the time zone and then correctly becomes 0 when I enter the market. But the problem is that the flag resets itself to 1 on the next bar. How can I stop the flag reseting itself to 1?
Simplified code12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849DEFPARAM CumulateOrders = Falsedaystart= 000000dayend= 160000longentry1= close crosses over SuperTrend[1.5,34]shortentry1= close crosses under SuperTrend[1.5,34]longexit1= close crosses under SuperTrend[1.5,34]shortexit1= close crosses over SuperTrend[1.5,34]tue1start=041200tue1end=052600if intradaybarindex=0 thentueflag1=0endifif time >= daystart and time <= dayend thentimezone=1endifif timezone=1 thenif time >=tue1start and time <=tue1end and opendayofweek=2 thentueflag1=1endifendifif not onmarket and tueflag1=1 and longentry1 thenBUY 1 PERPOINT AT MARKETtueflag1=0endifif not onmarket and tueflag1=1 and shortentry1 thenSellshort 1 perpoint at markettueflag1=0endifif longonmarket and longexit1 thensell at close stopendifif shortonmarket and shortexit1 thenexitshort at close stopendifgraph tueflag101/31/2020 at 4:46 PM #118375Only switch the flag at the beginning and end. Change lines 24 to 28 to:
123456789if timezone=1 thenif time=tue1start and opendayofweek=2 thentueflag1=1endifif time=tue1end and opendayofweek=2 thentueflag1=0endifendif2 users thanked author for this post.
01/31/2020 at 6:42 PM #118386Thank you!
Oh man I was so stupid! I now realise that “time >=X and time <=X” creates a constant positive loop within that zone.
02/03/2020 at 9:42 AM #118524there wasn’t a specific array function when I first looked through the PRT manual. I think it will shorten a lot of our code once it comes out!
Indeed! and i’m currently testing it. Array works very well so far as an alpha version and it’s pleasant now to know that we can almost code anything with them.
-
AuthorPosts
Find exclusive trading pro-tools on