Login Page - Create Account

Support Board


Date/Time: Wed, 07 May 2025 15:06:15 +0000



[Programming Help] - Beginner ACSIL help please

View Count: 505

[2024-11-25 02:43:33]
User745789 - Posts: 377
I hope I don't end up asking too much. I have started from zero knowledge and been able to piece together the below code using youtube and SC documentation.

At 10:45am I want to place the OCO orders as stipulated. It is working so far! Except that it appears to be placing that order repeatedly every millisecond (?) so long as the last bar time is 10:45am.

What I want is for the OCO order to be placed once at the moment the time becomes 10:45am. And then nothing else.

Any guidance would be greatly appreciated. To be honest I am surprised I have even made it this far in a few days.

  SCDateTime BarDateTime = sc.BaseDateTimeIn[sc.Index];
  
  int Hour = BarDateTime.GetHour();
  int Minute = BarDateTime.GetMinute();
  if(Hour == 10 && Minute == 45) {
    
    float BarLow = sc.Low[sc.Index-1];
    float BarHigh = sc.High[sc.Index-1];     

    s_SCNewOrder NewOrder;
    NewOrder.OrderQuantity = 1;
    NewOrder.OrderType = SCT_ORDERTYPE_OCO_BUY_STOP_SELL_STOP;
    NewOrder.Price1 = BarHigh + 1;
    NewOrder.Price2 = BarLow - 1;
    
    NewOrder.TimeInForce = SCT_TIF_DAY;
      
    
    sc.SubmitOCOOrder(NewOrder);
  }

To be honest, I am not sure if the error is the bar time. Because I added the following with a stipulation for "Second", and the orders are still produced repeatedly for the duration of the 15 minute bar.

if(Hour == 10 && Minute == 45 && Second == 0)

And when I set "Second == 1", I dont get any orders placed at all.
Date Time Of Last Edit: 2024-11-25 05:08:33
[2024-11-25 11:31:41]
Tr00pz - Posts: 20
You need to add order tracking to confirm that the order at 10:45 am has been placed so that it doesn't continue to try.
[2024-11-26 00:33:00]
User745789 - Posts: 377
Thanks for taking the time to reply.

But I have not found much mention of "order tracking" in the docs. Can you provide a bit more guidance in that regard?

I need to work out if there is an existing working order, I think it might involve this? Automated Trading From an Advanced Custom Study: IsWorkingOrderStatus()

And maybe these two
https://www.sierrachart.com/index.php?l=doc/ACSILTrading.html#GettingOrderInformation
Automated Trading From an Advanced Custom Study: sc.GetOrderByIndex

I also found this in the SC forum, but no mention of it in the docs: PositionData.WorkingOrdersExist

So I tried this, but the compiler doesn't like it. I have to declare PositionData, which I am trying to do without success.

int Hour = BarDateTime.GetHour();
int Minute = BarDateTime.GetMinute();
int Second = BarDateTime.GetSecond();
int workingOrderExists = PositionData.WorkingOrdersExist();
if(Hour == 10 && Minute == 45 && Second == 0 && !workingOrderExists) {

This example code form SC Engineering uses && !PositionData.WorkingOrdersExist seemingly without declaring it, but I cant find a way to use it in the same manner...
Simple ACSIL example to scale in to a trade

Here is my attempt. Compiler tells me "error: 'PositionData' was not declared in this scope; did you mean 's_SCPositionData'?".

int Hour = BarDateTime.GetHour();
int Minute = BarDateTime.GetMinute();
int Second = BarDateTime.GetSecond();
//int workingOrderExists = PositionData.WorkingOrdersExist();
if(Hour == 10 && Minute == 45 && Second == 0 && !PositionData.WorkingOrdersExist) {

So I looked on the internet and found a hint, this is what I have and it compiles! But I still get rapidly incrementing new orders being added, so I think && !PositionData.WorkingOrdersExist isn't working as hoped.

s_SCPositionData PositionData;
  
int Hour = BarDateTime.GetHour();
int Minute = BarDateTime.GetMinute();
int Second = BarDateTime.GetSecond();

if(Hour == 10 && Minute == 45 && Second == 0 && !PositionData.WorkingOrdersExist) {

I have no idea how to use the above properly. Sorry for all these details, I am trying to demonstrate what I have attempted myself before asking for help :)

I tried these, but didn't work, but I am not surprised.

sc.AllowMultipleEntriesInSameDirection = false;
sc.MaximumPositionAllowed = 1;

And my ongoing concern, why didn't the "Seconds == 0" condition work?
Date Time Of Last Edit: 2024-11-26 01:25:46
[2024-11-26 03:08:32]
seandunaway - Posts: 348
you've allocated space for a s_SCPositionData but you haven't filled it with anything

Automated Trading From an Advanced Custom Study: sc.GetTradePosition

for what it's worth, you'll ultimately save yourself a heap of time if you take a timeout to read a very basic c/c++ book, understand compiler diagnostics, and become proficient with a debugger - you'll be unstumpable
Date Time Of Last Edit: 2024-11-26 03:08:59
[2024-11-26 03:49:50]
User745789 - Posts: 377
I'll get a book or basic course.

I tried this, it compiles, but it still doesn't solve the problem in the original post.

s_SCPositionData PositionData;

int Hour = BarDateTime.GetHour();
int Minute = BarDateTime.GetMinute();
int Second = BarDateTime.GetSecond();
int WorkingOrders = PositionData.WorkingOrdersExist;
if(Hour == 10 && Minute == 45 && Second == 0 && !WorkingOrders) {

I'll give a $50 Amazon gift voucher to anyone who helps me solve this.
Date Time Of Last Edit: 2024-11-26 03:50:57
[2024-11-26 08:54:31]
User431178 - Posts: 667
PositionData is empty until you call the GetTradePosition function.
Automated Trading From an Advanced Custom Study: sc.GetTradePosition



s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);



To be honest, I am not sure if the error is the bar time. Because I added the following with a stipulation for "Second", and the orders are still produced repeatedly for the duration of the 15 minute bar.

The bar time is the time at the beginning of the bar, it does not change (though you could use the end datetime).
ACSIL Interface Members - Variables and Arrays: sc.BaseDataEndDateTime[]



s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);

int Hour = BarDateTime.GetHour();
int Minute = BarDateTime.GetMinute();
int Second = BarDateTime.GetSecond();

if(Hour == 10 && Minute == 45 && Second == 0
&& !PositionData.WorkingOrdersExist
&& PositionData.PositionQuantity == 0) {


}

I second the advice offered by @seandunaway, you might also find some useful tips from the videos these guys have on youtube.

https://www.youtube.com/@FrozenTundraTrader
https://www.youtube.com/@VerrilloTrading
[2024-11-26 23:57:42]
User745789 - Posts: 377
Thank you User431178! I'll be in touch to get your email address to send the Amazon gift voucher. I was experimenting with things close to your solution, but doubt I would have gotten there by trial and error. There is very little in the documentation to help, and I could not find any example code to mimic. These two lines don't really have any meaning to me. But the rest makes sense.


s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);

It was Frozen Tundra's youtube content that got me as far as I have. With some help for the forum I now have a working trading system with 88 lines of code. All I need to do now is add the trigger to move stoploss to breakeven and it is finished.

Edit, my move to breakeven doesn't work when the trigger is hit. I got the example code from tradingsystem.cpp that ships with SC. Any hints?

//Move SL to BE
  s_SCNewOrder NewOrder;
  NewOrder.MoveToBreakEven.Type = MOVETO_BE_ACTION_TYPE_OCO_GROUP_TRIGGERED;
  NewOrder.MoveToBreakEven.TriggerOffsetInTicks = 10;
  NewOrder.MoveToBreakEven.BreakEvenLevelOffsetInTicks = 0;
  NewOrder.MoveToBreakEven.TriggerOCOGroup= OCO_GROUP_1;

Another piece of example code in the same script is as follows. But that doesnt move the SL either

    // This is a common setting and applies to all Stop Attached Orders set on the main order.
      NewOrder.MoveToBreakEven.Type=MOVETO_BE_ACTION_TYPE_OFFSET_TRIGGERED;

      //After 5 ticks of profit, the stop order will be moved to breakeven
      NewOrder.MoveToBreakEven.TriggerOffsetInTicks= 5;
      NewOrder.MoveToBreakEven.BreakEvenLevelOffsetInTicks= 0;

Perhaps the location of the breakeven code is wrong. Though I have it outside the if statement that controls entry of positions. So it seems ok to me.

ps, I have started a 50 hour online intro to C++ course. It is quite good so far.
Date Time Of Last Edit: 2024-11-27 01:34:16
[2024-11-27 09:33:44]
User431178 - Posts: 667
Perhaps the location of the breakeven code is wrong.

Probably.
Upload the code here or send it by DM and I will help.

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

Login

Login Page - Create Account