Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with OCO order in a strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with OCO order in a strategy

    Plz help me correct this code. It compiles but unable to enable the strategy. My goals is to enter long based on some criteria and as soon i am long, want to place OCO order to book profit or loss.

    Code:
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[0] < 2)
                    return;
    
                 // Set 1
                if ((Close[0] > Close[1])
                     && (Position.MarketPosition == MarketPosition.Flat)
                     && (CrossAbove(Close, EMA1, 1))
                     && (ATR1[0] > ATRLength))
                {
                    Targetprice = (ATR1[0] / 2) ; // store a target price to exit
                    Stopprice = (Low[2] - 0.25) ; // store a stop price to exit
                    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0,  0, "oco1", "emascalp"); // entr long if the criteria is met
                    
                }
                
                if ((Position.MarketPosition == MarketPosition.Long)) // if long position established
                {
                    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, 1, Targetprice,  0, "oco1", "emascalp"); //submit oco profit booking order
                    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket,  1, Stopprice,  0, "oco1", "emascalp");// submit oco loss booking order
                }
                
            }
            ​

    #2
    Hello percy3687,

    Thank you for your post.

    If your strategy is getting automatically disabled, what is the full error being shown in the Log tab of the Control Center?

    Please note that OCO strings should not be reused. Use unique strings for each OCO group, and reset after orders in that group are filled/canceled.

    Below is also a link to a sample script which demonstrates submitting orders using the Unmanaged Approach:

    Hi, Is there a collection of sample/reference strategies that illustrates how to use the unmanaged order approach in advanced scenarios which also illustrates all the things one would need to be concerned about vs using the managed approach? Is there something like that you can point me to? Thanks, FaaastEddy

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    91 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    121 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    72 views
    0 likes
    Last Post PaulMohn  
    Working...
    X