Two conditions met in side by side candles, is it possible to open a position?
Forums › ProRealTime English forum › ProOrder support › Two conditions met in side by side candles, is it possible to open a position?
- This topic has 8 replies, 4 voices, and was last updated 8 years ago by robdav.
-
-
01/07/2017 at 2:26 PM #20118
I am developing a system that has two conditions required to open a position. Sometimes these conditions come together in the same candle so it is easy to open the position.
However, sometimes one condition happens in one candle and the second in the next candle. Is it possible to code in order to catch this happening and then open the position? The candles are always side by side or I’m not interested.
Does anyone know if this is possible? If so could you please provide some sample code?
Many thanks
Robert
01/07/2017 at 3:41 PM #20121Yep.
Example: If indicator1 >= indicator2 and ma5 crosses over ma20 then
1 user thanked author for this post.
01/07/2017 at 4:03 PM #2012301/07/2017 at 5:04 PM #2012501/07/2017 at 6:13 PM #20127I actually realised there are three scenarios to cater for.
- Both conditions happening in one candle
- Condition 1 in the first candle and condition 2 in the second candle
- Condition 2 in the first candle and condition 1 in the second candle
So I took the example from Nicolas’s code here https://www.prorealcode.com/topic/rsi-sab-strategy/
However, close[1]=indicator2 and close=indicator1 will be useful as well.
Thanks.
01/08/2017 at 12:39 PM #20163Hi Kasper
Does this “Close[1]=indicator2 and close=indicator1” definitely work with indicators and not just price functions? I can’t seem to get it to act but from GRAPH output I can see the conditions are being met in the two candles.
Thanks
Rob
01/08/2017 at 1:04 PM #2016601/08/2017 at 2:16 PM #20181Hi,
You store your 2 conditions in c1 and c2, I don’t know what they are but let’s take these 2 just for the sake of illustrating with an ewample:
12c1 = (a>b)c2 = (c>d)then c1 and c2 will return at each candle a result true (equal to 1) or false (equal to 0) depending of course in this example of a,b,c,d behaviour, and it’s worth knowing there are two ways checking a condition to be true in any “if” statement: either writing “if c1=1 then…” or just writing “if c1 then…” you can drop the =1 it makes it faster the code knows and interprets it as “if c1 is true then…”
from there, using [1] after any variable name will call the value of that variable at the previous candle, this is true for conditions too (they are nothing else than just a variable equal to 0 or 1)
so your 3 scenarios can be checked with the simple following “if” statement:
123if (c1 and c2) or (c1[1] and c2) or (c1 and c2[1]) then...insert what you want to do when the line above is trueendifthe rest is up to you…
01/08/2017 at 4:54 PM #20202 -
AuthorPosts
Find exclusive trading pro-tools on