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

Viewing 9 posts - 1 through 9 (of 9 total)
  • #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.

     

    Of course there is the short side as well based on the same but opposite conditions mentioned above:

     


     

    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:

     

    However, 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

    #77252

    Welcome to the forums. I see that this is your first topic. Please use the ‘Insert PRT Code’ button when posting code in future posts as it makes it far easier for others to read.

    I have tidied up your post for you. 🙂

    #77255

    thank you, appreciated

    #77256

    The 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:

     

    #77264

    Thank 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>c

    LongSetup=c1 AND c2 AND c3

    Let’s assume:
    a= +0.018
    b= +0.25
    c= +0.10

    Long 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.08

    c1 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

    #77269

    this 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 met

    as 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 otherwise

    I hope this further clarifies what I’m trying to translate from the trading system into the indicator

    thanks again,
    emanuele

    #77273

     

    #77280

    As it is just an indicator then why have two variables – just use one?

     

    2 users thanked author for this post.
    #77282

    bingo. it looks perfect
    thank you very much for your help

Viewing 9 posts - 1 through 9 (of 9 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login