Login Page - Create Account

Support Board


Date/Time: Thu, 28 Mar 2024 17:18:28 +0000



C++ ACSIL OCO stop/limit order clean implementation

View Count: 684

[2022-05-12 19:15:44]
Sergei Belov - Posts: 3
I am trying to implement OCO stop/limit order in C++/ ACSIL
for several days now and am using templates from TradingSystem.cpp
file which comes with the distribution.

I can show you my code for that with Message Log errors.
I tried 20 different combinations. All compile and produce some statistics.
The closest to correct implementation gives and error message
Trade Order Error - Invalid order prices relative to current price: 4035.25 | Symbol: [Sim]ESM22-CME
Buy Exit Price 4064.500000 TakeProfit 4077.000000 StopLoss 4070.750000

I tried all +1 and -1 factors and still getting the same error message

Another version I get OCO stop/limit order filled but next entry order failed

Maybe you already have some clean example of this

my code is very long but I am happy ton attach the relevant pieces
[2022-05-12 19:41:53]
bradh - Posts: 846
You can get the order qty from the trade window, then set the OrderType, Entry Price (Last in this example), Stop as an Offset, and Target as an offset:


s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = sc.TradeWindowOrderQuantity;
NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
NewOrder.Price1 = sc.Last[sc.Index]; // this is the Entry Price
NewOrder.Target1Offset = TargetTicks.GetInt() * sc.TickSize;
NewOrder.Stop1Offset = StopTicks.GetInt() * sc.TickSize;


[2022-05-12 20:22:46]
Sergei Belov - Posts: 3
Dar BradH

I ran this example -- it now sends exit orders but immediately at current price without any offsets (losing 1 tick on every trade)
even though I put TargetTicks to 50 and StopTicks to 25

You recommend NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;

Before I was using
NewOrder.OrderType = SCT_ORDERTYPE_OCO_BUY_STOP_SELL_STOP;
   NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP;
    NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;
NewOrder.Price1 = price - sc.TickSize * Stop_Level.GetFloat();
NewOrder.Price2 = price + sc.TickSize * Target_Level.GetFloat();
int Result1 = (int)sc.SubmitOCOOrder(NewOrder);


I had a version before with behavior similar to your version (exit trades immediately without any offset)

This should be something simple.
I am pretty good in general C++ but just starting in Sierra Chart.
I also have my own backtesting engine linked to 3 100TB of tick data
and several quant strategies there (I have math PhD from MIT) -- happy to collaborate

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account