Order placing in code

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #138622 quote
    Slowlyslowly
    Participant
    Average

    Hi

     

    Once you conditions have been met is it possible to place an order to trigger at a predetermined point NOT at market.

     

    i.e ALL the conditions are met but your order would be X pips higher than the current price at your trigger point Or when c1 and C2 and c3 and c4 are met. So then effectively placing an order etc ?

    #138640 quote
    robertogozzi
    Moderator
    Master

    Yes, you can use pending orders. Use STOP pending orders when the entry price il worse than current price, LIMIT  pending orders when it’s better (higher if yiu sell or lower if you buy):

    // Long  trades
    BUY 1 CONTRACT AT MyEntryPrice STOP   //current price is lower
    BUY 1 CONTRACT AT MyEntryPrice LIMIT  //current price is higher
    // Short trades
    SELLSHORT 1 CONTRACT AT MyEntryPrice STOP   //current price is higher
    SELLSHORT 1 CONTRACT AT MyEntryPrice LIMIT  //current price is lower

    Be warned that pending orders expire after one bar, so you need to place then again next bar if still needed.

    Set TP & SL as usual.

    #138647 quote
    Slowlyslowly
    Participant
    Average

    Thanks Roberto ,

     

    So if i envisaged myentryprice may not be hit for 5 or more bars after initial conditions were me how would be best to cope with that ?

    #138650 quote
    robertogozzi
    Moderator
    Master

    If your conditions are met keep placing them again and again, bar after bar, until those conditions are no more met (or  orders are triggered and you do not want to enter again until NEW conditions are met).

    #138651 quote
    Slowlyslowly
    Participant
    Average

    Once the conditions are met for placing an order at myentrypoint – i want the order to stay current until the entry point is achieved. The initial conditions to trigger myentrypoint will not be met going forward from the point of order as these are historical conditions to trigger my entry point.

     

    When you say keep placing the order bar after bar how is this coded to express the order is valid until achieved ? Regardless of the initial conditions to initially achieve the first placement of myentrypoint.

    #138652 quote
    robertogozzi
    Moderator
    Master

    There you go:

    If MyConditions AND Not OnMarket THEN  //make sure your conditions are still met to place a pending order
       BUY 1 CONTRACT AT MyEntryPrice STOP //or LIMIT
    ENDIF

    MyConditions can be any condition or combination of conditions linked either with AND or OR.

    Slowlyslowly thanked this post
    #172140 quote
    Lialh
    Participant
    New

    There you go:

    Essentially, what I need is to find and ‘set the order price’ at a high of that particular bar that the other conditions are met, and then to keep that order in place for the next 10 bars until it triggers.
    I can’t seem to still get that right in the code though.
    Do you perhaps have any ideas on how to do that? I have used your code below, but I think that I am doing something wrong though.
    Thanks.

    MyConditions can be any condition or combination of conditions linked either with AND or OR.

    #172142 quote
    robertogozzi
    Moderator
    Master

    There you go:

    DEFPARAM CumulateOrders = FALSE
    ONCE CondL = 0
    ONCE Count = 0
    ONCE Entry = 0
    ONCE Dist  = 10     //minimum distance from current price required  by the broker
    //                   to place pending orders
    //reset variables when on market
    IF OnMarket THEN
    CondL = 0
    Count = 0
    Entry = 0
    ENDIF
    //increnment count
    IF Count > 0 THEN
    Count = Count + 1
    //reset count and conditions after 10 bars have elapsed
    IF Count > 10 THEN
    Count = 0
    CondL = 0
    Entry = 0
    ENDIF
    ENDIF
    // LONG condition
    IF close crosses over Average[200] then
    CondL = 1
    Count = 1
    Entry = high
    ENDIF
    // entry
    IF Entry > 0 AND Not OnMarket THEN
    IF (close + Dist) < Entry THEN
    BUY 1 Contract AT Entry STOP
    ELSIF (close - Dist) > Entry THEN
    BUY 1 Contract AT Entry LIMIT
    ELSE
    BUY 1 Contract AT Market
    ENDIF
    ENDIF
    // exit
    IF close crosses under Average[200] and LongOnMarket then
    sell at market
    ENDIF
    #172176 quote
    Lialh
    Participant
    New

    Thanks so much for the help Roberto

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

Order placing in code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 8 replies,
has 2 voices, and was last updated by Lialh
4 years, 8 months ago.

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