Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 13:20:25 +0000



[Programming Help] - How to attached a custom name to an order using s_SCNewOrder::TextTag?

View Count: 391

[2025-03-04 23:25:36]
LTSys - Posts: 68
I was reading the docs about TextTag and it says...

Automated Trading From an Advanced Custom Study: [Type: SCString] s_SCNewOrder::TextTag

This is an optional text string that can be set to any free-form text that you want, to help identify an order.

So I use this code to add the TextTag to the order...


  s_SCNewOrder order;
  
  order.OrderType = SCT_ORDERTYPE_MARKET;
  order.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  // additional order code
  
  SCString tag;
  
  order.TextTag = tag.Format("Buy Order %u", count);

But when retrieving the order's TexTag later I get this text "SimpleBracket.twconfig"

Is there some extra step I'm missing?

TIA
Date Time Of Last Edit: 2025-03-04 23:29:27
[2025-03-05 04:08:17]
cmet - Posts: 690
Are you sending attached orders? If you are, the Trade Management may be overwriting it.

Simple things to look at:

Uncheck "Use Attached Orders" in the trade window (if you haven't already)

Set the Attached Order Configuration
order.AttachedOrderConfiguration = 0;

Try clearing the Trade Window Config File before submitting order
sc.TradeWindowConfigFileName = SCString("");

Check to see if the problem persists.
Date Time Of Last Edit: 2025-03-05 04:39:25
[2025-03-05 14:34:11]
John - SC Support - Posts: 39362
Refer to the following:
Basic Trading and the Trade Window: Set >> Use Config Name as Text Tag
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2025-03-05 17:08:11]
LTSys - Posts: 68
Are you sending attached orders? If you are, the Trade Management may be overwriting it.

Here is my order code...


  s_SCNewOrder order;
  
  order.OrderType = SCT_ORDERTYPE_MARKET;
  order.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  order.TradeAccount = "Sim1";
  order.Symbol = "EURUSD";
  order.OrderQuantity = 1000;  

  order.Stop1Price = ask - (100 * tick);
  order.Target1Price = ask + (100 * tick)  
  
  order.TextTag.Format("Buy Order %u", count);

  sc.BuyOrder(order);

I did what you suggested and made the code like this..


  sc.TradeWindowConfigFileName = SCString("");

  s_SCNewOrder order;
  
  order.OrderType = SCT_ORDERTYPE_MARKET;
  order.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  order.TradeAccount = "Sim1";
  order.Symbol = "EURUSD";
  order.OrderQuantity = 1000;  

  //order.AttachedOrderConfiguration = 0; // error C2039: 'AttachedOrderConfiguration': is not a member of 's_SCNewOrder'
  
  order.TextTag.Format("Buy Order %u", count);

  sc.BuyOrder(order);

But still no text tag with the value set... I'm looking in the Trade Orders Window to see if its set and the code also loops through all orders and prints the text tag but they are all empty string values.
Date Time Of Last Edit: 2025-03-05 19:47:52
[2025-03-05 18:32:55]
cmet - Posts: 690
Is there no value or are you seeing the SimpleBracket.twconfig?

I would think that this has to do with your Trade Window config.

If you open up the trade window for the chart and go to the Set tab, and disable "Use Config Name as Text Tag"

You could also try using the note which should show up in the Trade Orders Window. Something like this:

order.Note.Format("Buy Order %u", count);

[2025-03-05 18:56:01]
LTSys - Posts: 68
Is there no value or are you seeing the SimpleBracket.twconfig?

Printing the text tag has no value.

You could also try using the note

order.Note.Format("Buy Order %u", count);

I get error C2039: 'Note': is not a member of 's_SCNewOrder'

I would think that this has to do with your Trade Window config.

I'm ok if it don't show up in the window... but I do need to read it back from the order object.. and it's just an empty string.

TIA
Date Time Of Last Edit: 2025-03-05 19:02:27
[2025-03-05 19:25:18]
cmet - Posts: 690
My bad. Not exactly sure why the code you posted wouldn't work but my guess is you're running into this:

If the Use Config Name as Text Tag option is enabled, then this will use the selected Trade Configuration name instead of the Text Tag entry in the Notes column of the Trade Activity Log.

Maybe try saving a custom twconfig file and call it specifically.
[2025-03-05 19:46:04]
LTSys - Posts: 68
Maybe try saving a custom twconfig file and call it specifically.

If I uncheck the 'Use Config Name as Text Tag' and manually enter a tag value the order object contains the manually entered value... so the code reading the order is correct but setting the text tag from the code still doesn't work.
Date Time Of Last Edit: 2025-03-05 19:46:40
[2025-03-05 20:12:21]
cmet - Posts: 690
If you created a custom twconfig, did you change the following

sc.TradeWindowConfigFileName = SCString("");

To something like this?

sc.TradeWindowConfigFileName = "MyCustomConfig.twconfig";

[2025-03-05 20:33:38]
LTSys - Posts: 68
If you created a custom twconfig, did you change the following

Yes... and the text tag value is now the name of the config file 'NewConfig.twconfig'
[2025-03-05 20:37:37]
cmet - Posts: 690
Got me man.

Hopefully someone can sort that out. I'm curious now too.
[2025-03-05 20:41:39]
cmet - Posts: 690
Got me man. Though it clearly looks like the Use Config Name as Text Tag is being invoked.

Hopefully someone can sort that out. I'm curious now too.
[2025-03-05 20:41:59]
LTSys - Posts: 68
Hopefully someone can sort that out. I'm curious now too.

I appreciate all your help... sucks cause my design needs that text tag so I can match up my orders across multiple accounts.
Date Time Of Last Edit: 2025-03-05 20:42:15
[2025-03-05 21:54:17]
cmet - Posts: 690
Since you mentioned that you didn't need to see it in the window, just read it, you can try using

sc.GetTradeWindowTextTag()

But I'm guessing that would only work if your text tags are being applied correctly at some point.

Text tag should be used if Use Config Name as Text Tag is set to 0.
Date Time Of Last Edit: 2025-03-05 21:54:37
[2025-03-05 22:03:06]
LTSys - Posts: 68
Text tag should be used if Use Config Name as Text Tag is set to 0.

I wonder if I can set that in the sc.Defaults call?
[2025-03-05 22:27:43]
cmet - Posts: 690
If I understand correctly, you can't since it's dependent on the Trade Window.

This should be as simple as opening the Trade Window from the chart where your custom study is running and uncheck "Use Config Name as Text Tag".

No idea why it isn't.
[2025-03-05 22:39:59]
LTSys - Posts: 68
I unchecked "Use Config Name as Text Tag" and typed in a value in the empty text box and manually placed an order and that worked. I see the text tag value in the orders window and as the study code loops through the orders the text tag value I entered is there... but if I place an order programmatically through the study and set the text tag in the new order object it's just comes back as an empty string when looping through the orders.

Like you said this code should work...


s_SCNewOrder order;

order.OrderType = SCT_ORDERTYPE_MARKET;
order.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
order.TradeAccount = "Sim1";
order.Symbol = "EURUSD";
order.OrderQuantity = 1000;

order.TextTag = "test 123";

sc.BuyOrder(order);

Date Time Of Last Edit: 2025-03-05 22:44:19
[2025-03-05 23:19:02]
cmet - Posts: 690
Have you tried constructing the text tag in a different way?

Something along these lines:

SCString tag;
tag += "Symbol: ";
tag += order.Symbol;
tag += " | Side: ";
tag += direction;
tag += " | Order #: ";

SCString orderCount;
orderCount.Format("%u", count);
tag += orderCount;

order.TextTag = tag;

[2025-03-05 23:42:21]
LTSys - Posts: 68
I tried as simple as this... but no luck.

order.TextTag = SCString("test 123");

[2025-03-06 00:43:32]
ondafringe - Posts: 322
It worked for me, using this:

NewOrder.TextTag = "Text Tag Test";

The same thing you're doing.

The text tag showed up in my Trade Orders window and I was also able to see it in my code using the debugger:

s_SCTradeOrder TradeOrderData;
sc.GetOrderByOrderID(gl->orderID, TradeOrderData);
TradeOrderData.TextTag;

Regardless of whether I had "Use Config Name as Text Tag" checked or not. And that's on both entry and exit orders placed by my code.
Date Time Of Last Edit: 2025-03-06 01:12:27
[2025-03-06 00:49:28]
LTSys2 - Posts: 9
Thanks... I'll try a new install of Sierra Chart and see what happens.
[2025-03-06 01:44:20]
LTSys2 - Posts: 9
Fresh install and same problem.

As a test I created a study that just tries to open an order.

Put the study on the EURUSD chart and it fails.

Here's the code...


  s_SCNewOrder order;
  
  order.OrderType = SCT_ORDERTYPE_MARKET;
  order.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  order.OrderQuantity = 1000;
  
  order.TextTag = "123456";

  if(static_cast<int>(sc.BuyOrder(order)) > 0) {
    
    sc.AddMessageToLog("success", 0);
    
  } else {
    
    sc.AddMessageToLog("failed", 0);
  }

Date Time Of Last Edit: 2025-03-06 01:47:08
[2025-03-06 02:13:58]
ondafringe - Posts: 322
Check the return value and see what what you get.
[2025-03-06 02:44:11]
LTSys2 - Posts: 9
int result = static_cast<int>(sc.BuyOrder(order));

result comes back as 4294958298

Docs say...

Returns: A return value > 0 indicates the order was successfully submitted. If the value is > 0, then this value indicates the quantity of the submitted order. If the return value is negative, < 0, the order submission was ignored.

The code submitted 1000 not 4294958298!

And no order is being placed?

And it should have fallen into this code block but it doesn't?

if(static_cast<int>(sc.BuyOrder(order)) > 0)

Weird stuff going on!
Date Time Of Last Edit: 2025-03-06 02:45:33
[2025-03-06 02:56:46]
LTSys2 - Posts: 9
I checked if result was an error code


  int result = static_cast<int>(sc.BuyOrder(order));
  
  message.Format("error code: %u message: %s", result, sc.GetTradingErrorTextMessage(result));
  
  sc.AddMessageToLog(message, 0);

And got this output...

error code: 4294958298 message: Order entry skipped because full recalculation
Date Time Of Last Edit: 2025-03-06 03:01:21

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

Login

Login Page - Create Account