I am making a very basic stock simulation. I want ListLinePlot
to color my stock viewer based on whether the price went up or down from the previous price. Here is what I have:
RemoveScheduledTask[ScheduledTasks[]];
price = 100;
time = 0;
nextPrice := price += 2Random[]-1;
nextTime := time += Random[];
data = Table[{nextTime, nextPrice},{i,1,1000}];
Dynamic@ListLinePlot[
data,
ImageSize->1000,
PlotRange->{{time-525,time+25}},
ColorFunction->Function[If[Last@data[[-2]]<Last@data[[-1]], Green, Red]]
]
RunScheduledTask[
data = Rest[data];
AppendTo[data,{nextTime,nextPrice}];,
.1
];
Currently this code makes the graph all one color (not what I want). Does anyone know how to implement the functionality that I want? Also any general code improvements are very welcome (I feel like the way I am pushing/popping data
is inefficient).
TradingChart
andInteractiveTradingChart
? See the documentation. I can never bring myself to explore them further (just can't come up with any use for them), but they look close to what you want. $\endgroup$Accumulate[]
. $\endgroup$Accumulate
because I don't want to store all the data at once. Or perhaps I am misunderstanding how you think I should use it? $\endgroup$