Trading system with EMA, SAR and Stochastic

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #48200 quote
    Henry
    Participant
    Average

    A request that was addressed to ProRealTime:

    Dear Sir or Madame,

    I opened the account via the prorealtime homepage with IG Markets and would kindly like to ask for writing a code for trading system as follows:

    Parameter
    – Currency pair: AUD/USD (or other major pairs)
    – 3 Min Candle Chart
    – EMA 200
    – Parabolic SAR (using the standard setting)
    – Stochastic Indicator (13 ; 8 ; 3) / horizontal lines in the indicator are located at 25 (instead of 20) on the bottom and 75 (instead of 80) on the top
    – Trading Hours 08:05 o’clock German time until 15:25 o’clock German time and 15:35 o’clock until 21:45 o’clock

    Long Order

    • The current candle stick is trading above the EMA 200.
    • Parabolic SAR is plotting below the current candle (green for uptrend).
    • Stochastic is confirming the above with crossing upward (preferably the lines have crossed below the 25 horizontal line already)

    If the above conditions are all fulfilled, then:

    • Buy 0,1 Lot (mini-Lot) with the open of the next candlestick.
    • Stop-Loss is placed 2 pips below the Parabolic SAR.
    • Target is 10 pips (might be changed, just do not know which is the best target at the moment but I assume that amending the target should be possible without difficulties).
    • The Stop-Loss is a trailing stop which should be plotted always two pips below the Parabolic SAR.
    • Position is closed when the price reaches the target or the stop loss.

     

    Short Order

    • The current candle stick is trading below the EMA 200.
    • Parabolic SAR is plotting above the current candle (red for downtrend).
    • Stochastic is confirming the above with crossing downward (preferably the lines have crossed above the 75 horizontal line already)

    If the above conditions are all fulfilled, then:

    • Sell 0,1 Lot (mini-Lot) with the open of the next candlestick.
    • Stop-Loss is placed 2 pips above the Parabolic SAR.
    • Target is 10 pips (might be changed, just do not know which is the best target at the moment but I assume that amending the target should be possible without difficulties).The Stop-Loss is a trailing stop which should be plotted always two pips above the Parabolic SAR.
    • Position is closed when the price reaches the target or the stop loss.

    Trust the above is understandable. If you have any questions please contact me.

    Thank you very much in advance and look forward to hearing from you.

     

    Suggestion for an anwser:

     

    ParabolicSAR=SAR[0.02,0.02,0.2]
    EMA200=ExponentialAverage[200](close)
    mystoch=Stochastic[13,8](close)
    
    tradingtime=(time >= 080500 and time <152500) or (time >=153500 and time < 214500)
    
    c1=close > EMA200
    c2=close > ParabolicSAR
    c3=mystoch crosses over 75
    
    if not longonmarket and tradingtime and c1 and c2 and c3 then
    buy 0.1 share at market
    sell at ParabolicSAR-2*pointsize stop
    set target pprofit 10
    endif
    
    if longonmarket then
    sell at ParabolicSAR-2*pointsize stop
    endif
    
    c4=close < EMA200
    c5=close < ParabolicSAR
    c6=mystoch crosses under 75
    
    if not shortonmarket and tradingtime and c4 and c5 and c6 then
    sellshort 0.1 share at market
    exitshort at ParabolicSAR+2*pointsize stop
    set target pprofit 10
    endif
    
    if shortonmarket then
    exitshort at ParabolicSAR+2*pointsize stop
    endif
    
    if not tradingtime then
    sell at market
    exitshort at market
    endif
    #63335 quote
    Meta Signals Pro
    Participant
    Veteran

    Bonjour,

    Ce système ne semble pas marcher chez moi sur les actions :

    > que faudrait-il changer (désolé mes connaissances de programmation sont réduites) !

    Merci d’avance !!

    Chris

    #63336 quote
    Leo
    Participant
    Veteran

    I think is missing the stochastic lines crossing.

    Cross over in the last 5 bars:

     

    StochD=Average[Pd](myStoch)
    Cx= myStoch crosses over StochD
    Cx1= highest[5](Cx)=1
    #63360 quote
    robertogozzi
    Moderator
    Master

    I think is missing the stochastic lines crossing. Cross over in the last 5 bars:

    Line 3 should read

    Cx1= summation[5](Cx)
    #63526 quote
    Meta Signals Pro
    Participant
    Veteran

    Hi Roberto,

    Thanks for your answer ; so what would be the full code to deal with stocks ?

    BTW, do you know how to set a timeframe for backtest ?

    Best,

    Chris

    #63539 quote
    robertogozzi
    Moderator
    Master

    Here is the full code:

    ParabolicSAR=SAR[0.02,0.02,0.2]
    EMA200=ExponentialAverage[200](close)
    mystoch=Stochastic[13,8](close)
     
    tradingtime=(time >= 080500 and time <152500) or (time >=153500 and time < 214500)
     
    c1=close > EMA200
    c2=close > ParabolicSAR
    c3=mystoch crosses over 75
    
    StochD=Average[Pd](myStoch)
    Cx = myStoch crosses over StochD
    Cx1= summation[5](Cx)
    Cy = myStoch crosses under StochD
    Cy1= summation[5](Cy)
    
    if not longonmarket and tradingtime and c1 and c2 and c3 and Cx1 then
       buy 0.1 share at market
       sell at ParabolicSAR-2*pointsize stop
       set target pprofit 10
    endif
     
    if longonmarket then
       sell at ParabolicSAR-2*pointsize stop
    endif
     
    c4=close < EMA200
    c5=close < ParabolicSAR
    c6=mystoch crosses under 75
     
    if not shortonmarket and tradingtime and c4 and c5 and c6 and Cy1 then
       sellshort 0.1 share at market
       exitshort at ParabolicSAR+2*pointsize stop
       set target pprofit 10
    endif
     
    if shortonmarket then
       exitshort at ParabolicSAR+2*pointsize stop
    endif
     
    if not tradingtime then
       sell at market
       exitshort at market
    endif

    When a backtest is launched it uses the current TF on the chart, just change it.

    Meta Signals Pro thanked this post
    #63550 quote
    Meta Signals Pro
    Participant
    Veteran

    Thanks Roberto for the code and your answer 😉 (I don’t get it; apprently the Trading Systems I tried keep taking M5 for the backtest even if I am on the daily time frame ..;

    I would be interested in your advice for the best automatic trading system you have used on stocks !!

    I am struggling to find one profitable ;

    Are you using this ATS ?

    Best,

    Chris

    #63555 quote
    robertogozzi
    Moderator
    Master

    Sorry, I don’t trade stocks!

    I use ATS only on demo accounts and just a few FX pairs + DAX.

    Meta Signals Pro thanked this post
    #63556 quote
    Meta Signals Pro
    Participant
    Veteran

    Roberto,

    Here is what it returns ; what do I need to do ? Thanks !

    Image1.png Image1.png
    #63558 quote
    robertogozzi
    Moderator
    Master

    Leo wrote that line of code assuming you know what to write within brackets, i.e. the number of periods for the Average to be used with Stochastic. Just replace PD with your desidered value. This line of code is with number 3:

    StochD=Average[3](myStoch)
    #63560 quote
    Meta Signals Pro
    Participant
    Veteran

    Hi Roberto,

    Still not working sorry; would you mind checking is in PRT yourself when you have 5 mn?

    Thanks ;

    Chris

    #63562 quote
    robertogozzi
    Moderator
    Master

    On which instrument and TF are you testing it?

    #63601 quote
    GraHal
    Participant
    Master

    Results attached  …

    1st image with Pd at 42 – eurusd over 1ok bars on spreadbet @ £1 per point (= mini CFD).

    2nd image with Pd at 16 – Dow / DJI then same as above.

    Looks promising!?

    Henry.jpg Henry.jpg Henry-2.jpg Henry-2.jpg
    #63667 quote
    Leo
    Participant
    Veteran

    Hi,

    There is an error in condition  c3 : it should be crossing value 25.

    Hi Grahal, what is the background when you take the value Pd so high? I have never seen that. Sound interesting.

    #63759 quote
    Leo
    Participant
    Veteran

    Hi GraHal,

    Thanks to your comment, it sparks an idea to me ,I posted in a new forum

    PSEUDOSTOCHASTIC TRADE

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

Trading system with EMA, SAR and Stochastic


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Henry @henry Participant
Summary

This topic contains 14 replies,
has 5 voices, and was last updated by Leo
8 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/04/2017
Status: Active
Attachments: 3 files
Logo Logo
Loading...