Ha зaкpытии бeлoй cвeчи зaкpывaeм paнee oткpытыe лoнги в плюc.т.е. чтобы закрыть в плюс ВСЕ лонги, надо закрывать позицию не на первой попавшейся белой свече, а только по цене выше самой дорогой из предыдущих покупок.
for (int bar = 1; bar < Bars.Count; ++bar) {
if (IsLastPositionActive && (bar == Bars.Count-1 ||
Close[bar] > Open[bar])) {
while (ActivePositions.Count > 0)
ExitAtClose (bar, ActivePositions[0]);
} else if (bar < Bars.Count-10 && Close[bar] < Open[bar]) {
BuyAtClose (bar);
}
}
История торгов Сбера с 01.01.2018 по 31.12.2024 на дневках добыта с сайтаfor (int bar = 1; bar != Bars.Count; ++bar) {
if (IsLastPositionActive && (bar == Bars.Count-1 ||
Close[bar] > Open[bar])) {
while (ActivePositions.Count > 0)
ExitAtClose (bar, ActivePositions[0]);
} else if (bar < Bars.Count-10 && Close[bar] < Open[bar])
BuyAtClose (bar);
}
и его аналог на C++for (unsigned bar = 1; bar != Count; ++bar) {
if (IsLastPositionActive() && (bar == Count-1 ||
Close[bar] > Open[bar])) {
while (ActivePositions.size() > 0)
ExitAtClose (bar, ActivePositions.front());
} else if (bar < Count-10 && Close[bar] < Open[bar])
BuyAtClose (bar);
}
На всё-про-всё ушла рабочая неделя — годы уже не те.-- График должен быть открыт в Quik'е
Class = "SPBFUT" -- "CETS_MTL" "CETS"
SecId="BRK4" -- "NGJ4" "GLDRUB_TOM" "USD000UTSTOM" "SiZ3"
Intrvl = INTERVAL_H1 -- D1 -- M5
Header = "<TICKER>;<PER>;<DATE>;<TIME>;"..
"<OPEN>;<HIGH>;<LOW>;<CLOSE>;<VOL>"
Period = "60" -- Дневки - 0, W1, MN1, H4, H2 - недопустимо
function Log (i)
local t = DS:T(i)
local ymd = string.format ("%04d%02d%02d", t.year, t.month, t.day)
local hms = string.format ("%02d%02d%02d", t.hour, t.min, t.sec);
if not (IniDt <= ymd and ymd <= FinDt) or
not (IniTm <= hms and hms <= FinTm) then return end
local str = string.format ("%s;%s;%s;%s;%.4f;%.4f;%.4f;%.4f;%.0f\n"
,SecId, Period, ymd, hms
,DS:O(i), DS:H(i), DS:L(i), DS:C(i), DS:V(i))
F:write (str)
end -- Log()
function OnInit (scriptPath)
qu = require ("QuikUtil(qu)") -- lu,qc,tu
ScriptDir, ScriptName = lu.