Poyarkov696
0
All posts from Poyarkov696
  Poyarkov696 in Poyarkov696,

Робот-скальпер

'программа выставляет две заявки на некотором расстоянии от bid и offer и передвигает их в случае изменения цены. Заявки срабатывают на быстром резком микро движении. По сле того как обе заявки сработают выставляются новые две заявки на покупку и продажу.

PORTFOLIO_EX scalp;
DESCRIPTION scalp;
CLIENTS_LIST ALL_CLIENTS;
FIRMS_LIST ALL_FIRMS;

INCLUDE func_gr.txt;

PROGRAM
NEW_GLOBAL ("NorderS", 0)
NEW_GLOBAL ("PorderS", 0)
NEW_GLOBAL ("KorderS", 0)
NEW_GLOBAL ("SorderS", "")
NEW_GLOBAL ("NorderB", 0)
NEW_GLOBAL ("PorderB", 0)
NEW_GLOBAL ("KorderB", 0)
NEW_GLOBAL ("SorderB", "")
NEW_GLOBAL ("deposit", 0)
NEW_GLOBAL ("shares", 0)
NEW_GLOBAL ("HPC", 0)
NEW_GLOBAL ("LPC", 0)
NEW_GLOBAL ("first_start", 1)
NEW_GLOBAL ("shares", 0)
NEW_GLOBAL ("cash", 0)
NEW_GLOBAL ("total", 0)
NEW_GLOBAL ("stop", 0)
NEW_GLOBAL ("error", 0)

path="c:\program1\scalp\"


IF first_start == 1
file_param = path & "param.txt"
ClassCodeList = READ_LINE (file_param, 1*2, error)' код класса инструмента
Instrument = READ_LINE (file_param, 2*2, error)' название инструмента
step= str2num(READ_LINE (file_param, 3*2, error))' шаг
kolinpoint = str2num(READ_LINE (file_param, 4*2, error))' количество в одной точке
outpoint = str2num(READ_LINE (file_param, 5*2, error))'точка выхода (колво степов)

DELETE_ALL_ITEMS()

first_start = 0
end if
file_kill = path & "killer.txt"
file_logS = path & "logS.txt"
file_path = path & "save.txt"

kill=0
kill= str2num(READ_LINE (file_kill, 1, error))
' Блок проверки времени торгов. Торги с 10:45 до 18:45
CurrentHour = GET_VALUE(GET_DATETIME(), "HOUR")
CurrentMin = GET_VALUE(GET_DATETIME(), "MIN")
CurrentSec = GET_VALUE(GET_DATETIME(), "SEC")
CurrentTime = str2num(fTextTime(CurrentHour,CurrentMin,CurrentSec) & "")


CurrentYear = GET_VALUE(GET_DATETIME(), "YEAR")
CurrentMonth = GET_VALUE(GET_DATETIME(), "MONTH")
CurrentDay = GET_VALUE(GET_DATETIME(), "DAY")
CurrentData = str2num(fTextData(CurrentYear,CurrentMonth,CurrentDay) & "")


IF ((CurrentTime >= 100000) AND (CurrentTime

price = get_param(ClassCodeList,Instrument,"last")
offer = get_param(ClassCodeList,Instrument,"offer")
bid = get_param(ClassCodeList,Instrument,"bid")

if (price>1)and(bid>1)and(offer>1)and(stop=0)
if kill=1
kill_order(NorderB)
if rez3
cash=cash-PorderB*kolinpoint
shares=shares+kolinpoint
end if
kill_order(NorderS)
if rez3
cash=cash+PorderS*kolinpoint
shares=shares-kolinpoint
end if
if shares>0
send_order("S",shares,bid)
else
if shares
send_order("B",-shares,offer)
end if
end if
stop=1
else
if ((norderB=0)and(norderS=0))
send_order("B",kolinpoint,bid-step)
send_order("S",kolinpoint,offer+step)
else
take_status(NorderB,"B")
take_status(NorderS,"S")
if SorderB="FILLED"
cash=cash-PorderB*kolinpoint
shares=shares+kolinpoint
end if
if SorderS="FILLED"
cash=cash+PorderS*kolinpoint
shares=shares-kolinpoint
end if
total=cash+shares*price
if (SorderB="FILLED")and(SorderS="FILLED")
send_order("B",kolinpoint,bid-step)
send_order("S",kolinpoint,offer+step)
else
if (SorderS"FILLED")
offer = get_param(ClassCodeList,Instrument,"offer")
if (Porders-(offer+step)<-outpointorporders-offer+step>outpoint)
kill_order(NorderS)
if rez=3
send_order("S",kolinpoint,offer+step)
end if
end if
end if
if (SorderB"FILLED")
bid = get_param(ClassCodeList,Instrument,"bid")
if ((PorderB-(bid-step))<-outpointorporderb-bid-step>outpoint)
kill_order(NorderB)
if rez=3
send_order("B",kolinpoint,bid-step)
end if
end if
end if

end if
end if
end if
end if

DELETE_ALL_ITEMS()
output=CREATE_MAP()
output=SET_VALUE(output,"time" , currenttime)
output=SET_VALUE(output,"NorderB" , NorderB)
output=SET_VALUE(output,"PorderB" , PorderB)
output=SET_VALUE(output,"SorderB" , SorderB)
output=SET_VALUE(output,"NorderS" , NorderS)
output=SET_VALUE(output,"PorderS" , PorderS)
output=SET_VALUE(output,"SorderS" , SorderS)
output=SET_VALUE(output,"shares" , shares)
output=SET_VALUE(output,"total" , total)


ADD_ITEM(1,output)

CLEAR_FILE (file_path)
writeln (file_path, NorderB)
writeln (file_path, PorderB)
writeln (file_path, KorderB)
writeln (file_path, SorderB)
writeln (file_path, NorderS)
writeln (file_path, PorderS)
writeln (file_path, KorderS)
writeln (file_path, SorderS)
writeln (file_path, shares)
writeln (file_path, cash)


END IF
Func take_status(num,type)

n = GET_NUMBER_OF ("ORDERS")
found=0
FOR m FROM 1 TO n
ord = GET_ITEM ("ORDERS", m)
NUMBER = 0+GET_VALUE (ord, "NUMBER") + 0
IF num = NUMBER
pr = GET_VALUE (ord, "PRICE")
if type="B"
PorderB=0+pr
else
PorderS=0+pr
end if
if type="B"
SorderB= GET_VALUE (ord, "STATUS")
else
SorderS= GET_VALUE (ord, "STATUS")
end if
found=1
END IF
END FOR
End Func



FUNC kill_order(key)
trans_params = ""
trans_params = set_value (trans_params, "TRANS_ID", 17)
trans_params = set_value (trans_params, "ACTION", "KILL_ORDER")
trans_params = set_value (trans_params, "CLASSCODE", ClassCodeList)
trans_params = set_value (trans_params,"SECCODE",instrument)
trans_params = set_value (trans_params, "ORDER_KEY", key)
trans_result = SEND_TRANSACTION (30, trans_params)
desc=GET_VALUE (trans_result, "DESCRIPTION")
rez=GET_VALUE (trans_result, "RESULT_EX")+0
message(desc,1)
return
end func

' Функция совершения транзакции
FUNC send_order (operation,Lots,price)
for iii from 0 to 3
trans_params = ""
trans_params = set_value (trans_params, "TRANS_ID", 17)
trans_params = set_value (trans_params, "ACTION", "NEW_ORDER")
trans_params = set_value (trans_params, "CLASSCODE", ClassCodeList)
trans_params = set_value (trans_params, "SECCODE", Instrument)
trans_params = set_value (trans_params, "ACCOUNT", "SPBFUT00KZ7")
trans_params = set_value (trans_params, "OPERATION", operation)
trans_params = set_value (trans_params, "PRICE", price)
trans_params = set_value (trans_params, "QUANTITY", Lots)
trans_result = SEND_TRANSACTION (30, trans_params)
desc=GET_VALUE (trans_result, "DESCRIPTION")
message(desc,1)
IF GET_VALUE (trans_result, "RESULT_EX") = "3" 'если транзакция выполнена
if operation="B"
NorderB = 0+GET_VALUE(trans_result, "ORDER_NUMBER")
PorderB = 0+price
else
NorderS = 0+GET_VALUE(trans_result, "ORDER_NUMBER")
PorderS = 0+price
end if
result=1
return
end if
end for
result=0
return
END FUNC



END_PROGRAM

PARAMETER time;
PARAMETER_TITLE время;
PARAMETER_DESCRIPTION время;
PARAMETER_TYPE string(10);
END



PARAMETER NorderB;
PARAMETER_TITLE NorderB;
PARAMETER_DESCRIPTION NorderB;
PARAMETER_TYPE String(10);
END

PARAMETER PorderB;
PARAMETER_TITLE PorderB;
PARAMETER_DESCRIPTION PorderB;
PARAMETER_TYPE NUMERIC(10,2);
END
PARAMETER SorderB;
PARAMETER_TITLE SorderB;
PARAMETER_DESCRIPTION SorderB;
PARAMETER_TYPE String(10);
END

PARAMETER NorderS;
PARAMETER_TITLE NorderS;
PARAMETER_DESCRIPTION NorderS;
PARAMETER_TYPE String(10);
END

PARAMETER PorderS;
PARAMETER_TITLE PorderS;
PARAMETER_DESCRIPTION PorderS;
PARAMETER_TYPE NUMERIC(10,2);
END

PARAMETER SorderS;
PARAMETER_TITLE SorderS;
PARAMETER_DESCRIPTION SorderS;
PARAMETER_TYPE String(10);
END

PARAMETER shares;
PARAMETER_TITLE shares;
PARAMETER_DESCRIPTION shares;
PARAMETER_TYPE NUMERIC(10,0);
END

PARAMETER total;
PARAMETER_TITLE total;
PARAMETER_DESCRIPTION total;
PARAMETER_TYPE NUMERIC(10,0);
END