커뮤니티
재질문드립니다.
2019-07-25 17:06:53
186
글번호 130642
아래 수식은 횟수제한이 매수,매도 하루동안 토탈 횟수로 제한이 되는데
원하는 수식은
예를들어 추세마다 한번씩만 진입토록 원할 경우 T1 == 1 and T3 == 3 로 매수 추세가 나오고 진입신호가 나오는 횟수를 얘기하는 부분입니다.
추세가 변경되고 진입신호를 한번만 진입하도록 변경을 원합니다.
추세변경시마다 진입신호가 연달아 나올 경우 진입하는 것을 횟수로 제한하고 싶어서입니다.
input: b_time1(000000),e_time1(240000);
input: stoK_p11(100),stoK_p12(1),stoK_p13(6),상단(99),하단(1);
input: stoK_p21(200),stoK_p22(2),stoK_p23(6),상단1(99),하단1(1),익절틱수(10);
input: stoK_p31(500),stoK_p32(11),stoK_p33(6);
input: stoK_p41(500),stoK_p42(10),stoK_p43(1),상단2(99),하단2(1);
input : 당일수익틱수(200);
input : 당일목표손실(100);
Input : shortPeriod(4000), longPeriod(5000);
value1 = ma(C, shortPeriod);
value2 = ma(C, longPeriod);
Input : short(50), long(100), signal(1000);
Input : short1(1400), long1(3400), signal1(5000);
input : 매수진입횟수(2),매도진입횟수(2);
Var : MACDv(0), MACDs(0),macdo(0) ;
Var : MACDv1(0), MACDs1(0),macdo1(0),Bcount(0),Scount(0);
MACDv = MACD(short, long);
MACDs = ema(MACDv,signal);
macdo = MACDv-MACDs;
MACDv1 = MACD(short1, long1);
MACDs1 = ema(MACDv1,signal1);
macdo1 = MACDv1-MACDs1;
Var : stoK1(0),stoD1(0),stoK2(0),stoD2(0),stoK3(0),stoD3(0),stoK4(0),stoD4(0),T1(0),T2(0),T3(0),T4(0);
var : Tcond(false);
Var : N1(0),dayPl(0),당일수익(0),당일손실(0),Xcond(false),entry(0);
당일수익 = PriceScale*당일수익틱수;
당일손실 = PriceScale*당일목표손실;
if (sdate != sdate[1] and stime >= b_time1) or
(sdate == sdate[1] and stime >= b_time1 and stime[1] < b_time1) Then
{
Tcond = true;
Xcond = false;
N1 = NetProfit;
Bcount = 0;
Scount = 0;
}
if MarketPosition(0) == 1 and MarketPosition(0) != MarketPosition(0)[1] Then
Bcount = Bcount+1;
if MarketPosition(0) == -1 and MarketPosition(0) != MarketPosition(0)[1] Then
Scount = Scount+1;
daypl = NetProfit-N1;
if TotalTrades > TotalTrades[1] Then
{
if (IsExitName("금일수익종료",1) == true or IsExitName("금일손실종료1",1) == true or
IsExitName("금일수익종료2",1) == true or IsExitName("금일손실종료3",1) == true) then
Xcond = true;
if daypl >= 당일수익 or daypl <= -당일손실 Then
Xcond = true;
}
if MarketPosition(0) != 0 and MarketPosition(0) != MarketPosition(0)[1] Then
entry = entry+1;
If b_time1<=sTime and sTime<= e_time1 Then
{
entry = 0;
stoK1 = StochasticsK(stoK_p11,stoK_p12);
stoD1 = StochasticsD(stoK_p11,stoK_p12,stoK_p13);
If stoK1>=(99)
Then
{
T1 = 1;
}
If stoK1<=(1)
Then
{
T1 = -1;
}
stoK2 = StochasticsK(stoK_p21,stoK_p22);
stoD2 = StochasticsD(stoK_p21,stoK_p22,stoK_p23);
If stoK2>=(99)
Then
{
T2 = 2;
}
If stoK2<=(1)
Then
{
T2 = -2;
}
stoK3 = StochasticsK(stoK_p31,stoK_p32);
stoD3 = StochasticsD(stoK_p31,stoK_p32,stoK_p33);
If stoK3>=(99)
Then
{
T3 = 3;
}
If stoK3<=(1)
Then
{
T3 = -3;
}
stoK4 = StochasticsK(stoK_p41,stoK_p42);
stoD4 = StochasticsD(stoK_p41,stoK_p42,stoK_p43);
If stoK4>=(99)
Then
{
T4 = 4;
}
If stoK4<=(1)
Then
{
T4 = -4;
}
}
if Bcount < 매수진입횟수 and Xcond == false and
MarketPosition == 0 and
b_time1<=sTime and sTime<= e_time1 and
T1 == 1 and T3 == 3 and Crossup(stok2,하단) Then
buy("매수",AtMarket);
if MarketPosition == 1 Then
{
Exitlong("금일수익종료2",atlimit,EntryPrice+((당일수익-daypl)/CurrentContracts));
Exitlong("금일손실종료3",AtStop,EntryPrice-((당일손실+daypl)/CurrentContracts));
if value1<value2 and T1 == -1 and T3 == -3 and T4 == -4 Then
ExitLong("추세전환(-)",AtMarket);
}
if Scount < 매도진입횟수 and Xcond == false and
MarketPosition == 0 and
b_time1<=sTime and sTime<= e_time1 and
T1 == -1 and T3 == -3 and Crossdown(stok2,상단) Then
sell("매도",AtMarket);
if MarketPosition == -1 Then
{
ExitShort("금일수익종료",atlimit,EntryPrice-((당일수익-daypl)/CurrentContracts));
ExitShort("금일손실종료1",AtStop,EntryPrice+((당일손실+daypl)/CurrentContracts));
if value1>value2 and T1 == 1 and T3 == 3 and T4 == 4 Then
ExitShort("추세전환(+)",AtMarket);
}
SetStopProfittarget(PriceScale*익절틱수,PointStop);
답변 1
예스스탁 예스스탁 답변
2019-07-26 11:23:55
안녕하세요
예스스탁입니다.
1
T1 == 1 and T3 == 1인 구간에서 1회
T1 == -1 and T3 == -1인 구간에서 1회로 제한했습니다.
각 횟수는 외부변수로 설정하시면 됩니다.
2
if (sdate != sdate[1] and stime >= b_time1) or
(sdate == sdate[1] and stime >= b_time1 and stime[1] < b_time1) Then
{
Tcond = true;
Xcond = false;
N1 = NetProfit;
#Bcount = 0;
#Scount = 0;
}
날짜변경시 동일구간이라도 진입횟수를 초기화 하고자 하시면
위 내용에서 주석 해제하시면 됩니다.
3
input: b_time1(000000),e_time1(240000);
input: stoK_p11(100),stoK_p12(1),stoK_p13(6),상단(99),하단(1);
input: stoK_p21(200),stoK_p22(2),stoK_p23(6),상단1(99),하단1(1),익절틱수(10);
input: stoK_p31(500),stoK_p32(11),stoK_p33(6);
input: stoK_p41(500),stoK_p42(10),stoK_p43(1),상단2(99),하단2(1);
input : 당일수익틱수(200);
input : 당일목표손실(100);
Input : shortPeriod(4000), longPeriod(5000);
value1 = ma(C, shortPeriod);
value2 = ma(C, longPeriod);
Input : short(50), long(100), signal(1000);
Input : short1(1400), long1(3400), signal1(5000);
input : 매수진입횟수(1),매도진입횟수(1);
Var : MACDv(0), MACDs(0),macdo(0) ;
Var : MACDv1(0), MACDs1(0),macdo1(0),Bcount(0),Scount(0);
MACDv = MACD(short, long);
MACDs = ema(MACDv,signal);
macdo = MACDv-MACDs;
MACDv1 = MACD(short1, long1);
MACDs1 = ema(MACDv1,signal1);
macdo1 = MACDv1-MACDs1;
Var : stoK1(0),stoD1(0),stoK2(0),stoD2(0),stoK3(0),stoD3(0),stoK4(0),stoD4(0),T1(0),T2(0),T3(0),T4(0);
var : Tcond(false);
Var : N1(0),dayPl(0),당일수익(0),당일손실(0),Xcond(false),entry(0);
당일수익 = PriceScale*당일수익틱수;
당일손실 = PriceScale*당일목표손실;
if (sdate != sdate[1] and stime >= b_time1) or
(sdate == sdate[1] and stime >= b_time1 and stime[1] < b_time1) Then
{
Tcond = true;
Xcond = false;
N1 = NetProfit;
#Bcount = 0;
#Scount = 0;
}
daypl = NetProfit-N1;
if TotalTrades > TotalTrades[1] Then
{
if (IsExitName("금일수익종료",1) == true or IsExitName("금일손실종료1",1) == true or
IsExitName("금일수익종료2",1) == true or IsExitName("금일손실종료3",1) == true) then
Xcond = true;
if daypl >= 당일수익 or daypl <= -당일손실 Then
Xcond = true;
}
if MarketPosition(0) != 0 and MarketPosition(0) != MarketPosition(0)[1] Then
entry = entry+1;
If b_time1<=sTime and sTime<= e_time1 Then
{
entry = 0;
stoK1 = StochasticsK(stoK_p11,stoK_p12);
stoD1 = StochasticsD(stoK_p11,stoK_p12,stoK_p13);
If stoK1>=(99)
Then
{
T1 = 1;
}
If stoK1<=(1)
Then
{
T1 = -1;
}
stoK2 = StochasticsK(stoK_p21,stoK_p22);
stoD2 = StochasticsD(stoK_p21,stoK_p22,stoK_p23);
If stoK2>=(99)
Then
{
T2 = 2;
}
If stoK2<=(1)
Then
{
T2 = -2;
}
stoK3 = StochasticsK(stoK_p31,stoK_p32);
stoD3 = StochasticsD(stoK_p31,stoK_p32,stoK_p33);
If stoK3>=(99)
Then
{
T3 = 3;
}
If stoK3<=(1)
Then
{
T3 = -3;
}
stoK4 = StochasticsK(stoK_p41,stoK_p42);
stoD4 = StochasticsD(stoK_p41,stoK_p42,stoK_p43);
If stoK4>=(99)
Then
{
T4 = 4;
}
If stoK4<=(1)
Then
{
T4 = -4;
}
}
Condition1 = T1 == 1 and T3 == 3;
Condition2 = T1 == -1 and T3 == -3;
if Condition1 == true and Condition1[1] == false Then
Bcount = 0;
if Condition2 == true and Condition2[1] == false Then
Scount = 0;
if MarketPosition(0) == 1 and MarketPosition(0) != MarketPosition(0)[1] Then
Bcount = Bcount+1;
if MarketPosition(0) == -1 and MarketPosition(0) != MarketPosition(0)[1] Then
Scount = Scount+1;
if Bcount < 매수진입횟수 and Xcond == false and
MarketPosition == 0 and
b_time1<=sTime and sTime<= e_time1 and
T1 == 1 and T3 == 3 and Crossup(stok2,하단) Then
buy("매수",AtMarket);
if MarketPosition == 1 Then
{
Exitlong("금일수익종료2",atlimit,EntryPrice+((당일수익-daypl)/CurrentContracts));
Exitlong("금일손실종료3",AtStop,EntryPrice-((당일손실+daypl)/CurrentContracts));
if value1<value2 and T1 == -1 and T3 == -3 and T4 == -4 Then
ExitLong("추세전환(-)",AtMarket);
}
if Scount < 매도진입횟수 and Xcond == false and
MarketPosition == 0 and
b_time1<=sTime and sTime<= e_time1 and
T1 == -1 and T3 == -3 and Crossdown(stok2,상단) Then
sell("매도",AtMarket);
if MarketPosition == -1 Then
{
ExitShort("금일수익종료",atlimit,EntryPrice-((당일수익-daypl)/CurrentContracts));
ExitShort("금일손실종료1",AtStop,EntryPrice+((당일손실+daypl)/CurrentContracts));
if value1>value2 and T1 == 1 and T3 == 3 and T4 == 4 Then
ExitShort("추세전환(+)",AtMarket);
}
SetStopProfittarget(PriceScale*익절틱수,PointStop);
즐거운 하루되세요
> 미완 님이 쓴 글입니다.
> 제목 : 재질문드립니다.
> 아래 수식은 횟수제한이 매수,매도 하루동안 토탈 횟수로 제한이 되는데
원하는 수식은
예를들어 추세마다 한번씩만 진입토록 원할 경우 T1 == 1 and T3 == 3 로 매수 추세가 나오고 진입신호가 나오는 횟수를 얘기하는 부분입니다.
추세가 변경되고 진입신호를 한번만 진입하도록 변경을 원합니다.
추세변경시마다 진입신호가 연달아 나올 경우 진입하는 것을 횟수로 제한하고 싶어서입니다.
input: b_time1(000000),e_time1(240000);
input: stoK_p11(100),stoK_p12(1),stoK_p13(6),상단(99),하단(1);
input: stoK_p21(200),stoK_p22(2),stoK_p23(6),상단1(99),하단1(1),익절틱수(10);
input: stoK_p31(500),stoK_p32(11),stoK_p33(6);
input: stoK_p41(500),stoK_p42(10),stoK_p43(1),상단2(99),하단2(1);
input : 당일수익틱수(200);
input : 당일목표손실(100);
Input : shortPeriod(4000), longPeriod(5000);
value1 = ma(C, shortPeriod);
value2 = ma(C, longPeriod);
Input : short(50), long(100), signal(1000);
Input : short1(1400), long1(3400), signal1(5000);
input : 매수진입횟수(2),매도진입횟수(2);
Var : MACDv(0), MACDs(0),macdo(0) ;
Var : MACDv1(0), MACDs1(0),macdo1(0),Bcount(0),Scount(0);
MACDv = MACD(short, long);
MACDs = ema(MACDv,signal);
macdo = MACDv-MACDs;
MACDv1 = MACD(short1, long1);
MACDs1 = ema(MACDv1,signal1);
macdo1 = MACDv1-MACDs1;
Var : stoK1(0),stoD1(0),stoK2(0),stoD2(0),stoK3(0),stoD3(0),stoK4(0),stoD4(0),T1(0),T2(0),T3(0),T4(0);
var : Tcond(false);
Var : N1(0),dayPl(0),당일수익(0),당일손실(0),Xcond(false),entry(0);
당일수익 = PriceScale*당일수익틱수;
당일손실 = PriceScale*당일목표손실;
if (sdate != sdate[1] and stime >= b_time1) or
(sdate == sdate[1] and stime >= b_time1 and stime[1] < b_time1) Then
{
Tcond = true;
Xcond = false;
N1 = NetProfit;
Bcount = 0;
Scount = 0;
}
if MarketPosition(0) == 1 and MarketPosition(0) != MarketPosition(0)[1] Then
Bcount = Bcount+1;
if MarketPosition(0) == -1 and MarketPosition(0) != MarketPosition(0)[1] Then
Scount = Scount+1;
daypl = NetProfit-N1;
if TotalTrades > TotalTrades[1] Then
{
if (IsExitName("금일수익종료",1) == true or IsExitName("금일손실종료1",1) == true or
IsExitName("금일수익종료2",1) == true or IsExitName("금일손실종료3",1) == true) then
Xcond = true;
if daypl >= 당일수익 or daypl <= -당일손실 Then
Xcond = true;
}
if MarketPosition(0) != 0 and MarketPosition(0) != MarketPosition(0)[1] Then
entry = entry+1;
If b_time1<=sTime and sTime<= e_time1 Then
{
entry = 0;
stoK1 = StochasticsK(stoK_p11,stoK_p12);
stoD1 = StochasticsD(stoK_p11,stoK_p12,stoK_p13);
If stoK1>=(99)
Then
{
T1 = 1;
}
If stoK1<=(1)
Then
{
T1 = -1;
}
stoK2 = StochasticsK(stoK_p21,stoK_p22);
stoD2 = StochasticsD(stoK_p21,stoK_p22,stoK_p23);
If stoK2>=(99)
Then
{
T2 = 2;
}
If stoK2<=(1)
Then
{
T2 = -2;
}
stoK3 = StochasticsK(stoK_p31,stoK_p32);
stoD3 = StochasticsD(stoK_p31,stoK_p32,stoK_p33);
If stoK3>=(99)
Then
{
T3 = 3;
}
If stoK3<=(1)
Then
{
T3 = -3;
}
stoK4 = StochasticsK(stoK_p41,stoK_p42);
stoD4 = StochasticsD(stoK_p41,stoK_p42,stoK_p43);
If stoK4>=(99)
Then
{
T4 = 4;
}
If stoK4<=(1)
Then
{
T4 = -4;
}
}
if Bcount < 매수진입횟수 and Xcond == false and
MarketPosition == 0 and
b_time1<=sTime and sTime<= e_time1 and
T1 == 1 and T3 == 3 and Crossup(stok2,하단) Then
buy("매수",AtMarket);
if MarketPosition == 1 Then
{
Exitlong("금일수익종료2",atlimit,EntryPrice+((당일수익-daypl)/CurrentContracts));
Exitlong("금일손실종료3",AtStop,EntryPrice-((당일손실+daypl)/CurrentContracts));
if value1<value2 and T1 == -1 and T3 == -3 and T4 == -4 Then
ExitLong("추세전환(-)",AtMarket);
}
if Scount < 매도진입횟수 and Xcond == false and
MarketPosition == 0 and
b_time1<=sTime and sTime<= e_time1 and
T1 == -1 and T3 == -3 and Crossdown(stok2,상단) Then
sell("매도",AtMarket);
if MarketPosition == -1 Then
{
ExitShort("금일수익종료",atlimit,EntryPrice-((당일수익-daypl)/CurrentContracts));
ExitShort("금일손실종료1",AtStop,EntryPrice+((당일손실+daypl)/CurrentContracts));
if value1>value2 and T1 == 1 and T3 == 3 and T4 == 4 Then
ExitShort("추세전환(+)",AtMarket);
}
SetStopProfittarget(PriceScale*익절틱수,PointStop);