How can this be an entry?

Forums ProRealTime English forum ProOrder support How can this be an entry?

Viewing 15 posts - 1 through 15 (of 21 total)
  • #183713

    Your help please folks…

    The most simple of code is producing a strange result. The cross of the blue SMA 8 and green SMA 20 is the trigger for crossflag to equal 1, and yet when I graph crossflag it says it’s zero.

    The entry itself is correct by these simple rules, but it becomes a problem when I add more complicated variables to derive “crossflag”. I can’t trust my system until crossflag becomes 1, -1 or zero when it ought to.

    How can this code actually enter when crossflag is graphing at zero? I just can’t understand! And is there a different way of presenting this logic to make crossflag graph at 1 in the bar I’ve highlighted in the screengrab?

    Thanks in advance for your help.

    #183717

    Actually where your mouse is sitting no crossover occurred, as Sma8 is below Sma20, while on the right side of your chart there’s been a crossover, which is correctly reported.

     

     

    #183720

    But SMA8 is lower than SMA20 to the left of the mouse, and then it is higher one bar to the right of the mouse. How could this happen without there being a crossover?

    #183724

    Yes, right.

    I need the code to figure out what’s the cause.

     

    #183739

    Oh sorry, I forgot to include it! And now I can’t see the “include code” button, so here it is below in plain text.

     

    DEFPARAM CumulateOrders = False

    Longcross= Average[8](close) > Average[20](close)

    Shortcross= Average[8](close) < Average[20](close)

    if longcross and not longcross[1] then
    crossflag=1
    endif

    if not onmarket and crossflag=1 then
    sl=abs(close-lowest[3](low))+5
    tp=sl * VL
    Set target profit tp
    Set stop loss sl
    BUY 1 PERPOINT AT market
    crossflag=0
    endif

    if shortcross and not shortcross[1] then
    crossflag=-1
    endif

    if not onmarket and crossflag=-1 then
    sl= abs(close-highest[3](high))+5
    tp=sl * VL
    Set target profit tp
    Set stop loss sl
    Sellshort 1 PERPOINT AT market
    crossflag=0
    endif

    graph crossflag

    #183740

    Hi Mike – allow me to jump in. Assuming that what you showed is the full code :

     

    Since this is the only time you set crossflag to 1, the culprit has to be the combined condition which won’t become true.
    Besides that, for me it would look odd if two subsequent bars would cross (any signal). Thus there it has to go wrong ?

    Additionally, this looks a bit odd as well :

    First off, this suggests that you want to know crossflag at the next call (bar) of your code. Do notice that this would require a

    somewhere at the start of your code.

    Also, personally I would have the Set Stop Loss (and I think Set Target Profit as well) after the Sellshort. It may be fine, but if I would be the PRT code parser ;-), I would set those only at the next call of the code and then it would not even happen because by that time OnMarket will be True.
    Possibly it is fine anyway, but I would not depend on that (the code executes from top to bottom and how to set a SL if there is no position yet).

    Maybe Roberto has better ideas for you ?

    1 user thanked author for this post.
    #183741

    Thanks for the suggestion, Peter. I haven’t quite managed to work out how to use ONCE statements effectively, but I’ll have another look in the manual to see how I could apply it here. The SL code has been fine in previous systems, so I think I’ll just leave that one.

    What I’d really like to do is have the flag reset to zero on the flip of the PSAR, and then have the cross creating 1 or -1. Or alternatively have each PSAR flip indicate that it’s going to be a long cross or a short cross. I attempted it with this code but it didn’t work:

     

     

    #183744

    or

     

    1 user thanked author for this post.
    #183748
    JS

    When using only Longcross and Shortcross there is no problem…

    (SL and TP omitted for a better view)

    #183753
    JS

    If you want to use Crossflag then remove from your code:
    “not onmarket” (because your always on market)
    “crossflag=0”

    #183755

    Thanks for the suggestions. If I remove not onmarket, when I have a live trade, won’t it enter in a counter direction when these signals are met?

    #183756

    I haven’t quite managed to work out how to use ONCE statements effectively

     

    Easy ! (and the most useful)

    #183757

    DEFPARAM CumulateOrders = False Averagecrosslong= Average[8](close) CROSSES OVER Average[20](close) Averagecrossshort= Average[8](close) CROSSES under Average[20](close) if SAR[0.02,0.02,0.2] > SAR[0.02,0.02,0.2][1] then longsar=1 shortsar=0 endif if SAR[0.02,0.02,0.2] < SAR[0.02,0.02,0.2] then shortsar=1 longsar=0 endif crossflag=0 if longsar=1 and averagecrosslong  then crossflag=1 endif if not onmarket and crossflag=1 then sl=abs(close-lowest[3](low))+5 tp=sl * VL Set target profit tp Set stop loss sl BUY 1 PERPOINT AT market longsar=0 endif if shortsar=1 and averagecrossshort  then crossflag=-1 endif if not onmarket and crossflag=-1 then sl= abs(close-highest[3](high))+5 tp=sl * VL Set target profit tp Set stop loss sl Sellshort 1 PERPOINT AT market crossflag=0 shortsar=0 endif graph crossflag

    That code was okay for only longs, but it didn’t reset properly when I added in shorts. But I think I’ve solved it with this amended version of your code. I added “crossflag=0” at the very top and removed any instances of “crossflag=0” from the rest of the code.

     

    #183758
    JS

    No, it will open only in the direction of “crossflag”
    Add Crossflag = 0 at the top of your code and everything works fine 🙂

    1 user thanked author for this post.
    #183760

    once is to initialise the variable once on the first reading of algo

Viewing 15 posts - 1 through 15 (of 21 total)

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