Для ANDY!
Здравствуйте!
Есть скрипт в велсе на средних, сделано было в велсе все отлично работает, но я его не могу переложить в тслаб, прошу оказать помощь. Скрипт выкладываю ниже, можно письмо выкладывать в личку.
Если надо, я могу его конвертировать в шарп.
(*Description...
From the Stocks Trading System lab article in the May 2004 issue of the Active Trader Magazine by Dion Kurczek.
*)
{#OptVar1 1; 1;10;1}
{#OptVar2 4; 2;10;1}
function OurPriceOpen(b:integer):float;
begin
Result := PriceOpen(b);
end;
function WriteFile( action, operation: string; i:integer; price:float): boolean;
begin
var f: integer;
var str:String;
f:= FileOpen('d:\trg2\input.tri');
while not FileEOF( f ) do FileRead( f );
str:= 'TRANS_ID=' + inttostr(i) + ';ACCOUNT=SPBFUT00N10' + ';CLIENT_CODE=SPBFUT00N10'+ //
';STATUS=0' + ';ACTION=' + action + ';CLASSCODE=SPBFUT' +
';SECCODE=SRU0' + ';OPERATION=' + operation +
';QUANTITY=1' + ';PRICE=' + formatfloat('####', price) + ';TYPE=L;';
filewrite(f,str);
fileclose(f);
Result := true;
end;
var offset_buy, offset_sell:integer;
var Bar, fin, fout, i, p: integer;
var x, value: float;
offset_buy := 0; // смещение на покупку
offset_sell := 0; // смещение на продажу
fin := FileCreate('d:\trg2\input.tri' );
FileClose(fin);
// создаем каждый раз новый *.tro файл
fout:= FileCreate('d:\trg2\output.tro' );
FileClose(fout);
value := wMA (Bar, #close, #OptVar1);
PlotSeries( WMASeries( #Close, #OptVar1 ), 0, #Green, #Thick );
PlotSeries( WMASeries( #Close, #OptVar2 ), 0, 030, #Thick );
for Bar := 70 to BarCount - 1 do
begin
if LastPositionActive then
begin
p := LastPosition;
if CrossOver( Bar, WMASeries( #Close, #OptVar1 ), WMASeries( #Close, #OptVar2 ) ) then
begin
// SellAtLimit(Bar, value, LastPosition, 'Limit Sell'); // лимитированная
if Bar = BarCount - 1 then // ИЛИ
WriteFile( 'NEW_ORDER', 'S', CurrentTime, OurPriceOpen(Bar) - offset_sell);
SellAtClose( Bar, p, '' );
end;
end
else
begin
if not LastPositionActive then
begin
if CrossUnder( Bar, WMASeries( #Close, #OptVar1 ), WMASeries( #Close, #OptVar2 ) ) then
begin
BuyAtClose( Bar, '0' );
// BuyAtLimit(Bar, value, 'Limit Buy'); // лимитированная
if Bar = BarCount - 1 then // ИЛИ
WriteFile( 'NEW_ORDER', 'B', CurrentTime, OurPriceOpen(Bar) + offset_buy);
end;
end;
end;
end;