Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 21:42:23 +0000



Post From: Offering To The Community: Brett's Multi-Function Trailing Stop

[2015-10-27 15:33:11]
User126996 - Posts: 30
Just at a glance it appears that it won't replay outside of trading hours bc the "HandleTimeExitSetup" is set against sc.CurrentSystemDateTime. Therefore, if your system time is outside the hours of trading it cancels all orders. I would recommend the following code to fix this. I apologize that I can't implement this. I have a few appointments today to get to. But I at least wanted to share immediately to help solve the issue. Thanks for sharing this! If you are rusty with programming it sure doesn't show.


// Establishes adjustable inputs for time ext in SC Defaults
if (sc.SetDefaults){
sc.Input[33].Name = "Start Hour";
sc.Input[33].SetInt(0);
sc.Input[33].SetIntLimits(0, 23);

sc.Input[34].Name = "Start Minute";
sc.Input[34].SetInt(0);
sc.Input[34].SetIntLimits(0, 59);

sc.Input[35].Name = "End Hour";
sc.Input[35].SetInt(14);
sc.Input[35].SetIntLimits(0, 23);

sc.Input[36].Name = "End Minute";
sc.Input[36].SetInt(0);
sc.Input[36].SetIntLimits(0, 59);

return; }

/***************************************************************************
Start - Calculating Time Exit Strategy
***************************************************************************/
int StartTime, EndTime, InputDate;
SCDateTime StartDateTime, EndDateTime, InputDateTime1, InputDateTime2;

InputDate = sc.BaseDateTimeIn[sc.Index].GetDate();
InputDateTime1 = sc.BaseDateTimeIn[sc.Index];
InputDateTime2 = sc.BaseDateTimeIn[sc.Index - 1];

StartTime = HMS_TIME(sc.Input[33].GetInt(), sc.Input[34].GetInt(), 0);
StartDateTime = COMBINE_DATE_TIME(InputDate, StartTime);
EndTime = HMS_TIME(sc.Input[35].GetInt(), sc.Input[36].GetInt(), 0);
EndDateTime = COMBINE_DATE_TIME(InputDate, EndTime);

/***************************************************************************
Stop - Calculating Exit Strategy
***************************************************************************/

/***************************************************************************
Start - Execution of Time Exit Strategy
***************************************************************************/

int& inTradeTime = sc.GetPersistentInt(0);
int& outTradeTime = sc.GetPersistentInt(1);

if (InputDateTime1 > StartDateTime && InputDateTime1 < EndDateTime ) {

inTradeTime = 1; }

else { inTradeTime = 0; }


if (InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime && PositionStatus != 0) {

outTradeTime = 1;
sc.FlattenAndCancelAllOrders();
return; }

else { outTradeTime = 0; }



I hope this helps. I just glanced through the programming.