first hit of a moving average

Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #75423 quote
    Vonasi
    Moderator
    Master

    If by ‘next bar’ you really mean the current bar that is being checked to see whether the order should be sent to market then the problem is that you are using DHIGH which is the daily high when you should be using HIGH which is the current bars high.

    I can highly recommend reading everything in the documentation here to help with understanding PRT coding more fully:

    https://www.prorealcode.com/prorealtime-documentation/

    #75427 quote
    Bullets
    Participant
    Junior

    Thank you Im currently reading those documents.

    What I mean is. After the gap criteria has been meet. If price than crosses under the 50ma for the first time (a low will do). Than the next bar’s high must be higher than the 50ma. Than on the open of the following bar take the trade. So Im looking for confirmation the 50ma will hold as support. What Im trying to avoid is if prices just fall straight through the 50ma I dont want to take that trade.

    Let me know if that clears it up? Cheers

    #75434 quote
    Vonasi
    Moderator
    Master

    So you want:

    • Fast MA’s crosses over Slow MA
    • Gap between MA’s is big enough.
    • Price touches fast MA
    • Next candles high is higher than fast MA
    • Open trade at opening of next candle.
    #75437 quote
    Bullets
    Participant
    Junior

    Yes correct.

    #75441 quote
    Vonasi
    Moderator
    Master
    starttime = 000000
    startday = 1
    gapneeded = 20 * pipsize
     
    ma20 = average[20](close)
    ma50 = average[50](close)
    ma200 = average[200](close)
    magap = ma20 - ma200
     
    if (opentime = starttime and opendayofweek = startday) or onmarket then
    crossflag = 0
    gapflag = 0
    endif
     
    if ma20 crosses over ma200 then
    crossflag = 1
    endif
     
    if crossflag and magap > gapneeded then
    gapflag = 1
    endif
     
    if ma20 crosses under ma200 then
    crossflag = 0
    gapflag = 0
    endif
     
    if not onmarket and crossflag[1] and gapflag[1] and low[1] < ma50 and high > ma50 then
    buy 1 contract at market
    endif
     
    SET STOP pLOSS 25
    SET TARGET pPROFIT 25
    
    #75449 quote
    Bullets
    Participant
    Junior

    thanks mate that works well !

    #75619 quote
    GraHal
    Participant
    Master

    I’ve got code below on Fwd Test on Demo, attached is equity curve for an open trade which was at > 55 gain and yet my Set TP = 30 didn’t trigger.

    Anybody any ideas why TP not triggered (or do I need more coffee 🙂 )?

    //-------------------------------------------------------------------------
    // Main code : MA Hit DAX 5M v1.0
    //-------------------------------------------------------------------------
    //https://www.prorealcode.com/topic/first-hit-of-a-moving-average/page/2/
    DEFPARAM CUMULATEORDERS = False
    
    starttime = 000000
    startday = 1
    gapneeded = 2 * pipsize
     
    ma20 = average[20](close)
    ma50 = average[50](close)
    ma200 = average[200](close)
    magap = ma20 - ma200
     
    if (opentime = starttime and opendayofweek = startday) or onmarket then
    crossflag = 0
    gapflag = 0
    endif
     
    if ma20 crosses over ma200 then
    crossflag = 1
    endif
     
    if crossflag and magap > gapneeded then
    gapflag = 1
    endif
     
    if ma20 crosses under ma200 then
    crossflag = 0
    gapflag = 0
    endif
     
    if not onmarket and crossflag[1] and gapflag[1] and low[1] < ma50 and high > ma50 then
    buy 1 contract at market
    endif
     
    SET STOP pLOSS 25
    SET TARGET pPROFIT 30
    
    MA-Hit.jpg MA-Hit.jpg
    #75626 quote
    Vonasi
    Moderator
    Master

    Did the order actually ever go to market or was it rejected for some reason? Check your orders list and on the chart to see if there is an order connected to the trade?

    #75627 quote
    GraHal
    Participant
    Master

    Yes the equity curve above is from clicking on Performance in the Auto-Trading window. Its is still trading see attached.

    No cancelled or rejected in the Orders List for that System

    MA-Hit-2.jpg MA-Hit-2.jpg
    #75629 quote
    GraHal
    Participant
    Master

    Typical, I did a Technical Report, pressed send and the Platform has frozen now!

    #75633 quote
    GraHal
    Participant
    Master

    Don’t know if Technical Report went before the freeze up or not and of course there is no acknowledgment sent out!

    I had to use Task Manager to close Platform!

    Anyway the SAME trade has gone above gain of 30 AGAIN (I’m liking this strategy! 🙂 ) but the Set TP 30 has not triggered for the second time … well weird ???

    MA-Hit-3.jpg MA-Hit-3.jpg
    #75635 quote
    GraHal
    Participant
    Master

    2nd Technical Report sent! 🙁


    @Vonasi
    … attached is the Order you were asking about.

    MA-Hit-4.jpg MA-Hit-4.jpg
    #75638 quote
    Vonasi
    Moderator
    Master

    That last image is the BUY order at 12506.4. There should also be an order to SELL at 12536.4

    #75641 quote
    Bullets
    Participant
    Junior

    FYI – depending on where you live (I live in Australia), don’t set the start time @ 000000

    I had this system on real trading and it took the first candle at the open which was a wide range bar with a very wide spread.

    In fact, I couldn’t even see the price trade at the level I was stopped out at the same time I entered? very strange.

    In any case I changed the start time to 100000 to avoid the opening mess

    #75642 quote
    GraHal
    Participant
    Master

    Ahaha … gotcha!

    There are two pending orders, one for the Stop and one for the Limit. but the Limit of 30 has been met at least twice but not triggered a close / exit.

    MA-Hit-5.jpg MA-Hit-5.jpg
Viewing 15 posts - 16 through 30 (of 32 total)
  • You must be logged in to reply to this topic.

first hit of a moving average


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Bullets @bullets Participant
Summary

This topic contains 31 replies,
has 3 voices, and was last updated by GraHal
7 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/03/2018
Status: Active
Attachments: 9 files
Logo Logo
Loading...