Извините на путал, но вот как задумывал.
Код: Выделить всё
function Initialize()
{
StrategyName = "Inputs01";
AddInput("Input1", Inputs.Candle, 5, true, "SiM1=ФОРТС");
AddInput("Input2", Inputs.Candle, 1, false, "SiM1=ФОРТС");
}
function OnUpdate()
{
var I1 = Input1;
var I2 = Input2;
if ((I1.Close[0] > I1.High[1]) && (CurrentPosition() == 0))
{
EnterLong();
WriteLine("c:\\temp\\inputs.txt", String.Format("BUY: Input1: BarDate:{0} BarTime:{1}", Input1.BarDate(), Input1.BarTime()));
StopLoss(1, SignalPriceType.DeltaInPercentFromAveragePrice);
}
if ( (CurrentPLper() > 0.4) && (CurrentPosition() > 0) )
{
CancelStopLoss();
StopLoss(AverPrice()+100, SignalPriceType.Price);
WriteLine("c:\\temp\\inputs.txt", String.Format("BUY: Input1: BarDate:{0} BarTime:{1};{2};{3};{4}", Input1.BarDate(), Input1.BarTime(), CurrentPLper(), AverPrice(), Input1.Close[0]));
}
}
Везде используется 5 минут, минута просто есть.
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:30:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:30:00;0,5719;77640;77640
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:30:00;0,5719;77640;77640
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:30:00;0,5719;77640;77640
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:30:00;0,5719;77640;77640
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:35:00;0,5719;77640;77617
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:15:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:15:00;0,6769;77559;77563
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:15:00;0,6769;77559;77563
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:15:00;0,6769;77559;77563
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:15:00;0,6769;77559;77563
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:20:00;0,6769;77559;77582
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:20:00
Меняем Input2 на 15 минутный таймфрейм
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:30:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:07:35:00;0,5719;77640;77617
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:15:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:20:00;0,6769;77559;77582
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:25:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:08:30:00;0,6017;77617;77580
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:09:15:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:09:20:00;0,7276;77520;77542
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:09:25:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:09:30:00;0,6535;77577;77598
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:09:35:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:09:40:00;0,5253;77676;77786
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:10:20:00
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:10:25:00;0,59;77626;77706
BUY: Input1: BarDate:08.04.2021 0:00:00 BarTime:10:30:00
Файл лог изменился, хотя ни 1 минутый ни 15 минутый в код не используется. И при цене открытия сделки 77640 а цена закрытия 77617 прибыль показывает 0,57 хотя 0,57 это 442,548 пунктов.
То есть надо исполнять на новом баре ряда 1
В том и дело что не сработает, т.к. ТФ не торговый (M5) а минутный будет пытаться отправить (до 5 раз). Он кидает в очередь и выполняет только по торговому инструменту когда придёт бар. Если 5 раз (в данном случае) послать ему CanceStopLoss(); StopLoss(); , то как я понимаю, исполнится только последняя, а остальные проигнорируются.
Код: Выделить всё
if ( Input1.NewBar && (CurrentPLper() > 0.4) && (CurrentPosition() > 0) )
Попробовал вот так ну явно, что то я наглупил.