how to:entry two bars after setup bar and moving SL after met target R1/2 etc

Forums ProRealTime English forum ProOrder support how to:entry two bars after setup bar and moving SL after met target R1/2 etc

  • This topic has 3 replies, 2 voices, and was last updated 8 years ago by avatarVeen.
Viewing 4 posts - 1 through 4 (of 4 total)
  • #16920

    Hello,

    since a few weeks i’ve been trying to code one of my strategies. I find this forum very helpfull, but am kind of stuck right now.
    I hope someone can help me out a bit.

    For trading I use PRT10.2 through IG.
    When trading manual and enter a trade, I open 3, 4 or 5 lots and use R1, R2, R3 as target and after that I trail the position left using a moving average or bar by bar.
    I understand that with auto trading through IG (I found out eventually in this forum) it is not posssible to close positions partially.
    Because of that ‘feature’ I was thinking to enter the same strategy 3, 4 or 5 times but with different targets (and moving the SL, but more about that later)

    For identifying the setup bar I use a couple of selfmade indicators. In the example below Indicator 1 and 11.
    After the setup bar is closed, my entry (Buy STOP) is 0.5 ticks above the high of the setup bar. My Stoploss is placed 2 ticks below the low of the setup bar.
    (see code below, till now everything is working fine)
    But sometimes the setup bar is not taken out by the first following bar, but the second bar. For my strategy that is still valid. I’ve tried to use differtent examples I found in this forum and the manual,
    but i am completly lost on how to code that my stoploss has to be beneath the low of the setup bar and not the first bar after the setup bar.
    I attached an image (R1.jpg) with additional text tot clarify things.
    Question 1: how can i adjust my code (see below) in a way that ALSO the second bar is a valid entry when taking out the setup bar and still use the same stoploss beneath
    the low of the setupbar? The problem I face is referring to the low of the setup bar.

    Working code with only using the first bar after the setup bar as a trigger:

    indicator1 = CALL “myindicator1”
    indicator11 = CALL “myindicator11”

    c1 = (indicator1=1)
    c11 = (indicator11 <= 2 or indicator11[1] <= 2)
    Buyprice=high+0.5
    R1 = (buyprice-low) +2

    IF C1 and C11 THEN
    BUY 1 shares AT buyprice STOP
    SET STOP PLOSS R1
    set target pprofit R1
    ENDIF

    And now the second part of my post.
    As mentioned before I want to enter the trade with multiple positions. For the second entry I initaly like the use the same stoploss. But after reaching R1 I want to move the stoploss to:
    buyprice – (0.4*(buyprice-initial stoploss)).
    Question 2: The problem with coding this is I can refer to the buyprice, I can refer to R1 but how can I refer to the low of the setup bar after reaching R1? (the question is somewhat the same as question 1)
    See also the attached image (R2.jpg).
    I think the key to this is to ‘store’ the values of the setup bar (High, Low)(?).

    Many, many thanks in advance!

    #16940

    attached files

    #16954

    Firstly, about your question 1, I believe you wait for a bar close to validate your setup bar and then initiate your pending stop order? So, you may calculate the stoploss with the wrong bar and you should offset this calculation with 1 bar in the past:

    Question 2 : you are right, you should store the high/low of the setup bar. Why don’t you code it directly into your indicator and then call this values as new variables in your strategy instead? It should solve also your first question 🙂

     

    #16971

    Hi Nicolas,
    thanks for taking time considering my questions.
    You answer definitely gives me some new clues. I don’t know how yet, but am confident I will make it from here. At least the part about using the high and low of the setup bar,
    but maybe you (or someone else:-)) can give me a hint on which code to use to make sure that also the second following bar is valid for the pending stop order (so only the first and second bar after setupbar).
    Regarding your remarks about referring to the former bar ([1]), this is exactly how Ii coded it the first time. But somehow it then used the low/high of the bar prior the setup bar.
    Maybe it’s something I resolved when building the indicator, I really don’t know.
    (see attachement):The attached image shows the setup indicator -1 and the entry takes place when in the following bar when taking out the low of the setupbar.
    Well, it’s working as intended so I don’t bother at the moment:-)

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

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