buy /sell when the price crosses over/under a value and equals a different value

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #240452 quote
    J.gymea
    Participant
    New

    Hi and thank you guys!

    I want to code this but dont know how:

    for example

    BUY 1 contract when the price crosses over 100 then reaches 120 ( so basically the price has to cross over 1oo and reaches 120 to buy a contract at 120 )

    CLOSE THE TRADE when the price crosses down 140 then reaches 120 ( price has to cross under 140 and reaches 120 to sell at 120)

     

    Appreciate your help

    Thank you

    #240453 quote
    JS
    Participant
    Senior

    Hi,

    Try this one:

    DefParam CumulateOrders=False
    
    Once LongLevel100=0
    Once ShortLevel140=0
    
    If Close Crosses Over 100 then
    LongLevel100=1
    EndIf
    
    If Close Crosses Over 120 and LongLevel100=1 then
    Buy 1 contract at Market
    LongLevel100=0
    EndIf
    
    If Close Crosses Under 140 then
    ShortLevel140=1
    EndIf
    
    If Close Crosses Under 120 and ShortLevel140=1 then
    SellShort 1 contract at Market
    ShortLevel140=0
    EndIf
    
    Iván González, J.gymea and Watanabix thanked this post
    #240511 quote
    J.gymea
    Participant
    New

    Thank you JS,

    It worked but I need the trade to be closed when the price crosses under 140 to 120 and not to sell ( now its buying 1 contract when the price crosses over 100 reaching 120, closing the buying contract and selling 1 contract when the price crosses under 140 reaching 120). what I need to change in this code please?

     

    Thank you so much

    JS thanked this post
    #240512 quote
    JS
    Participant
    Senior

    Hi,

    Change line 20 to “Sell at Market”

    J.gymea thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

buy /sell when the price crosses over/under a value and equals a different value


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
J.gymea @j-gymea Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by JS
1 year, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/18/2024
Status: Active
Attachments: No files
Logo Logo
Loading...