커뮤니티
setstoptrailing 함수
2004-12-22 21:58:29
1243
글번호 6126
5이평과 20 이평의 교차를 이용하여 매매하는 식 입니다.
0.2pt 이상 이익난 진입에 대하여 수익에서 30% 수익감소하면 즉시 청산하려고
합니다. setstoptrailing 함수를 사용하려고 하는데요...
if ( intime == entrytime(0) ) then {
setstoptrailing(30, 0.2, percentstop, 0);
}
setstoptrailing 사용법은 맞았죠?
문제는 로직에 있는데요.... 하루에도 여러번 진입을 하게 되는데,
첫번째 진입에 한 해서만 트레일링스톱을 적용하려고 합니다.
첫번째 진입시간을 intime 변수에 할당하여서
intime 시간이 진입시간(entrytime(0))과 일치하는 경우만
setstoptrailing이 실행되도록 짰습니다.
그런데 모든 진입에 대하여 트레일링스톱이 적용되더라구요...
아무리 검토해 봐도 어디가 문제인지 찾을 수가 없군요.
해결해 주세요.....
어떻게 고쳐야 하루에 한 번 첫번째 진입에 대해서만
트레일링 스톱을 할 수 있는지요...
또 왜 제가 짠 식으론 안 되는지요?
input : p3(0.4);
var : value5(0),starthere(0),intime(0);
value5 = ma(c,5)-ma(c,20);
if ( stime > 090000 and stime < 091500 ) then {
starthere = 0;
}
If ( stime > 091500 and stime < 150900) then {
// 첫번째 진입. 전일 종가 넘고 임계치 비교 하여 매수 매도 진입
if (starthere == 0 ) then {
if ( value5 > p3 ) then {
buy("첫매수");
starthere = 5;
intime = entrytime(0);
}
if ( value5 < -1 * p3 ) then {
sell("첫매도");
starthere = 5;
intime = entrytime(0);
}
}
// 두 번째 부터의 재진입
if (starthere == 5 ) then {
if ( value5 > p3 and barssinceexit(1) > 8 ) then { //청산 후 8 동안 쉬는게 좋다.
buy("매수 ");
}
if ( value5 < -1 * p3 and barssinceexit(1) > 8 ) then {
sell("매도 ");
}
}
// 첫 거래는 트레일링 스탑 적용
if ( intime == entrytime(0) ) then {
setstoptrailing(30, 0.2, percentstop, 0);
}
if ( value5 < 0 ) then {
exitlong("0선청산");
}
if ( value5 > 0) then {
exitshort(" 0선청산");
}
} //큰 if 마무리
답변 1
예스스탁 예스스탁 답변
2004-12-24 13:38:40
안녕하세요
예스스탁입니다.
문의하신 식은 다음과 같습니다.
input : p3(0.4);
var : value5(0),cnt(0),pos(0);
value5 = ma(c,5)-ma(c,20);
if date != date[1] then{
pos = 0;
cnt = 0;
}
#장일 첫번째 진입. 전일종가 넘고 임계치비교하여 매수매도 진입
If stime > 091500 and stime < 150000 then{
if marketposition() == 0 and value5 > p3 and pos < 1 then {
buy("첫매수");
pos = pos+1;
cnt = 1;
}
if marketposition() == 0 and value5 < -1 * p3 and pos < 1 then {
sell("첫매도");
pos = pos+1;
cnt = 1;
}
}
// 두 번째 부터의 재진입
if pos == 1 and stime > 091500 and stime < 150000 then {
if marketposition() == 0 and value5 > p3 and barssinceexit(1) > 8 then { //청산 후 8 동안 쉬는게 좋다.
buy("매수 ");
cnt= 0;
}
if marketposition() == 0 and value5 < -1 * p3 and barssinceexit(1) > 8 then {
sell("매도 ");
cnt = 0;
}
}
// 첫 거래는 트레일링 스탑 적용
if cnt == 1 then
setstoptrailing(30, 0.2, percentstop, 0);
else
setstoptrailing(0, 0);
if value5 < 0 or stime == 150000 then
exitlong("0선청산");
if value5 > 0 or stime == 150000 then
exitshort(" 0선청산");
첫매수일때는 셋스탑트레일링을 활성화하고
그 이후에는 해지하는 식입니다.
식을 조금 소중했습니다.
시간등은 기호에 맞게 쓰시면 됩니다.
즐거운 하루되시고 즐거운 크리스마스 되세요
> 대박천사 님이 쓴 글입니다.
> 제목 : setstoptrailing 함수
> 5이평과 20 이평의 교차를 이용하여 매매하는 식 입니다.
0.2pt 이상 이익난 진입에 대하여 수익에서 30% 수익감소하면 즉시 청산하려고
합니다. setstoptrailing 함수를 사용하려고 하는데요...
if ( intime == entrytime(0) ) then {
setstoptrailing(30, 0.2, percentstop, 0);
}
setstoptrailing 사용법은 맞았죠?
문제는 로직에 있는데요.... 하루에도 여러번 진입을 하게 되는데,
첫번째 진입에 한 해서만 트레일링스톱을 적용하려고 합니다.
첫번째 진입시간을 intime 변수에 할당하여서
intime 시간이 진입시간(entrytime(0))과 일치하는 경우만
setstoptrailing이 실행되도록 짰습니다.
그런데 모든 진입에 대하여 트레일링스톱이 적용되더라구요...
아무리 검토해 봐도 어디가 문제인지 찾을 수가 없군요.
해결해 주세요.....
어떻게 고쳐야 하루에 한 번 첫번째 진입에 대해서만
트레일링 스톱을 할 수 있는지요...
또 왜 제가 짠 식으론 안 되는지요?
input : p3(0.4);
var : value5(0),starthere(0),intime(0);
value5 = ma(c,5)-ma(c,20);
if ( stime > 090000 and stime < 091500 ) then {
starthere = 0;
}
If ( stime > 091500 and stime < 150900) then {
// 첫번째 진입. 전일 종가 넘고 임계치 비교 하여 매수 매도 진입
if (starthere == 0 ) then {
if ( value5 > p3 ) then {
buy("첫매수");
starthere = 5;
intime = entrytime(0);
}
if ( value5 < -1 * p3 ) then {
sell("첫매도");
starthere = 5;
intime = entrytime(0);
}
}
// 두 번째 부터의 재진입
if (starthere == 5 ) then {
if ( value5 > p3 and barssinceexit(1) > 8 ) then { //청산 후 8 동안 쉬는게 좋다.
buy("매수 ");
}
if ( value5 < -1 * p3 and barssinceexit(1) > 8 ) then {
sell("매도 ");
}
}
// 첫 거래는 트레일링 스탑 적용
if ( intime == entrytime(0) ) then {
setstoptrailing(30, 0.2, percentstop, 0);
}
if ( value5 < 0 ) then {
exitlong("0선청산");
}
if ( value5 > 0) then {
exitshort(" 0선청산");
}
} //큰 if 마무리
다음글
이전글