2014-07-09 3 views
1

편집 : 원하는 경우 작은 예제를 조작하여 재현 할 수 있습니다.XTS를 사용하는 chartSeries에서 점과 기술 지표를 동시에 그릴 수 없습니다.

은 내가

> theBars 
        Open High Low Close 
2014-06-17 01:42:26 13835 13836 13835 13836 
2014-06-17 01:42:59 13836 13838 13835 13837 
2014-06-17 01:43:21 13837 13838 13837 13837 
2014-06-17 01:43:51 13837 13837 13837 13837 
2014-06-17 01:44:23 13837 13837 13837 13837 
2014-06-17 01:44:51 13837 13838 13837 13838 
2014-06-17 01:45:28 13837 13840 13837 13840 
2014-06-17 01:45:59 13840 13842 13840 13842 
2014-06-17 01:46:22 13842 13843 13842 13843 
2014-06-17 01:46:58 13843 13844 13843 13844 
2014-06-17 01:47:29 13843 13844 13843 13843 
2014-06-17 01:47:58 13843 13843 13841 13843 
2014-06-17 01:48:22 13843 13843 13842 13843 
2014-06-17 01:48:59 13843 13843 13842 13842 
2014-06-17 01:49:05 13842 13842 13841 13841 
2014-06-17 01:49:54 13841 13841 13840 13841 
2014-06-17 01:50:18 13841 13841 13841 13841 
2014-06-17 01:50:44 13840 13840 13839 13840 
2014-06-17 01:52:55 13839 13839 13838 13839 
2014-06-17 01:53:42 13838 13839 13838 13838 
2014-06-17 01:54:22 13837 13838 13837 13838 
2014-06-17 01:54:58 13837 13838 13836 13837 
2014-06-17 01:55:29 13836 13836 13834 13835 
2014-06-17 01:55:59 13835 13837 13835 13837 
2014-06-17 01:56:28 13837 13839 13837 13838 
2014-06-17 01:56:59 13838 13838 13837 13837 
2014-06-17 01:57:29 13837 13838 13837 13838 
2014-06-17 01:57:59 13838 13838 13838 13838 
2014-06-17 01:58:29 13838 13838 13836 13837 
2014-06-17 01:58:58 13837 13837 13836 13836 
2014-06-17 01:59:29 13836 13841 13836 13840 
2014-06-17 01:59:59 13840 13840 13835 13837 
2014-06-17 02:00:29 13837 13837 13836 13836 
2014-06-17 02:00:58 13836 13836 13835 13836 
2014-06-17 02:01:29 13835 13837 13835 13837 
2014-06-17 02:01:58 13837 13837 13836 13836 

(유로/$의)를 사용 해요 OHLC XTS 테이블이 내가 의도 한대로 작동

points.default(x=timeIndex*tMult+1, #aligns with tMult = 3 when candles are candles, 1 when they are matchsticks 
        y=as.numeric(dataCol[i]), #the price, its around 13818 
        cex=dotSize, 
        pch=dotType, 
        col=thecolor) 

로에 포인트를하려하고 있습니다. 이 예에서, 여기에 값은

 x  y  cex  pch  col 
    "19" "13841"  "2"  "2" "green" 
     x   y  cex  pch  col 
    "19" "13841"  "3"  "2" "#7070FF" 
     x   y  cex  pch  col 
    "19" "13841"  "4"  "2" "#7070FF" 

나는 또한

와 함께 몇 가지 기술적 지표를 그래프있어 (각 지점의 중심은 동시에 하나 개의 가격에 여러 거래 때문에 동일)
plot(addMACD(fast,slow,signal,maType,histogram)) 

그냥 기본값을 사용하여 의도 한대로도 작동
plot(addSMA(n,overlay = overlay)) 

등.

bbands 및 SMA와 같은 그래프에 기술을 오버레이하는 기술을 사용하면 포인트를 동시에 그래프로 표시 할 수 있습니다. 그러나 동일한 플롯 윈도우에서 그래프를 두 그래프로 분리하는 별도의 상자에있는 MACD와 같은 플롯이있는 경우 더 이상 점을 그릴 수 없습니다. 왜?!

+0

같은 데이터 열 dataCol에 포인트를 플롯. 그것은 단순히 적은 수의 사람들이 당신을 도우려는 경향이 있음을 의미합니다. –

+0

예, 포함하지 않으면 댓글을 달았습니다. – hedgedandlevered

+0

예를 포함하도록 수정했습니다. – hedgedandlevered

답변

0

y 축은 추가 된 표시기에 따라 다시 색인됩니다. 직접 색인을 다시 생성 한 다음 지점을 조정하여 그래프를 그려 보는 것이 좋습니다. 나는 그 수색을 통해 찾은 모든 상수들을 여기에 포함시킬 것이다.

, 데이터가 "theBars"라는 변수에 OHLC에 내가 1920x1200의 해상도의 모니터에이 모든 짓이 par(usr=c(0,1,min(theBars),max(theBars)),xpd=TRUE)

, 픽셀 측정 그래서 모두가 그 측면에 않습니다 가정. 이는 par("fin") 을 사용하여 모든 해상도와 호환됩니다. 또한이 작업은 몇 분의 1 초 내에 실행됩니다. 이것은 속도가 아닌 명확성을 위해 작성되었습니다.

에서

수평 방향의 배치 [0,1] 다양한 촛불 번호 : 지표의 수는 이미 그려되고 plotNum

if(numBars < 10) stop("cannot plot less than 10 candles") 
    horizNumerator <- if(numBars == 10) 1547 else 
         if(numBars == 11) 1559 else 
         if(numBars == 12) 1568 else 
         if(numBars == 13) 1574 else 
         if(numBars == 14) 1581 else 
         if(numBars == 15) 1588 else 
         if(numBars == 16) 1592 else 
         if(numBars == 17) 1597 else 
         if(numBars == 18) 1601 else 
         if(numBars == 19) 1603 else 
         if(numBars == 20) 1606 else 
         if(numBars <= 30) 1626 + (numBars-30)/(10/20) else 
         if(numBars <= 40) 1636 + (numBars-40)/(10/10) else 
         if(numBars <= 50) 1641 + (numBars-50)/(10/7) else 
         if(numBars <= 60) 1646 + (numBars-60)/(10/5) else 
         if(numBars <= 100) 1651 + (numBars-100)/(40/5) else 
         if(numBars <= 140) 1655 + (numBars-140)/(40/4) else 
         if(numBars <= 312) 1658 + (numBars-312)/(172/3) else 
         if(numBars > 312) 1662 



    horizUnit <- (horizNumerator/1802)/(length(theBars[,1])-1)*ifelse(plotNum<2,1,1693/1655)*par("fin")[1]/20 
    startHoriz <- ifelse(plotNum<2,55/1802,35/1802)*par("fin")[1]/20 

수직 정렬 및 deltaP <- max(theBars)-min(theBars) : 지표가 첨벙 첨벙와

이 거래 작의 영역

pixelStretch <- (switch(as.character(plotNum),"0"=975,"1"=665,"2"=551,"3"=465, "4"=400,"5"=352,"6"= 313))/(983) 
deltaP <- max(theBars)-min(theBars) 

표시 자

maxRaise <- if(plotNum == 0) 0 else 
       if(plotNum == 1) 15 else 
       if(plotNum == 2) 31 else 
       if(plotNum > 2) 36 
    maxRaise <- maxRaise*par("fin")[2]/12.0625/983 

를 꾸몄다 다음 재현 예제를 포함하지 않는 우리에게 사과 할 필요가 없습니다이

points.default(x=startHoriz + horizUnit*timeIndex, 
       y= maxRaise * deltaP + max(theBars)-((max(theBars)-as.numeric(dataCol[i]))*(pixelStretch)), 
       cex=dotSize, 
       pch=dotType, 
       col=thecolor)