New York, NY
Experience: Master
Platform: Various
Trading: Everything that moves
Posts: 217 since Feb 2014
Thanks Given: 340
Thanks Received: 466
|
SCENARIO = THERE IS A LONG POSITION WITH AN ATTACHED STOP BELOW
bool flag = true;
//Find PreExistingStop ID
s_SCTradeOrder PreExistingStop;
int StopResult = sc.GetNearestStopOrder(PreExistingStop);
int PreExistingStopOrderID = PreExistingStop.InternalOrderID;
//Get position data
s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);
//Run the following only on the most recent bar
if (sc.Index == sc.ArraySize - 1)
{
//this says execute if flag=true and the distance between the high and the PositionData.AveragePrice is >= 10
if (((max(sc.High[sc.Index],sc.High[sc.Index-1]) - PositionData.AveragePrice) >= 10))
&& flag)
{
int Result = sc.CancelOrder(PreExistingStop.InternalOrderID); // this cancels the PreExistingStop
if (Result > 0) // if PreExistingStop succesfully cancelled enter new sell stop at 1800 and make flag=false
{
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 1;
NewOrder.OrderType = SCT_ORDERTYPE_STOP;
NewOrder.TimeInForce = SCT_TIF_GTC;
NewOrder.Stop1Price = 1800;
int Result = sc.SellEntry(NewOrder);
flag = false;
}
}
}
Once the trigger is reached, if flag=true, that 1) cancels the preexisting stop, 2) creates a new stop at 1800, and 3) makes flag=false.
THIS WORKED.
Needed to tinker with the following to get it to work:
sc.AllowEntryWithWorkingOrders = true;
sc.AllowOnlyOneTradePerBar = false;
sc.AllowMultipleEntriesInSameDirection = true;
|