crossing higher than previous crossing

Forums ProRealTime English forum ProBuilder support crossing higher than previous crossing

Viewing 14 posts - 1 through 14 (of 14 total)
  • #198716

    I have an indicator that has two MA-lines (line p and q), just like the MACD-line and its signal-line. I want to build a system that goes long when p crosses over q AND when this crossing is higher than the previous crossing (because then there is the change of nice rising pattern). Similar: go short when p crosses under q AND this crossing is lower than the previous crossing.
    My knowlegde of programming is not enough. I tried this code but it is not working:

    IF p CROSSES OVER q THEN
    a = p
    ENDIF
    IF p CROSSES UNDER q THEN
    b = p
    ENDIF

    //Conditions for long
    c1 = (p CROSSES OVER q)
    IF c1 AND a > a[1] THEN
    BUY 1 SHARES AT MARKET
    ENDIF

    Who can help? Thanks!

     

     

    #198726
    JS

    Hi @Vogeltje

    I have a comment about the “previous crossing”

    For example, if the “FastMA crosses over SlowMA” then the “previous crossing” must always be “FastMA crosses under SlowMA”.

    The “previous crossing” can therefore never be a confirmation of the current crossing but is always the opposite.

    (A “Crosses Under” is always followed by a “Crosses Over” and this is always followed by a “Crosses Under”, and so on)

    1 user thanked author for this post.
    #198731

    Not tested:

    1 user thanked author for this post.
    #198734
    JS

    This system is based on two of the same crossings so for example the last crossing was a “LONG crossing” (crosses over) and when this LONG crossing takes place higher than the previous “LONG crossing” then the system goes LONG and vice versa for SHORT…

    1 user thanked author for this post.
    #198753

    Yes JS that is wright. I should have said: the positive crossing must be on a higher level than the previous positive crossing. Thank you.

    1 user thanked author for this post.
    avatar JS
    #199455

    Hello Roberto, Thanks for your work but your code is not working. The one JS built works.

    #199456

    Thanks a lot JS this code is working. But, there is a “but”. And that is that on every new day this systems acts on the very first crossing. By the start of a new day the system does not look at the previous crossing, which should be higher or lower. I have studied your code and I can understand a lot of it (I could not have figured it ou my self).

    Is it possible that this mistake has to do with:

    For i = 1 to BarIndex[1]  ?

    Does that start every day new? And can this be fixed?

    Thanks!

    #199458
    JS

    Hi @Vogeltje

    Nice that the code works…

    How do you use this system?

    Do you stop it every night or does it continue automatically?

    Do you (manually) close positions?

    Is the market you trade on a 24-hour market, or does it have a limited opening?

    #199460
    JS

    I think this will solve the problem…

    #199466

    Hi JS,

    I use this only in backtesting at the moment. I try different intraday-timeframes like 15 min, 30 min, 1 hour.

    I backtest over longer periods like 3 months.

    I test on futures like miniDAX (closes 22.00 – 08.00) or miniNasdaq (closes 23.00 -00.00).

    Thank you.

    Does the new system replace the one before? I guess so and will try.

    #199469
    JS

    Hi @Vogeltje

    Yes, the “new” system (V2) replaces the previous system…

    I have removed the lines that set the “CrossingPrice” to zero.
    I have made sure that there are always enough bars present for the calculation (PreLoadBars = 1000)

    I think this is going to solve the problem…

    #199485

    Yes JS I think tis is working…..  but the results are much worse  🙂 🙂  But that is not your mistake…..

    Few simple questions:

    • why is good to remove the lines that set previous cross to zero?
    • you write: FOR….. Break     in the tutorial I see   For… Else…  Break    I added Else but it makes no difference    ( 🙂 )
    • You end   “”Break ..  Endif… Next… Endif”        is there  a reason for this extra   Next.. Endif?

     

    #199494
    JS

    Hi @Vogeltje

    You just must assume that the results are always bad … 😉

    • The code is executed at the close of each bar, so after each bar the “CrossingPrice” and “PrevCrossingPrice” are set to zero.This is not desirable because when you compare them, one can still be at zero and then the comparison is always true.

    • You can use “else” when you want to set a variable to zero or one, for example:

    If ….then

    Variable = 1

    Else

    Variable = 0

    EndIf

    • You are looking for the previous crossing with “For i=1 to BarIndex[1]”, when the “If … then” is not true then you end up after the “EndIf” and that is “Next”

    When the “If… then” is true then you end up at “Break” and the “For … to” ended.

    Hopefully a little clear.

     

    #200043

    Thanks JS, I must think hard about this. For me this is not easy stuff….

    1 user thanked author for this post.
    avatar JS
Viewing 14 posts - 1 through 14 (of 14 total)

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