Please can someone help me code this Strategy

Forums ProRealTime English forum ProOrder support Please can someone help me code this Strategy

Viewing 10 posts - 1 through 10 (of 10 total)
  • #14579

    Can someone please help me to code this.

    Condition to Buy or Sell. Happening in sequence

    1. ADX to drop to value 13.5
    2. ADX to recover to above Value 20
    3. ADXR to go above Value 20 at this time ADX should be still above 20
    4. When 1 ,2,3 is fulfilled. BUY if EMA 4 >EMA 9 >EMA 20.    SELL if EMA 4 < EMA 9 < EMA 20

     

    Exit

    Exit Long when EMA 4 cross below EMA 9

    Exit Short when EMA 4 Cross above EMA 9

     

    Please it will be greatly appreciated. I know nothing about programing

     

    #14595

    This code should do, if I understood what you need:

    Just try it.

    I hope someone else puts an eye on it just to make sure it is correct, I did not start coding strategies much time ago.

     

    #14596

    It was automatically so badly indented, I hope this is better:

     

    2 users thanked author for this post.
    #14601

    Thanks a lot Roberto for helping others members. You deserve to be awarded for this 😉

    Code is not indended automatically I’m sorry. This is something I need to work to… All codes you see on website which is indended has been made manually..


    @tom
    Please update your country in your profile. Thanks.

    #14621

    Thanks Roberto

    Can’t wait to try it out later to night. Many thanks for even trying.

     

    #14855

    Hi Mr Roberto

    The Algo works fine when i Back test it. But i am not sure why when I run it it for the whole of today. It does not seems to follow the same logic.

    As you can see it made a few order when ADX are below 20.

    It should not have since ADX had not went down to 13.5 and was never above 20 as well.

    Did i mess up the code while i was editing ?

     

    DEFPARAM CumulateOrders = False //No more than 1 trade allowed

    ONCE Adx13 = 0 //Make sure it has an initial value
    ONCE Adx20 = 0 //Make sure it has an initial value

    ADXval = ADX[21] //Current ADX value

    Ema4 = ExponentialAverage[9] //Current value for all EMA’s
    Ema9 = ExponentialAverage[13]
    Ema8 = ExponentialAverage[40]
    Ema20 = ExponentialAverage[20]

    IF ONMARKET THEN //If a trade is entered, then reset flags to false
    Adx13 = 0 // to restart the whole sequence for next trades
    Adx20 = 0
    IF LONGONMARKET THEN
    IF Ema4 CROSSES UNDER Ema8 THEN // Exit LONG trades if needed
    SELL AT MARKET
    ENDIF
    ENDIF
    IF SHORTONMARKET THEN
    IF Ema4 CROSSES OVER Ema8 THEN // Exit SHORT trades if needed
    EXITSHORT AT MARKET
    ENDIF
    ENDIF
    ELSE //otherwise start the sequence…
    IF Adx13 = 0 THEN //If 13.5 not reached yet, then
    Adx20 = 0 // reset this flag to 0, just in case and…
    Adx13 = (ADXval <= 13.5) // set this one to its current value
    ELSE
    Adx20 = (ADXval > 20) //If 13.5 already reached, set this flag to its
    ENDIF // current value (false or true, whichever the case)
    IF Adx20 THEN //If this flag was set, but ADX drops below 20, then
    IF ADXval < 20 THEN // it must be reset to false
    Adx20 = 0
    ENDIF
    ENDIF
    ENDIF

    // Conditions to enter a LONG trade
    c1 = (Ema4 > Ema9) AND (Ema9 > Ema20)
    IF c1 AND Adx20 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF

    // Conditions to enter a SHORT trade
    c2 = (ema4 < Ema9) AND (Ema9 < Ema20)
    IF c2 AND Adx20 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF

    // Stop e target
    SET TARGET PPROFIT 5
    SET STOP $LOSS 4

    #14897

    Actually ProOrder enters trades which shouldn’t be entered, but the Algo does seem correct.

    I tried to limit trades to Oct. 12th 10-18, just to test fewer trades and I found that ALL trades should not have entered!

    I wonder if the problem is in the instructions ONCE and/or ONMARKET, but I am pretty sure the logic is fine.

    Maybe Nicolas could help us better.

     

    #14949

    I paste the code, more readable, but without significant changes that make it behave correctly:

    I modified lines 42 and 49 so that it only enters trades when ADX > 20 (and should have previously gone at or below 13.5), no matter the ema’s. It appears that Adx20 contains the value 1 (true) as if line 31 had been executed, which shouldn’t have been.

    I even wonder if too many IF…THEN…ELSE’s may confuse ProBackTest/ProOrder.

    I also commented out some useless lines (33-37).

    Any further help is highly appreciated.

    #16402

    After thinking it over in my spare time I could write the correct code.

    Please try it and check if trades are entered/exited correctly (of course you will have to adjust values for profitable trades):

    1 user thanked author for this post.
    avatar ALE
    #16403

    Sorry, but indentation still was not appealing, so I used Notepad to amend it:

     

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

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