Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 15:46:09 +0000



[Programming Help] - Unmanaged Automated Trading not working

View Count: 415

[2023-08-02 12:58:53]
User538264 - Posts: 26
Hi, I have been trying to use Unmanaged Automated Trading, but it seems that the restrictions are still in place for managing position.

i.e., If I have an open long position with 2 lots and without any exit orders and then I try to place a limit sell order with 3 quantities to get net short 1 qty. But instead of doing this, it will first flatten the 2 long lots and then short 3 qty which will result in net 3 lots short.

I am using sc.BuyOrder and sc.SellOrder for placing the orders and I have checked all the conditions of unmanaged trading but the issue still persists.

Kindly help me with this.


Thank You.
[2023-08-08 00:16:55]
ForgivingComputers.com - Posts: 960
Please post your unmanaged trading settings.

Automated Trading Management: Unmanaged Automated Trading
[2023-08-08 08:54:12]
Sierra_Chart Engineering - Posts: 17195
But instead of doing this, it will first flatten the 2 long lots and then short 3 qty which will result in net 3 lots short.
This does not make sense. You must actually be doing this in your automated trading system. Check the Trade Activity Log:
Trade Activity Log: Viewing Historical Trade Activity
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2023-08-08 08:54:42
[2023-08-08 09:40:57]
User538264 - Posts: 26
Here is a simple example code I am using to demonstrate this. It takes a long entry with 2 lots when there are two consecutive green bars printed on chart and places a limit sell order with 3 qty as soon as the entry is taken.
I am also attaching a picture of the chart including the service log.

You can see that as soon as I place the sell order, the position is flattened first and then the 3 lot sell order is placed.
https://www.sierrachart.com/image.php?Image=1691487560369.png




int32_t PlaceMarketEntry(SCStudyInterfaceRef sc, SCString longShort, int qty, SCString OrderTag)
{
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = qty;
  NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  NewOrder.TextTag = OrderTag;


  if (longShort == "BUY")
    sc.BuyOrder(NewOrder);
  else
    sc.SellOrder(NewOrder);

  SCString msg;
  msg.Format("Market order with qty %d", qty);
  sc.AddMessageToLog(msg, 1);


  return NewOrder.InternalOrderID;

}

int32_t PlaceLimitEntry(SCStudyInterfaceRef sc, SCString longShort, int qty, double EntryPrice, SCString OrderTag)
{
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = qty;
  NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  NewOrder.TextTag = OrderTag;
  NewOrder.Price1 = EntryPrice;

  if (longShort == "BUY")
    sc.BuyOrder(NewOrder);
  else
    sc.SellOrder(NewOrder);

  SCString msg;
  msg.Format("Limit order - price %.02f with qty %d", EntryPrice, qty);
  sc.AddMessageToLog(msg, 1);

  return NewOrder.InternalOrderID;

}

SCSFExport scsf_aza_testBothSidePosition(SCStudyInterfaceRef sc)
{

  SCString scriptName = "testBothSidePosition";


  if (sc.SetDefaults)
  {

    sc.GraphName = scriptName;
    sc.GraphRegion = 0; //Main chart region
    sc.AutoLoop = 1;

    sc.MaximumPositionAllowed = 500;

    sc.AllowMultipleEntriesInSameDirection = true;
    sc.AllowOppositeEntryWithOpposingPositionOrOrders = true;
    sc.CancelAllOrdersOnEntriesAndReversals = false;
    sc.CancelAllWorkingOrdersOnExit = false;
    sc.AllowEntryWithWorkingOrders = true;
    sc.AllowOnlyOneTradePerBar = false;
    sc.SupportReversals = true;

    sc.MaintainTradeStatisticsAndTradesData = true;



    return;
  }

  if (sc.IsFullRecalculation && sc.Index == 0)
    sc.ClearAllPersistentData();

  s_SCPositionData PositionData;
  sc.GetTradePosition(PositionData);


  if (sc.Close[sc.Index] > sc.Close[sc.Index - 1] && sc.Close[sc.Index - 1] > sc.Close[sc.Index - 2] && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED && !sc.IsFullRecalculation)
    PlaceMarketEntry(sc, "BUY", 2, scriptName);
  



  if (PositionData.PositionQuantity != 0 && !PositionData.WorkingOrdersExist)
  {
    PlaceLimitEntry(sc, "SELL", 3, sc.Close[sc.Index] + 10 * sc.TickSize, scriptName);
  }


}



Date Time Of Last Edit: 2023-08-08 09:44:33
imagetoSC.png / V - Attached On 2023-08-08 09:36:53 UTC - Size: 77.34 KB - 74 views
[2023-08-08 14:41:01]
Sierra_Chart Engineering - Posts: 17195
Set :
sc.SupportReversals= 0;
Refer to:
Automated Trading Management: SupportReversals
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2023-08-08 15:14:33]
User538264 - Posts: 26
Thanks a ton for this. Since there was nothing mentioned about sc.supportReversals on the documentation page of unmanaged autotrading, I missunderstood it. Also, I have tried it earlier too but it did not work apparently because I did not remove and reload the study at that time. It seems to be working now and I'll try this on my running studies.

Thanks again, I appreciate the help.

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

Login

Login Page - Create Account