в параметрах
TP = % для закрытия части
TPLot = частичное закрытие шт.
без стопа, переворот.
Код: Выделить всё
function Initialize()
{
StrategyName = "SuperTrendParts";
AddParameter("PeriodATR", 4, "", 1);
AddParameter("PeriodCCI", 39, "", 1);
AddParameter("K", 1, "", 1);
AddParameter("TP", 0.5, "TakeProfit %", 1);
AddParameter("TPLot", 1000, "Lot TakeProfit", 1);
AddInput("Input1", Inputs.Candle, 60, true, "SBER=МБ ЦК");
LongLimit = 5000;
ShortLimit = -5000;
AddChartIndicator("MY.SuperTrend", new Dictionary <string, string>{{"PeriodATR", "PeriodATR"},{"PeriodCCI", "PeriodCCI"},{"K", "K"}});
AddGlobalVariable("N", Types.Int, 0);
AddGlobalVariable("Last", Types.Double, 0);
}
function OnUpdate()
{
// evge 08.10.2019 https://alfadirect4.ru
var I = Input1;
var ST = MY.SuperTrend(Input1, PeriodATR, PeriodCCI, K);
var CP = CurrentPosition();
/// ПРАВИЛО 1
if ( ST["U"][1] > 0 && N >= 0)
{
EnterLong();
Last = I.Close[0];
N = -1;
}
/// ПРАВИЛО 2
if ( ST["D"][1] > 0 && N <= 0)
{
EnterShort();
Last = I.Close[0];
N = 1;
}
if (CP > 0 && I.Close[0] > Last * (1 + TP * 0.01)) { CloseLong(TPLot); Last = I.Close[0]; }
if (CP < 0 && I.Close[0] < Last * (1 - TP * 0.01)) { CloseShort(TPLot); Last = I.Close[0]; }
}