Boolean 1 -1 to replicate a trading system long or short conds in indicator
Forums › ProRealTime English forum › ProBuilder support › Boolean 1 -1 to replicate a trading system long or short conds in indicator
- This topic has 8 replies, 2 voices, and was last updated 6 years ago by ga2quae.
-
-
08/01/2018 at 9:23 AM #77248
Dear everyone,
I wrote a Long / Short code (into backtest mode to test its effectiveness), pretty simple but it works and I’m happy with it.
12345678910111213141516171819202122232425// Conditions to enter long positionsc1= a>0c2= b>0c3= b>cIF c1 AND c2 AND c3 THENBUY 1 SHARES AT MARKETENDIF// Conditions to exit long positionsc4= a<0c5= b<0c6= b<cIF c4 AND c5 AND c6 THENSELL AT MARKETENDIFOf course there is the short side as well based on the same but opposite conditions mentioned above:
12345678910111213//conditions to enter short positionsIF c4 AND c5 AND c6 THENSELLSHORT 1 SHARES AT MARKETENDIF// Conditions to exit short positionsIF c1 AND c2 AND c3 THENEXITSHORT AT MARKETENDIF
As mentioned, I#m happy with that and I would like to “translate” thy simple system into a boolean +1 (when Long condition is met I would like the system to keep sowing +1 until the short condition is met), -1(when the short condition is met and keep showing -1 until the long condition is met again; then boolean flips to +1 until short condition is met and then flips to -1, etc..)
So far I coded the following:
12345678910111213141516171819LongSetup=c1 AND c2 AND c3ShortSetup=c4 AND c5 AND c6IF LongSetup THENTrendUP=1ENDIFIF Short Setup THENTrendDown=-1ENDIFHowever, the system test for the validity of condition LongSetup or ShortSetup at any bar , and if it happen that neither LongSetup nor Short Setup are met, then boolean return zero. This is not what I want, as I would like the Boolean to go 1 when LongSetup is met AND stay 1 until ShortSetup is met.
Does anyone know how I can write that ?
Thank you in advance for your help,
Emanuele
08/01/2018 at 9:33 AM #7725208/01/2018 at 9:42 AM #7725508/01/2018 at 9:44 AM #77256The code you have provided would just set the values at + 1 and -1 and then never change them so I’m confused why you think they return to zero. Try this:
123456789101112LongSetup=c1 AND c2 AND c3ShortSetup=c4 AND c5 AND c6IF LongSetup THENTrendUP = 1trenddown = 0ENDIFIF ShortSetup THENTrendDown = -1trendup = 0ENDIF08/01/2018 at 10:09 AM #77264Thank you, for the advice, however those conditions return 0 more often than you think.
system returns trendUP only when ALL c1 AND c2 AND c3 are met .
the fact that one variable among c1 or c2 or c3 doesnot meet its condition, it s nto by itself enough to negate the trend.
for example:c1= a>0
c2= b>0
c3= b>cLongSetup=c1 AND c2 AND c3
Let’s assume:
a= +0.018
b= +0.25
c= +0.10Long setup condition is met. and system returns 1. that s fine
now let’s go on with the example and after few bars, the values are now
a= -0.011
b= +0.22
c=+0.08c1 is not met anymore, as a<0
while c2 and c3 are still valid.
system would return zero in this case (as the Short setup conditions are not met either)so, what I need is to keep plotting 1 until all c1 and c2 and c3 flips to make c4 and c5 and c6 true and trigger system to go -1
it complicated to say by words, but it is very straightforward in practice (think about the trading system. when longsetup is true, system buy at market, and system stays long the market until shortsetup becomes true, then system sells its holding and also sells short. then system stays short until longsetup becomes true again)
I hope I clarified the issue I’m facing, but if you still have doubts, pls let me know, cheers
08/01/2018 at 10:20 AM #77269this is how the indicator would like like when applying the code you kindly suggested:
dark green= trendUP condition is met
Dark red= TrendDOWN condition is metas you can see, there are tons of points were trend is zero and no bar shows up.
In the panel above, I shows how the trading system looks like applying the same conditions TrendUP and TrendDOWN
In Blue, the trendUP condition is met and triggers the buy order at market, and system stays long until proven otherwise
In orange, the trendDOWN condition is met and the system sells to close the long and open a new short at market, system then stays short until proven otherwiseI hope this further clarifies what I’m trying to translate from the trading system into the indicator
thanks again,
emanuele08/01/2018 at 10:28 AM #77273123456789101112//I believe I can input something like this:IF LongSetup THENTrendUP=1 "until ShortSetup is triggered"ENDIFIF ShortSetup THENTrendDOWN=-1 "until LongSetup is triggered"ENDIF//how can I code something like this ?//thanks08/01/2018 at 10:54 AM #77280As it is just an indicator then why have two variables – just use one?
12345678910111213141516LongSetup=c1 AND c2 AND c3ShortSetup=c4 AND c5 AND c6IF LongSetup THENTrend = 1r = 0g = 128ENDIFIF ShortSetup THENTrend= -1r = 128g = 0ENDIFreturn trend coloured(r,g,0) style(histogram, 2)08/01/2018 at 11:03 AM #77282 -
AuthorPosts
Find exclusive trading pro-tools on