답변완료
종목검색 잘부탁드립니다
1,아래 지표로 종목검색 부탁드립니다2,시장구분 변수 처리부탁3, 매수 상위 종목 중에서 100개중에서 검색 할려고 합니다 변수처리 해주세요4, bull reversal 이 신호종목 부탁립니다input : uselow_bull(true); input : usehigh_bear(true); input : line_forward(8); input : line_back(-200); input : label_offset(8); var : use_low_bull(0),use_high_bear(0); var : bull_dir(False),bear_dir(False),red_bar(false),green_bar(False); var : strong_bull_dir(False),strong_bear_dir(False),nuetral_bar(False); var : line_price(naN),label_price(NaN); var : is_bar_index(0),a(0),b(0),price(0); var : bull_break(False),bear_break(False); var : confirmed_bull_(False),bull_value(0); var : confirmed_bear_(False),bear_value(0); use_low_bull = IFf(uselow_bull,low,close); use_high_bear = IFF(usehigh_bear,high,close); bull_dir = close >= open[1]; bear_dir = close <= open[1]; red_bar = open < close; green_bar = open > close; strong_bull_dir = bull_dir and red_bar; strong_bear_dir = bear_dir and red_bar; nuetral_bar = strong_bear_dir == False and strong_bull_dir == False; is_bar_index = index; if is_bar_index>0 Then { TL_Delete(line_price); Text_Delete(label_price); a = close; b = is_bar_index; line_price = TL_new(sDate,sTime,a,NextBarSdate,NextBarStime,a); TL_SetColor(line_price, IFf(strong_bull_dir , red ,IFf(strong_bear_dir , lime , IFf(nuetral_bar , orange, Black)))); TL_SetExtRight(line_price,true); TL_SetExtLeft(line_price,true); label_price = Text_new(NextBarSdate,NextBarStime,a, ntostr(a,2)); Text_SetColor(label_price,iFf(strong_bull_dir , red ,IFf(strong_bear_dir , lime , IFf(nuetral_bar , orange, Black)))); Text_SetSize(label_price,20); } //================= //BEGIN Definitions //================= price = close; bull_break = price > high[1] and price > high[2] and price > high[3] and price > high[4] and price > high[5] and price > high[6] and price > high[7] and price > high[8] and price > high[9] and price > high[10] and price > high[11] and price > high[12] and price > high[13] and price > high[14]; // confirmed_bull_ = bull_break[1] and bull_break == False; if confirmed_bull_ == true Then bull_value = high; if bull_break == bull_break[1] Then plot1(bull_value,"bull_value",iff(bull_break != bull_break[1],Black ,red)); Else NoPlot(1); bear_break = price < low[1] and price < low[2] and price < low[3] and price < low[4] and price < low[5] and price < low[6] and price < low[7] and price < low[8] and price < low[9] and price < low[10] and price < low[11] and price < low[11] and price < low[12] and price < low[13] and price < low[14]; // confirmed_bear_ = bear_break[1] and bear_break == False; if confirmed_bear_ == true Then bear_value = low; if bear_break == bear_break[1] Then plot2(bear_value,"bear_value",iff(bear_break != bear_break[1],Black,green)); Else NoPlot(2); input : rsiLen(6); input : rsiOverbought(85); input : rsiOversold(15); var : rsiValue(0),rsiisoverbt(False),rsiisoversld(False); var : bear_signal(False),bull_signal(False); var : bulllabel1(Nan),bulllabel2(nan),bullline(NaN); var : bearlabel1(Nan),bearlabel2(nan),bearline(NaN); rsiValue = rsi(rsiLen); rsiisoverbt = rsiValue >= rsiOverbought; rsiisoversld = rsiValue <= rsiOversold; bear_signal = (bear_break[1] and bear_break == False); bull_signal = (bull_break[1] and bull_break == False); if bull_signal Then { Text_Delete(bulllabel1); bulllabel1 = Text_New(sDate,sTime,H,"Potential bear Reversal"+NewLine+NewLine); Text_SetColor(bulllabel1,Green); Text_SetStyle(bulllabel1,2,1); Text_Delete(bulllabel2); bulllabel2 = Text_New(sDate,sTime,H,"▼"); Text_SetColor(bulllabel2,Green); Text_SetStyle(bulllabel2,2,1); Text_SetSize(bulllabel2,20); } if bull_break Then { TL_Delete(bullline); bullline = TL_new(sDate,sTime,use_high_bear,NextBarSdate,NextBarStime,use_high_bear); TL_SetExtRight(bullline,true); TL_SetColor(bullline,Red); } if bear_signal then { Text_Delete(bearlabel1); bearlabel1 = text_new(sDate,sTime,L,"▲"); Text_SetColor(bearlabel1,Red); Text_SetStyle(bearlabel1,2,0); Text_SetSize(bearlabel1,20); Text_Delete(bearlabel2); bearlabel2 = text_new(sDate,sTime,L,NewLine+NewLine+"Potential bull Reversal"); Text_SetColor(bearlabel2,Red); Text_SetStyle(bearlabel2,2,0); } if bear_break Then { TL_Delete(bearline); bearline = TL_new(sDate,sTime,use_low_bull,NextBarSdate,NextBarStime,use_low_bull); TL_SetExtRight(bearline,true); TL_SetColor(bearline,green); } var : Sell_signal(False),Buy_signal(False); var : bull_function(False),bear_function(False),custom_signal(False); Sell_Signal = bull_signal; Buy_Signal = bear_signal; bull_function = Buy_Signal; bear_function = Sell_Signal; custom_signal = (bull_function or bear_function); //END CUSTOM FUNCTIONS==== // Plot BUY SELL markers input : show_sell_signals(false); input : show_buy_signals(false); var : tx1(0),tx2(0); if show_sell_signals == true and Sell_Signal == true Then { tx1 = text_new(sDate,sTime,H,"▼"); Text_SetColor(tx1,Red); Text_SetStyle(tx1,2,1); tx2 = text_new(sDate,sTime,H,"O-B"+NewLine); Text_SetColor(tx2,Yellow); Text_SetStyle(tx2,2,1); } if show_buy_signals == true and Buy_Signal == true Then { tx1 = text_new(sDate,sTime,L,"▲"); Text_SetColor(tx1,Lime); Text_SetStyle(tx1,2,0); tx2 = text_new(sDate,sTime,L,NewLine+"O-S"); Text_SetColor(tx2,Yellow); Text_SetStyle(tx2,2,0); }
답변완료
일봉전략을 5분봉전략으로의 변환 코드 검토 부탁 드립니다. (수정)
얼마 전 올렸던 질문(글번호: 194570) 관련 추가질문입니다.아래와 같이 코드를 변경했는데, 이게 맞나 싶네요... 결과가 너무 달라요.그리고, 날짜변경시 Daily~로 시작되는 변수들을 업데이트 하도록 했는데,한국투자증권 나스닥 선물 시간상 한국자정에 날짜가 바뀌는 거 같은데미국시장 기준으로 바꾸도록 하려면 어떻게 하나요?검토 좀 부탁 드립니다.늘 감사 드립니다.============= 원본코드 =============// --- 원본 전략 로직 시작 (문법 수정 적용) ---PcntChange = Close / DayClose(PChng) * 100;If PcntChange < 100 - OverRange then Begin OS = TRUE; HighBand = Highest( High , Bands ); End;If PcntChange > 100 + OverRange then Begin OB = TRUE; LowBand = Lowest( Low, Bands); End;if EntriesToday(sDate) < 1 and NoContract > 0 and TradeAllowed then { If OS and MarketPosition <> 1 Then Buy("B", AtStop, HighBand, NoContract); If OB and MarketPosition <> -1 then Sell("S", AtStop, LowBand, NoContract);}If marketposition == 1 and C > entryprice + profit then ExitLong("LX_Profit", AtMarket);if marketposition == -1 and C < entryprice - profit then ExitShort("SX_Profit", AtMarket);if MRO( OS == false, MRO_Length, MRO_Threshold ) == -1 then OS = false;if MRO( OB == false, MRO_Length, MRO_Threshold ) == -1 then OB = false;ExitLong("EL_Trail", AtStop, lowest(low,exitperiod));ExitShort("ES_Trail", AtStop, highest(high,exitperiod));SetStopLoss(stopPer, PercentStop);// --- 원본 전략 로직 종료 ---============= 수정코드 =============Array: DailyReturns[100](0), DailyOpenArray[100](0), DailyHighArray[100](0), DailyLowArray[100](0), DailyCloseArray[100](0);// ================== 로직 시작 ==================// 1. 5분봉을 일봉으로 집계CurrentDate = sDate;if Index == 0 then begin PrevDate = CurrentDate; DailyOpen = Open; DailyHigh = High; DailyLow = Low; DailyBarCount = 0;end// 날짜가 바뀌었을 때 (새로운 거래일 시작)if CurrentDate != PrevDate then begin // 전일 일봉 데이터를 배열에 저장 For Value1 = 99 DownTo 1 begin DailyOpenArray[Value1] = DailyOpenArray[Value1-1]; DailyHighArray[Value1] = DailyHighArray[Value1-1]; DailyLowArray[Value1] = DailyLowArray[Value1-1]; DailyCloseArray[Value1] = DailyCloseArray[Value1-1]; end; DailyOpenArray[0] = PrevDailyOpen; DailyHighArray[0] = PrevDailyHigh; DailyLowArray[0] = PrevDailyLow; DailyCloseArray[0] = PrevDailyClose; // 새로운 일봉 시작 DailyOpen = Open; DailyHigh = High; DailyLow = Low; DailyBarCount = DailyBarCount + 1; PrevDate = CurrentDate;end// 같은 날 내에서 고가/저가 업데이트if High > DailyHigh then DailyHigh = High;if Low < DailyLow then DailyLow = Low;DailyClose = Close;// 이전 일봉 데이터 저장PrevDailyOpen = DailyOpen;PrevDailyHigh = DailyHigh;PrevDailyLow = DailyLow;PrevDailyClose = DailyClose;.......... 생략 ..........if CurrentDate != PrevDate and DailyBarCount > 1 then begin if DailyOpenArray[1] > 0 then DailyReturn = (DailyOpenArray[0] - DailyOpenArray[1]) / DailyOpenArray[1] else DailyReturn = 0; For Value1 = VaR_Period - 1 DownTo 1 begin DailyReturns[Value1] = DailyReturns[Value1-1]; end; DailyReturns[0] = DailyReturn;end.......... 생략 ..........// 5. 원본 전략 로직 (일봉 기준 계산)if DailyBarCount >= Pchng and DailyCloseArray[Pchng-1] > 0 then PcntChange = DailyClose / DailyCloseArray[Pchng-1] * 100else PcntChange = 100;If PcntChange < 100 - OverRange then begin OS = true; // 최근 Bands개 일봉의 최고가 HighBand = DailyHighArray[0]; For Value1 = 1 to Bands-1 begin if DailyHighArray[Value1] > HighBand then HighBand = DailyHighArray[Value1]; end;endelse OS = false;If PcntChange > 100 + OverRange then begin OB = true; // 최근 Bands개 일봉의 최저가 LowBand = DailyLowArray[0]; For Value1 = 1 to Bands-1 begin if DailyLowArray[Value1] < LowBand then LowBand = DailyLowArray[Value1]; end;endelse OB = false;// 6. 주문 실행 (5분봉에서 즉시 실행)if EntriesToday(sDate) < 1 and NoContract > 0 and TradeAllowed then begin If OS and MarketPosition <> 1 then Buy("B", AtStop, HighBand, NoContract); If OB and MarketPosition <> -1 then Sell("S", AtStop, LowBand, NoContract);endIf MarketPosition == 1 and C > EntryPrice + profit then ExitLong("LX_Profit", AtMarket);if MarketPosition == -1 and C < EntryPrice - profit then ExitShort("SX_Profit", AtMarket);if MRO(OS == false, MRO_Length, MRO_Threshold) == -1 then OS = false;if MRO(OB == false, MRO_Length, MRO_Threshold) == -1 then OB = false;// exitperiod도 일봉 기준으로 계산Var: ExitLowBand(99999), ExitHighBand(0);ExitLowBand = DailyLowArray[0];ExitHighBand = DailyHighArray[0];For Value1 = 1 to exitperiod-1 begin if DailyLowArray[Value1] < ExitLowBand then ExitLowBand = DailyLowArray[Value1]; if DailyHighArray[Value1] > ExitHighBand then ExitHighBand = DailyHighArray[Value1];end;ExitLong("EL_Trail", AtStop, ExitLowBand);ExitShort("ES_Trail", AtStop, ExitHighBand);SetStopLoss(stopPer, PercentStop);