Code not executed at the given interval
Forums › ProRealTime English forum › ProOrder support › Code not executed at the given interval
- This topic has 15 replies, 3 voices, and was last updated 1 year ago by sriramtgi.
-
-
04/10/2023 at 3:47 PM #213065
Firstly my appreciation for this Prorealtime software. I am not a programmer, but I was able to learn and code so easily. Amazing stuff.
I wrote a code. The idea is to attach to 1 minute candle, so it execute at every minute. But the code is not getting executed at every minute, but at different interval. Sometimes I could not understand the logic when it gets triggered. What am I doing wrong. This is the simplest martingale code checking the previous candle . There are infact 3 issues. Please help me. Kindest regards.
- The Code doesn’t get executed at every minute as expected
- I donot know why After 1,2 the ordersize goes to 8
- The Code checking the CurrentMinute doesn’t work. I thought I will buy at 1 minute and sell at 59th minute.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748ONCE OrderSize = 1//IF CurrentMinute = 59 THEN//ENDIF//IF CurrentMinute = 1 THENisBullish = 0isBearish = 0IF Close[0] >= Open[0] THENisBullish = 1ENDIFIF Close[0] < Open[0] THENisBearish = 1ENDIFIF isBullish = 1 THENIF PositionPerf(0) < 0 THENOrderSize = OrderSize*2ELSIF PositionPerf(0) >= 0 THENOrderSize = 1ENDIFIF LongOnMarket THENSELL OrderSize LOTS AT MARKETENDIFIF ShortOnMarket THENBUY OrderSize LOTS AT MARKETENDIFBUY OrderSize CONTRACTS AT MARKETENDIFIF isBearish = 1 THENIF PositionPerf(0) < 0 THENOrderSize = OrderSize*2ELSIF PositionPerf(0) >= 0 THENOrderSize = 1ENDIFIF LongOnMarket THENSELL OrderSize LOTS AT MARKETENDIFIF ShortOnMarket THENBUY OrderSize LOTS AT MARKETENDIFSELLSHORT OrderSize CONTRACTS AT MARKETENDIF04/10/2023 at 4:25 PM #21306704/11/2023 at 9:04 AM #213085Code is read one time at candlestick Close and order is launch at next open. So a visual decay is observed and you might get lost on this.
Also, to open a SHORT position, use SELLSHORT instruction. SELL keyword is to close a long (BUY) position.
1 user thanked author for this post.
04/11/2023 at 9:11 AM #213086Dear Nucolas,
Thanks for the response.
Even in that case, the execution should be at the end of every candlestick. How come it misses out on many candles. Also apart from non execution, the lotsize also is different and not martingale as coded.
I have used SELLSHORT when I donot find any long position. Refer the last sell line.
04/11/2023 at 2:03 PM #213107All the Orders below will just trade at the start of each new bar as there are no conditions attached to the Orders so they always be True so they will always Trade?
Unless I have missed something?
123456789IF LongOnMarket THENSELL OrderSize LOTS AT MARKETENDIFIF ShortOnMarket THENBUY OrderSize LOTS AT MARKETENDIFSELLSHORT OrderSize CONTRACTS AT MARKETENDIF04/11/2023 at 2:08 PM #213108Unless I have missed something?
Yes you have GraHal … I just spotted the If Bearish / If Bullish Conditions higher up your code.
04/11/2023 at 2:32 PM #213109Yes Grahal, I have a bullish or bearish check.
But as per Nicolas, the code will be executed at the end of the candle stick. My problem is that the execution doesn’t happen for every candle as shown in the attachment. The lotsizes doesn’t increase as double, but 1,4 and sometimes 1,2,8.Moreover the syntax “CurrentMinute” variable doesn’t work.
Do you see the reason?
04/11/2023 at 3:13 PM #213111“CurrentMinute” variable doesn’t work.
The code in your OP, shows both references to CurrentMinute as // commented out, but I guess you know that?
So If CurrentMinute = 1 (end of bar) then Orders would be executed in CurrentMinute = 2 (at open of next bar) … are you taking this into account?
04/11/2023 at 3:29 PM #213112sometimes 1,2,8
Have you investigated if the missing ‘4’ was an exit ordersize (as you use ordersize in your exits alsso)?
04/12/2023 at 7:17 AM #213156I commented because it didn’t work. I gave for 59th minute and 1st minute.
There was no 4 in exit or entry, it just jumped to 8 or sometimes 16. I think it all had to do with the non execution of this code at every minute which is a basic problem.
- The code must get triggered at every candle, but it doesn’t.
04/12/2023 at 8:58 AM #213159From Line 22 to Line 29 at every bar you check if Long then Sell, If Short then Buy … there seems not much chance for any trade to accumulate profit?
What Timefame does the System run on?
Have you tried using below, at the bottom of your Code, so you can easily see when trades are triggered …
GRAPH LongTriggered
GRAPH ShortTriggered1 user thanked author for this post.
04/12/2023 at 10:10 AM #213169The idea is to trade at 1st second and close at the 59th second.
Trade depends on previous candle bring bullish or bearish.
1) the code must get triggered every minute which is not happening
2) the martingale logic not working.. Donot know why as it seems right. This also could be tagged to previous one
3) CurrentMinute didn’t work so commented out
The code 22 to 27, I had vide this way because current minute is not working and I had to close any open position before I buy or sell for this current candle
Thanks for your help and guidance.
I have little experience in coding..
04/12/2023 at 10:11 AM #21317004/12/2023 at 2:28 PM #21319204/12/2023 at 3:21 PM #213193 -
AuthorPosts
Find exclusive trading pro-tools on