1
$\begingroup$

How can I obtain the data of the trace of a RenkoChart? Any code available?

Something like obtaining the range of dates or the middle point of the box.

$\endgroup$
1

1 Answer 1

2
$\begingroup$
data = {{{2010, 1, 4}, 130.54}, {{2010, 1, 5}, 128.96}, {{2010, 1, 6}, 128.13}, 
      {{2010, 1, 7}, 127.68} , {{2010, 1, 8}, 128.96}, {{2010, 1, 11}, 127.61}, 
      {{2010, 1, 12}, 128.63}, {{2010, 1, 13}, 128.35}, {{2010, 1, 14}, 130.4}, 
      {{2010, 1, 15}, 129.88}, {{2010, 1, 19}, 132.21}, {{2010, 1, 20}, 128.37}} ;

rc = RenkoChart[data, PerformanceGoal -> "Speed"];
pts = Cases[rc, Rectangle[a_, b_, ___] :> Mean[{a, b}], ∞]; 
Show[rc, Epilog -> {PointSize[Large], Point @ pts}]

enter image description here

Alternatively, you can extract the tooltips which contain the information on dates and values:

DeleteDuplicates @ Cases[ RenkoChart[data], Tooltip[_,  t_] :> 
 ({DateList[#], ToExpression @ #2} & @@@
  Partition[DeleteCases[StringSplit @ t[[1]], "~"],  2]), ∞]

{{{{2010, 1, 4, 0, 0, 0.}, 130.54}, {{2010, 1, 5, 0, 0, 0.}, 128.96}},
{{{2010, 1, 6, 0, 0, 0.}, 128.13}}, {{{2010, 1, 7, 0, 0, 0.}, 127.68}},
{{{2010, 1, 8, 0, 0, 0.}, 128.96}, {{2010, 1, 14, 0, 0, 0.}, 130.4}},
{{{2010, 1, 15, 0, 0, 0.}, 129.88}, {{2010, 1, 19, 0, 0, 0.}, 132.21}},
{{{2010, 1, 20, 0, 0, 0.}, 128.37}}}

$\endgroup$
8
  • $\begingroup$ Excelent answer. I was no able to do it. Thanks $\endgroup$
    – user58270
    Nov 17, 2018 at 7:17
  • $\begingroup$ If you change the PerformanceGoal -> "Speed" by a brick size or quality It is not working? why? $\endgroup$
    – user58270
    Dec 2, 2018 at 10:59
  • $\begingroup$ @roble_the reason for using PerformanceGoal -> "Speed" to prevent RenkoChart from creating Tooltips (and dynamic elements) so that post-processing the output to extract elements is easier. $\endgroup$
    – kglr
    Dec 3, 2018 at 7:07
  • $\begingroup$ Thanks for your comments and help. But if I want the pair {middle date, midle point} of ^SP500 index. I can not do it. The first code give me the midle data but the second give a dates that not correspond. How Will be the code for the ^SP500 index that prodeuce pairs of mean of (date, data) of each renko box ? $\endgroup$
    – user58270
    Dec 8, 2018 at 20:30
  • $\begingroup$ DeleteDuplicates@ Cases[RenkoChart["^SP500"], Tooltip[, t] :> ({DateList[#], ToExpression@#2} & @@@ Partition[DeleteCases[StringSplit@t[[1]], "~"], 2]), [Infinity]] produces 23 points $\endgroup$
    – user58270
    Dec 8, 2018 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.