MA cross, buy trigger

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #5053 quote
    Real Pro
    Participant
    Average

    Salut,

    Say I have an MA plotted on the price chart, and the price is currently sitting under the MA.

    I want to buy when the MA is touched, but I don’t want to buy at next open… I want to buy at the price of the MA on that same bar.  Is this possible to code please?

    Many thanks.

    #5060 quote
    Adolfo
    Participant
    Senior

    Hi, not exactly because the system always wait until the current bar is finished to open a new position.

    But you can still open a position in the next candle at the same price where the last bar was touched with a LIMIT order.

    REM Moving Average
    mm = Average[x](close) // x = periods of ma 
    
    // buy = your conditions to go in
    
    IF NOT LongOnMarket AND buy = 1 THEN
    BUY 1 CONTRACT AT mm[1] LIMIT
    ENDIF

    Hope it helps you.

    #5071 quote
    Nicolas
    Keymaster
    Master

    Hello, if the price is “currently sitting under the MA”, the pending order would be a STOP one and not a LIMIT one, or I miss something here.. sorry got a cold.. 😐

    Thank you very much Adolfo for helping people around here!!!

    #5078 quote
    Adolfo
    Participant
    Senior

    I’m glad if can help even one person.
    Nicolas, I mean, in my example we are buying when the price comes to touch MA after a long movement, we go with the trend after a pullback.

     

    Greetings!

    #5079 quote
    Real Pro
    Participant
    Average

    Adolfo, PRT finds an error on this line.  Unfortunately I’m very new to coding this platform…

    IF NOT LongOnMarket AND BUY=1  THEN

    Thank you.

    PS price is touches on a price above the current price, so yes Nicolas that’s right, probably a STOP order.

    #5080 quote
    Adolfo
    Participant
    Senior

    Maybe you are not using “BUY=1”. So I should be wrong.

    You want to BUY when the price CROSSES UNDER MA? When the price is rising and touch MA you want to buy, right?

    Can you give more details please?

    #5083 quote
    Real Pro
    Participant
    Average

    I want to buy when the price rises to touch the MA (which lies above it), with an entry price == MA on the same day.

    Thank you. 🙂

    #5084 quote
    Adolfo
    Participant
    Senior

    Then should be something like this, but it will always buy when it occours.

    REM Moving Average
    mm = Average[x](close) // x = define MA periods you want to use
    
    // Your conditions to buy
    // You are not in, and price was under MA
    IF NOT LongOnMarket AND High<mm THEN
    BUY 1 CONTRACT AT mm STOP
    ENDIF

    Let me know if works for you!

    #5088 quote
    Real Pro
    Participant
    Average

    Thank you, it appears to work fine.  I just have to go through the trade list and check.

    🙂

    #13937 quote
    traderollie
    Participant
    New

    This is something similar to what I need, Where do I put this in my current code?

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

MA cross, buy trigger


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Real Pro @real-pro Participant
Summary

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

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