Exponential moving average code required

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4988 quote
    cosmicsurfer
    Participant
    New

    Hi, im new to PRT, i need some code just a simple exponential moving average say say a EMA5 and a EMA 27 , buy when the long cross,s over the short and sell when the short cross,s over the long and visa versa for shorting the trade, preferably when the instrument is trending strongly. A MACD may be included or a Stocastic.

    any takers??

    Cosmic surfer

    #5011 quote
    Nicolas
    Keymaster
    Master

    Hello, what you are requesting is very easy to do with the assisted creation mode. Have you tried it?

    #5048 quote
    cosmicsurfer
    Participant
    New

    Hi Nicolas, i dont fully understand the indicator language when it comes to configuring macd and moving averages…I have had a go writing my own code i need a hand fine tuning it……If you could point me in the right direction with some code that would be great.

    cheers

    Jay

    #5050 quote
    cosmicsurfer
    Participant
    New

    Ok Nicolas i,ve just written some code using 2 Exponential moving averages (3/16) but the back test confirm what i am trying to eliminate when the instrument i am trading goes sideways it all goes to shit…. how can i eliminate sideways trading and just capture the majors up and down trends? I have attached a backtest. This is the code

    cheers

    Jay

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = ExponentialAverage[16](close)
    indicator2 = ExponentialAverage[3](close)
    c1 = (indicator1 CROSSES UNDER indicator2)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = ExponentialAverage[16](close)
    indicator4 = ExponentialAverage[3](close)
    c2 = (indicator3 CROSSES OVER indicator4)
    
    IF c2 THEN
    SELL  AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator5 = ExponentialAverage[16](close)
    indicator6 = ExponentialAverage[3](close)
    c3 = (indicator5 CROSSES OVER indicator6)
    
    IF c3 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator7 = ExponentialAverage[16](close)
    indicator8 = ExponentialAverage[16](close)
    c4 = (indicator7 CROSSES UNDER indicator8)
    
    IF c4 THEN
    EXITSHORT  AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP %TRAILING 5
    #5070 quote
    Nicolas
    Keymaster
    Master

    Hello cosmic, first of all I see something wrong at lines 32 and 33, you are trying to test a crossover between the 2 same moving average, which will never happen.

    About trading sideways market …. well you’ll never know when it gonna happens and when you see you are in a narrowed price oscillation, you are already in it, so it’s too late 🙂 In your example, you got then 2 options : stay in position or try to filter a lot with wide period moving average (100, 200 …) to define bulls or bears territories..

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

Exponential moving average code required


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Nicolas
9 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/07/2016
Status: Active
Attachments: No files
Logo Logo
Loading...