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$
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$
  • $\begingroup$ Excelent answer. I was no able to do it. Thanks $\endgroup$ – roble_t Nov 17 '18 at 7:17
  • $\begingroup$ If you change the PerformanceGoal -> "Speed" by a brick size or quality It is not working? why? $\endgroup$ – roble_t Dec 2 '18 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 '18 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$ – roble_t Dec 8 '18 at 20:30
  • $\begingroup$ DeleteDuplicates@ Cases[RenkoChart["^SP500"], Tooltip[, t] :> ({DateList[#], ToExpression@#2} & @@@ Partition[DeleteCases[StringSplit@t[[1]], "~"], 2]), [Infinity]] produces 23 points $\endgroup$ – roble_t Dec 8 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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