Make a trade on each candle
Forums › ProRealTime English forum › ProOrder support › Make a trade on each candle
- This topic has 18 replies, 4 voices, and was last updated 3 years ago by Vonasi.
-
-
12/22/2020 at 11:29 PM #154931
I want to open and close a trade on each candle.
With “IF on market Then sell at market” it only trades every second candle.
Is there another way? Tried MTF but it would only trade longs or shorts! Not both.
Any help gratefully appreciated.
12/23/2020 at 12:44 AM #154935There you go:
123defparam cumulateorders = falsesell at marketbuy at market12/23/2020 at 8:26 AM #154943Basically Roberto’s code will open a trade on the first candle and then after that every BUY order will be cancelled by a SELL order so you will just stay on the market forever!
Do you mean that you want a position to be opened at start of a candle if conditions are met and then closed mid candle or at the close of the candle if not closed mid candle?
You mention long and short. It is not possible to be both long and short at the same time in an auto strategy.
12/23/2020 at 10:40 PM #155054I still cannot get this to work. Started with a new code. See attachment “MySystem19”. This traded every candle.
Then I put in “my conditions” and copied and pasted the closing arguments from MySystem19 (see attachment “MySystems21″)
My conditions is 200ma <> previous candle.
When I ran it, it does not trade the next candle even if the conditions are met. (see attachment” 877 screen copy”)
It should trade every candle!
Can you please help me work out what I am doing wrong?
Thanks in advance.
12/23/2020 at 11:08 PM #155061If the code is not massive then you are better to use the ‘Insert PRT Code’ button and post the strategy code directly in your post. Just attaching an ITF file means that someone who wants to help you has to download a file, open their platform, import a file, guess which instrument and time frame you are applying it to and then finally look at the code to see where the error is. This is even less likely to happen if the markets are closed and no one has their platform open! 🙂
Inserting the code in your post will get far more eyes on it far sooner.
12/24/2020 at 12:23 AM #15506212345678OT LongOnMarket THENBUY 1 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket THENSELL AT MARKETENDIFMy apologies Vonasi. I had been corrected by the moderator to attach the code as it was more readable.
But I am aware of the different level, and I can understand where you are coming from.
I will add the codes below
Here is the first code that trades every candle-
1234567891011// Conditions to enter short positionsIF NOT ShortOnMarket THENSELLSHORT 1 CONTRACTS AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket THENEXITSHORT AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets hereHere is the second code, with conditions, that only trades every other candle – see screenshot
123456789101112131415161718192021222324252627282930// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[200](close)indicator2 = Average[200](close)c1 = (indicator1 > indicator2[1])IF c1 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator3 = Average[200](close)indicator4 = Average[200](close)c2 = (indicator3 < indicator4[1])IF c2 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket THENEXITSHORT AT MARKETENDIF12/24/2020 at 1:25 AM #155066This will enter every other candle:
1234567891011121314// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// exit any open positionSELL AT MARKETEXITSHORT AT MARKET// Conditions to enter positionsindicator1 = Average[200](close)indicator2 = Average[200](close)c1 = (indicator1 > indicator2[1])IF c1 THENBUY 1 CONTRACT AT MARKETelseSELLSHORT 1 CONTRACT AT MARKETENDIFThis will enter each candle:
1234567891011121314// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// exit any open positionSELL AT MARKETEXITSHORT AT MARKET// Conditions to enter positions//indicator1 = Average[200](close)//indicator2 = Average[200](close)//c1 = (indicator1 > indicator2[1])//IF c1 THENBUY 1 CONTRACT AT MARKET//elseSELLSHORT 1 CONTRACT AT MARKET//ENDIF12/24/2020 at 1:35 AM #155069Code in text format.
MySystem19. This trades every candle
12345678910111213141516171819// Conditions to enter long positionsIF NOT LongOnMarket THENBUY 1 CONTRACTS AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket THENSELLSHORT 1 CONTRACTS AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket THENEXITSHORT AT MARKETENDIFMySystem21. This one only trades every candle.
How do I make this trade every candle?
123456789101112131415161718192021222324252627282930// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = Average[200](close)indicator2 = Average[200](close)c1 = (indicator1 > indicator2[1])IF c1 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator3 = Average[200](close)indicator4 = Average[200](close)c2 = (indicator3 < indicator4[1])IF c2 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket THENEXITSHORT AT MARKETENDIF12/24/2020 at 1:37 AM #15507012/24/2020 at 2:12 AM #155072This code will open/close each candle, provided conditions are different each candle:
1234567891011121314// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// exit any open positionSELL AT MARKETEXITSHORT AT MARKET// Conditions to enter positionsindicator1 = Average[200](close)indicator2 = Average[200](close)c1 = (indicator1 > indicator2[1])IF c1 THENBUY 1 CONTRACT AT MARKETelseSELLSHORT 1 CONTRACT AT MARKETENDIFbecause when conditions are different it always enters doing Stop & Reverse, while if conditions aree the sane as the previous candle:
- if CumulateOrders = FALSE then it can’t open another trade in the same direction, because it needs one candle before it knows the trade had been closed a few lines above
- if CumulateOrders = TRUE then it will accumulate positions in the same direction.
To recap, you can open/close a trade every candle only by doing Stop & Reverse, that is when conditions are different from the previous candle.
12/24/2020 at 5:12 AM #155075Still not working. There are different conditions to Buy & Sell – 200ma < or > previous candle.
1.Have set cumulating positions to True.
2. Closed any open positions.
The code is still only trading every other candle even when the conditions are true.
See attachment.
Latest code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182// Cumulating positions allowedDEFPARAM CumulateOrders = True// Exit any open positionsSELL AT MARKETEXITSHORT AT MARKET// Conditions to enter long positions//c1 = (close > open)// MAs > previous candleindicator1 = Average[200](close)indicator2 = indicator1c2 = (indicator1 > indicator2[1])indicator3 = Average[100](close)indicator4 = indicator3c3 = (indicator3 > indicator4[1])indicator5 = Average[50](close)indicator6 = indicator5c4 = (indicator5 > indicator6[1])indicator7 = Average[25](close)indicator8 = indicator7c5 = (indicator7 > indicator8[1])indicator9 = Average[12](close)indicator10 = indicator9c6 = (indicator9 > indicator10[1])indicator11 = Average[6](close)indicator12 = indicator11c7 = (indicator11 > indicator12[1])indicator13 = Average[3](close)indicator14 = indicator13c8 = (indicator13 > indicator14[1])//indicator15 = Average[1](close)//indicator16 = indicator15//c9 = (indicator15 > indicator16[1])IF NOT LongOnMarket AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit positions// closes end of candleIF LongOnMarket THENSELL AT MARKETENDIF// Conditions to enter short positions// MAs < previous candle//c10 = (close < open)indicator17 = Average[200](close)indicator18 = indicator17c11 = (indicator17 < indicator18[1])indicator19 = Average[100](close)indicator20 = indicator19c12 = (indicator19 < indicator20[1])indicator21 = Average[50](close)indicator22 = indicator21c13 = (indicator21 < indicator22[1])indicator23 = Average[25](close)indicator24 = indicator23c14 = (indicator23 < indicator24[1])indicator25 = Average[12](close)indicator26 = indicator25c15 = (indicator25 < indicator26[1])indicator27 = Average[6](close)indicator28 = indicator27c16 = (indicator27 < indicator28[1])indicator29 = Average[3](close)indicator30 = indicator29c17 = (indicator29 < indicator30[1])//indicator31 = Average[1](close)//indicator32 = indicator31//c18 = (indicator31 < indicator32[1])IF NOT ShortOnMarket AND c11 AND c12 AND c13 AND c14 AND c15 AND c16 AND c17 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit positions// closes at end of candleIF ShortOnMarket thenEXITSHORT AT MARKETENDIF12/24/2020 at 6:41 AM #155090You’ve been posting several code snippets without using the ‘Insert PRT Code’ button, please respect the rules as highlighted below in yellow.
As I explained, if conditions are the same direction as the previous candle a trade cannot be opened the following candle.
There’s no workaround. You either change your conditions so that they always imply doing a Stop & Reverse each candle or change your strategy.
1 user thanked author for this post.
12/24/2020 at 9:21 AM #15509712/24/2020 at 9:25 AM #155099You’ve been posting several code snippets without using the ‘Insert PRT Code’ button, please respect the rules as highlighted below in yellow.
Wow. Did it maybe occur to you that you refer to a button which you know but others may not ?
1 user thanked author for this post.
12/24/2020 at 9:30 AM #155101Wow. Did it maybe occur to you that you refer to a button which you know but others may not ?
We assume that everyone is aware that the tools available for editing your posts can be found in the tool box attached to the box where you are typing. Perhaps we make too much of an assumption regarding everyone’s abilities.
The button in your image is not the correct one. That is for posting to the library. See the image in my previous post for the correct button. 🙂
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on