Login Page - Create Account

Support Board


Date/Time: Sat, 18 May 2024 07:58:47 +0000



[Programming Help] - "Use attached orders" to exit from DLL entries?

View Count: 760

[2019-05-22 12:52:25]
uM8137 - Posts: 180
Is it possible, as a way to experiment with attached bracket orders during a backtest, to have
the GUI Trade window's attached orders exit from a trade entered by an ACSIL trading system?

I have the trade window with the "Use Attached Orders" checked. And there is a green "match",
it looks like this[1]. But my 1 tick stop loss and 1 tick take profit bracket never fire, in code [2].

I suppose this does make sense since the entry order is submitted by the ACSIL system
and it doesn't have the take profit/stop loss OCO bracket attached to it at that time of entry.

But I wonder if there is a workaround, to allow the GUI settings (very convenient) to be
read or utilized by an ASCIL system? To somehow have them attached by the automated trade management?

To summarize, I would actually prefer to put the bracket orders into the DLL code. But for
quick experimentation, it would be nice to be able to set them via the GUI.

So I was curious if the ACSIL study/trading system can read the GUI to implement the
brackets, perhaps, or if there is another simple way of evaluating stop losses in a backtest
of a ACSIL system. I could just add additional Input fields in the study for
setting a stop loss amount, but there is already such
a beautiful GUI available for setting them...!

Thank you for any ideas here!

Best wishes.

[1] Attached Orders: Using a Preconfigured Attached Orders Set

[2] Here is my ACSIL test code (below).


// enter a buy at noon, check if the GUI configured attached orders will exit.
// Even with "use attached orders" checked in the GUI, and
// with a 1 tick stop loss and a 1 tick take profit target,
// the SierraCharts automated trade management never kicks in.
#include "sierrachart.h"

SCDLLName("buy_at_noon")

SCSFExport scsf_buy_at_noon(SCStudyInterfaceRef sc)
{
SCSubgraphRef TakenBuy = sc.Subgraph[0];

if (sc.SetDefaults) {

sc.MaximumPositionAllowed = 60;
sc.AllowMultipleEntriesInSameDirection =1;

sc.GraphName = "buy_at_noon";
sc.StudyDescription = "buy 1 contract at noon.";
sc.GraphRegion = 0;

TakenBuy.Name = "TakenBuy";
TakenBuy.PrimaryColor = COLOR_YELLOW;
TakenBuy.DrawStyle = DRAWSTYLE_ARROWUP;
TakenBuy.LineWidth = 3;
TakenBuy.DrawZeros = false;
  
// Auto Looping On
sc.AutoLoop = 1;

// During development only set to 1
sc.FreeDLL = 1;

// want end times of bars too.
sc.MaintainAdditionalChartDataArrays = 1;

// Must return
return;
}

if(sc.GetBarHasClosedStatus(sc.Index) != BHCS_BAR_HAS_CLOSED) {
return;
}

int &LastBarIndexProcessed = sc.GetPersistentInt(0);
if (sc.Index == 0) {
LastBarIndexProcessed = -1;
}
if(sc.Index == LastBarIndexProcessed) {
return;
}
LastBarIndexProcessed = sc.Index;

int BarStartTime = sc.BaseDateTimeIn.TimeAt(sc.Index);
int minuteOfDay = BarStartTime / 60;

const int noonMinutes = 12 * 60;

if (minuteOfDay == noonMinutes) {
// time to buy

s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 1;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_GTC;
NewOrder.Price1 = 0;
NewOrder.Price2 = 0;

int Result = (int)sc.BuyEntry(NewOrder);
if (Result > 0) {//If there has been a successful order entry, then draw an arrow at the low of the bar.
TakenBuy[sc.Index] = sc.Low[sc.Index] - 2*sc.TickSize;

} else { //order error
SCString Msg;
Msg.Format("at simtm %02i:%02i failed to buy 1 contract, at BarStartTime=%i, Result=%i", minuteOfDay / 60, minuteOfDay % 60, BarStartTime, Result);
sc.AddMessageToLog(Msg, 1);  
sc.AddMessageToLog(sc.GetTradingErrorTextMessage(Result), 0);
}
}
}


[2019-05-22 16:28:31]
uM8137 - Posts: 180
Nevermind! I found

ACSIL Interface Members - Variables and Arrays: sc.SupportAttachedOrdersForTrading

ACSIL Interface Members - Variables and Arrays: sc.UseGUIAttachedOrderSetting

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

Login

Login Page - Create Account