커뮤니티
수식 부탁드립니다.
2015-05-14 10:44:13
126
글번호 86015
안녕하십니까? 매번 성의 있는 답변 감사드립니다.
1.
반올림 함수로 round 가 있던데,
단순 반올림이 아니라 0.25, 0.5 등 더 작은 단위의 반올림은 안되더군요.
얼마전 제가 부탁드려 짜주셨던 진입문인데, 여기서 어찌 고쳐야 될지 모르겠습니다.
if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then
var1 = O;
if MarketPosition <= 0 and stime == 155000 Then
buy("b1",AtStop,NextBarOpen*1.01);
if MarketPosition >= 0 and stime == 155000 Then
sell("s1",AtStop,NextBarOpen*0.99);
if MarketPosition <= 0 and H < var1*1.01 Then
buy("b",AtStop,var1*1.01);
if MarketPosition >= 0 and L > var1*0.99 Then
sell("s",AtStop,var1*0.99);
SetStopLoss(1,PercentStop);
위의 수식에서 0.25 의 반값인 0.125 를 반올림 단위로 쓰고 싶습니다.
예를들어, 호가 단위가 0.25 일 때,
진입가를 계산했더니 1.6243 이 나왔습니다.
이 값은 1.5 와 1.75 사이에 있는데,
1.6243 - 1.5 = 0.1243 입니다.
이 값은 0.125 미만 값이므로 진입가는 1.5 가 되었으면 합니다.
만약 0.125 이상 값이 경우는 1.75 가 될 것입니다.
엑셀과는 달리 풀어써야 할 듯 한데 어찌 할지 모르겠네요.
그리고,
위에 말씀드린 0.25 나 0.5 등의 반올림식을
변수로 잡고 그 부분만 변형 시켜서 쓸 수는 없나요?
예를들어, 수식에 1.01 이라는 숫자가 많이 나와서
이를 AA = 1.01; 과 같이 미리 대입해 놓으면,
다음에 그 수치를 바꿀때 이 부분만 바꾸면 아래 AA 로 해 놓은 부분도
한꺼번에 바뀌지 않습니까?
그렇듯이 이런 작은 단위의 반올림도 미리 변수로 잡아놓고 그 부분만
바꿔서 쓸 수는 없나요?
종목마다 0.5, 0.25 등등 수치가 다양해서, 일일히 바꾸기가 번거로워서 그렇습니다.
2.
아래식은 손절 회수 제한에 대한 수식을 짜주셨던 것인데,
여기서 만약 3회 손절 제한을 뒀을 경우
재진입 신호가 나와도 '10분 안에는 재진입 금지' 따위는 어떻게 짜야 되는지요?
input : N(3);
var : loss(0);
if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{
var1 = O;
Loss = 0;
}
if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and
(IsExitName("bx",1) == true or IsExitName("sx",1) == true) Then
loss = loss+1;
if loss < N then{
if MarketPosition <= 0 and stime == 155000 Then
buy("b1",AtStop,round(NextBarOpen*1.01,3));
if MarketPosition >= 0 and stime == 155000 Then
sell("s1",AtStop,round(NextBarOpen*0.99,3));
if MarketPosition <= 0 and H < var1*1.01 Then
buy("b",AtStop,round(var1*1.01,3));
if MarketPosition >= 0 and L > var1*0.99 Then
sell("s",AtStop,round(var1*0.99,3));
}
if MarketPosition == 1 Then
ExitLong("bx",AtStop,round(EntryPrice*0.99,3));
if MarketPosition == -1 Then
ExitLong("sx",AtStop,round(EntryPrice*1.01,3));
답변 1
예스스탁 예스스탁 답변
2015-05-14 15:08:54
안녕하세요
예스스탁입니다.
1.
수식의 함수중 PriceScale이
차트종목의 호가단위(1틱)의 값을 리턴히는 함수입니다.
각 종목의 호가를 외부변수 처리하실 필요는 없습니다.
if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then
var1 = O;
if MarketPosition <= 0 and stime == 155000 Then{
if (NextBarOpen*1.01)%PriceScale < PriceScale*0.5 Then
value1 = int((NextBarOpen*1.01)/PriceScale)*PriceScale;
Else
value1 = (int((NextBarOpen*1.01)/PriceScale)+1)*PriceScale;
buy("b1",AtStop,value1);
}
if MarketPosition >= 0 and stime == 155000 Then{
if (NextBarOpen*1.01)%PriceScale < PriceScale*0.5 Then
value1 = int((NextBarOpen*0.99)/PriceScale)*PriceScale;
Else
value1 = (int((NextBarOpen*0.99)/PriceScale)+1)*PriceScale;
sell("s1",AtStop,value1);
}
if MarketPosition <= 0 and H < var1*1.01 Then{
if (NextBarOpen*1.01)%PriceScale < PriceScale*0.5 Then
value1 = int((var1*1.01)/PriceScale)*PriceScale;
Else
value1 = (int((var1*1.01)/PriceScale)+1)*PriceScale;
buy("b",AtStop,value1);
}
if MarketPosition >= 0 and L > var1*0.99 Then{
if (NextBarOpen*1.01)%PriceScale < PriceScale*0.5 Then
value1 = int((var1*0.99)/PriceScale)*PriceScale;
Else
value1 = (int((var1*0.99)/PriceScale)+1)*PriceScale;
sell("s",AtStop,value1);
}
if MarketPosition == 1 Then{
if (NextBarOpen*1.01)%PriceScale < PriceScale*0.5 Then
value1 = int((EntryPrice*1.01)/PriceScale)*PriceScale;
Else
value1 = (int((EntryPrice*1.01)/PriceScale)+1)*PriceScale;
exitlong("bx",AtStop,value2);
}
if MarketPosition == -1 Then{
if (NextBarOpen*1.01)%PriceScale < PriceScale*0.5 Then
value1 = int((EntryPrice*1.01)/PriceScale)*PriceScale;
Else
value1 = (int((EntryPrice*1.01)/PriceScale)+1)*PriceScale;
ExitShort("sx",AtStop,value2);
}
2.
input : N(3);
var : loss(0),entry(0);
var : T(0),T1(0),T2(0),TF(0),TFF(0);
if T == 1 and date != date[1] Then{
T = 2;
T2 = TF;
}
if bdate != Bdate[1] Then{
T = 1;
T1 = TimeToMinutes(stime);
}
if T <= 1 Then
TF = TimeToMinutes(stime)-T1;
Else
TF = TimeToMinutes(stime)+T2;
if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{
var1 = O;
Loss = 0;
entry = 0;
}
if MarketPosition != 0 and MarketPosition != MarketPosition[1] Then
entry = entry+1;
if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and
(IsExitName("bx",1) == true or IsExitName("sx",1) == true) Then
loss = loss+1;
if loss < N then{
if MarketPosition <= 0 and stime == 155000 Then
buy("b1",AtStop,round(NextBarOpen*1.01,3));
if MarketPosition >= 0 and stime == 155000 Then
sell("s1",AtStop,round(NextBarOpen*0.99,3));
if MarketPosition <= 0 and H < var1*1.01 Then{
if entry == 0 or
MarketPosition == -1 or
(MarketPosition == 0 and MarketPosition(1) != 1) or
(MarketPosition == 0 and MarketPosition(1) == 1 and TF >= TF[BarsSinceExit(1)]+10) Then{
buy("b",AtStop,round(var1*1.01,3));
}
}
if MarketPosition >= 0 and L > var1*0.99 Then{
if entry == 0 or
MarketPosition == 1 or
(MarketPosition == 0 and MarketPosition(1) != -1) or
(MarketPosition == 0 and MarketPosition(1) == -1 and TF >= TF[BarsSinceExit(1)]+10) Then{
sell("s",AtStop,round(var1*0.99,3));
}
}
}
if MarketPosition == 1 Then
ExitLong("bx",AtStop,round(EntryPrice*0.99,3));
if MarketPosition == -1 Then
ExitLong("sx",AtStop,round(EntryPrice*1.01,3));
즐거운 하루되세요
> spek 님이 쓴 글입니다.
> 제목 : 수식 부탁드립니다.
>
안녕하십니까? 매번 성의 있는 답변 감사드립니다.
1.
반올림 함수로 round 가 있던데,
단순 반올림이 아니라 0.25, 0.5 등 더 작은 단위의 반올림은 안되더군요.
얼마전 제가 부탁드려 짜주셨던 진입문인데, 여기서 어찌 고쳐야 될지 모르겠습니다.
if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then
var1 = O;
if MarketPosition <= 0 and stime == 155000 Then
buy("b1",AtStop,NextBarOpen*1.01);
if MarketPosition >= 0 and stime == 155000 Then
sell("s1",AtStop,NextBarOpen*0.99);
if MarketPosition <= 0 and H < var1*1.01 Then
buy("b",AtStop,var1*1.01);
if MarketPosition >= 0 and L > var1*0.99 Then
sell("s",AtStop,var1*0.99);
SetStopLoss(1,PercentStop);
위의 수식에서 0.25 의 반값인 0.125 를 반올림 단위로 쓰고 싶습니다.
예를들어, 호가 단위가 0.25 일 때,
진입가를 계산했더니 1.6243 이 나왔습니다.
이 값은 1.5 와 1.75 사이에 있는데,
1.6243 - 1.5 = 0.1243 입니다.
이 값은 0.125 미만 값이므로 진입가는 1.5 가 되었으면 합니다.
만약 0.125 이상 값이 경우는 1.75 가 될 것입니다.
엑셀과는 달리 풀어써야 할 듯 한데 어찌 할지 모르겠네요.
그리고,
위에 말씀드린 0.25 나 0.5 등의 반올림식을
변수로 잡고 그 부분만 변형 시켜서 쓸 수는 없나요?
예를들어, 수식에 1.01 이라는 숫자가 많이 나와서
이를 AA = 1.01; 과 같이 미리 대입해 놓으면,
다음에 그 수치를 바꿀때 이 부분만 바꾸면 아래 AA 로 해 놓은 부분도
한꺼번에 바뀌지 않습니까?
그렇듯이 이런 작은 단위의 반올림도 미리 변수로 잡아놓고 그 부분만
바꿔서 쓸 수는 없나요?
종목마다 0.5, 0.25 등등 수치가 다양해서, 일일히 바꾸기가 번거로워서 그렇습니다.
2.
아래식은 손절 회수 제한에 대한 수식을 짜주셨던 것인데,
여기서 만약 3회 손절 제한을 뒀을 경우
재진입 신호가 나와도 '10분 안에는 재진입 금지' 따위는 어떻게 짜야 되는지요?
input : N(3);
var : loss(0);
if stime == 160000 or (stime > 160000 and stime[1] < 160000) Then{
var1 = O;
Loss = 0;
}
if MarketPosition == 0 and CurrentContracts < CurrentContracts[1] and
(IsExitName("bx",1) == true or IsExitName("sx",1) == true) Then
loss = loss+1;
if loss < N then{
if MarketPosition <= 0 and stime == 155000 Then
buy("b1",AtStop,round(NextBarOpen*1.01,3));
if MarketPosition >= 0 and stime == 155000 Then
sell("s1",AtStop,round(NextBarOpen*0.99,3));
if MarketPosition <= 0 and H < var1*1.01 Then
buy("b",AtStop,round(var1*1.01,3));
if MarketPosition >= 0 and L > var1*0.99 Then
sell("s",AtStop,round(var1*0.99,3));
}
if MarketPosition == 1 Then
ExitLong("bx",AtStop,round(EntryPrice*0.99,3));
if MarketPosition == -1 Then
ExitLong("sx",AtStop,round(EntryPrice*1.01,3));
다음글
이전글