Using 3 ema for back testing not working

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #87219 quote
    Alec Imad
    Participant
    New

    I am needing a code to buy when 10 ema crosses over the 20 and 50 and sell when the 10 crosses under the 20 and 50.

    The issues im having is with this code:

    [Moderators edit – code removed as it was unreadable. It can now be found further down the thread.

    #87220 quote
    Vonasi
    Moderator
    Master

    Alec Imad – I’m not sure what has happened when you have tried to put code in your post but it has turned out unreadable. Please repost the code and I can then try to tidy everything up a little.

    #87221 quote
    GraHal
    Participant
    Master

    Alec Imad – I’m not sure what has happened when you have tried to put code in your post but it has turned out unreadable.

    It goes like that when you have entered the code correctly using the Enter PRT Code button and then you edit the code on the normal page and then you post the whole message (changes need to be made by going back into the Enter PRT Code box).

    Or another way you get all the html commands (?) is if you copy code from another message (which has been correctly entered using the Enter PRT Code button) and then you paste it straight onto a normal message page!

    #87235 quote
    robertogozzi
    Moderator
    Master

    Please update your country flag. Thank you.

    #87248 quote
    Vonasi
    Moderator
    Master

    Alec Imad – Welcome to the forums.

    Please repost your code here so that someone can assist you.

    There are some basic rules that you will need to follow when posting in the forums. You have broken most of them already! 🙂

    • Ensure your country flag is updated.
    • Make sure you post in the correct forum. ProOrder for strategies, Probuilder for indicators etc.
    • Do not double post as it leads to wasted time and confusion.

     

    I have deleted your identical question in the ProBuilder forum as it was a double post in the wrong forum and the code was also unreadable in that one!

    I’m not sure what you are exactly doing to make the code unreadable but if you want to put code in your posts then just simply click the ‘add PRT Code button’ then type or cut and paste your code into the box and then click ‘add’.

    #87250 quote
    Alec Imad
    Participant
    New
      // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[10](close)
    indicator2 = ExponentialAverage[20](close)
    c1 = (indicator1 CROSSES OVER indicator2 and  )
      indicator3 = ExponentialAverage[10](close)
    indicator4 = ExponentialAverage[50](close)
    c2 = (indicator3 CROSSES OVER indicator4)
    
    IF c1 and c2 THEN
    BUY 10 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator5 = ExponentialAverage[10](close)
    indicator6 = ExponentialAverage[20](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    indicator7 = ExponentialAverage[10](close)
    indicator8 = ExponentialAverage[50](close)
    c4 = (indicator7 CROSSES UNDER indicator8)
    
    IF c3 AND c4 THEN
    SELL AT MARKET
    ENDIF

    Thank you and sorry for breaking the rules.

     

    I have tried looking where to add my country flag but can not find it. I am from australia.

    #87254 quote
    Vonasi
    Moderator
    Master

    Hover on your profile picture in the top right of the screen and then click on ‘Profile and Posts’. Then ‘Edit Profile’ and you can select your location flag there.

    #87255 quote
    Vonasi
    Moderator
    Master

    Your problem is because both conditions have to be found on the same bar which is highly unlikely to happen. You need to look for one condition and then set a flag to say that that condition has happened and then only enter a trade if the second condition happens while the first ones flag is still valid. Same for the exit.

    Alec Imad thanked this post
    #87257 quote
    Alec Imad
    Participant
    New

    Thank you for your reply, I have updated my location.

     

    Im sorry i am not a developer at all and have wrote this code through researching on the internet and using the software. How would i write that exactly

    #87258 quote
    GraHal
    Participant
    Master

    You could do below and get attached on DJI @5 Min TF, spread = 4 and Lot size = 1

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[10](close)
    indicator2 = ExponentialAverage[20](close)
    c1 = (indicator1 > indicator2)
    indicator3 = ExponentialAverage[10](close)
    indicator4 = ExponentialAverage[50](close)
    c2 = (indicator3 CROSSES OVER indicator4)
     
    IF c1 and c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
     
    // Conditions to exit long positions
    indicator5 = ExponentialAverage[10](close)
    indicator6 = ExponentialAverage[20](close)
    c3 = (indicator5 < indicator6)
    indicator7 = ExponentialAverage[10](close)
    indicator8 = ExponentialAverage[50](close)
    c4 = (indicator7 CROSSES UNDER indicator8)
     
    IF c3 AND c4 THEN
    SELL AT MARKET
    ENDIF
    
    Alec Imad and Vonasi thanked this post
    Alec.jpg Alec.jpg Alec-2.jpg Alec-2.jpg
    #87267 quote
    Alec Imad
    Participant
    New

    Thank you grahal im running some test now and will report back thank you

    #87274 quote
    Vonasi
    Moderator
    Master

    Thanks GraHal that is a far simpler solution than mine. I do like to complicate things whenever I possibly can so it is always nice to be reminded that there are simpler ways sometimes!

    GraHal thanked this post
    #87285 quote
    GraHal
    Participant
    Master

    Alec Imad … on the basis that Shorts don’t trigger / play out same as Longs here’s a both ways strategy.

    I will Forward Test (on Demo) the Long only and Long & Short version below and report back on here after 1 month or so.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[10](close)
    indicator2 = ExponentialAverage[20](close)
    c1 = (indicator1 > indicator2)
    indicator3 = ExponentialAverage[10](close)
    indicator4 = ExponentialAverage[50](close)
    c2 = (indicator3 CROSSES OVER indicator4)
     
    IF not shortonmarket and c1 and c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
     
    // Conditions to exit long positions
    indicator5 = ExponentialAverage[10](close)
    indicator6 = ExponentialAverage[20](close)
    c3 = (indicator5 < indicator6)
    indicator7 = ExponentialAverage[10](close)
    indicator8 = ExponentialAverage[50](close)
    c4 = (indicator7 CROSSES UNDER indicator8)
     
    IF c3 AND c4 THEN
    SELL AT MARKET
    ENDIF
    // Conditions to enter short positions
    indicator1 = ExponentialAverage[30](close)//50
    indicator2 = ExponentialAverage[85](close)//20
    c1 = (indicator1 < indicator2)
    indicator3 = ExponentialAverage[30](close)//50
    indicator4 = ExponentialAverage[80](close)//75
    c2 = (indicator3 CROSSES UNDER indicator4)
     
    IF not longonmarket and c1 and c2 THEN
    SellShort 1 CONTRACT AT MARKET
    ENDIF
     
    // Conditions to exit short positions
    indicator5 = ExponentialAverage[30](close)//50
    indicator6 = ExponentialAverage[85](close)//20
    c3 = (indicator5 > indicator6)
    indicator7 = ExponentialAverage[30](close)//50
    indicator8 = ExponentialAverage[80](close)//75
    c4 = (indicator7 CROSSES OVER indicator8)
     
    IF c3 AND c4 THEN
    ExitShort AT MARKET
    ENDIF
    
    Alec-3.jpg Alec-3.jpg Alec-4.jpg Alec-4.jpg
    #87288 quote
    GraHal
    Participant
    Master

    If anybody is interested, I did 5 versions … results attached.

    Alec-5.jpg Alec-5.jpg
    #87291 quote
    Vonasi
    Moderator
    Master

    You will notice that all the strategies suddenly started making money around February 2018 when the bull market came to an end and we entered a volatile mean reversing market. A simple strategy of EMA’s crossing can be easily be tuned (curve fitted) to this sort of market. Finding the correct EMA values for tomorrow and onward is the hard bit and also knowing when to turn it off as a bull or bear trend has started again is also difficult as you don’t know it is a trend until your mean reversal strategy has already lost you a lot of money usually!

    Sorry voice of doom again.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Using 3 ema for back testing not working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Alec Imad @alec_imad Participant
Summary

This topic contains 16 replies,
has 4 voices, and was last updated by Vonasi
7 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/16/2018
Status: Active
Attachments: 5 files
Logo Logo
Loading...