Skip to content

Commit 7ce846f

Browse files
committed
Finish candlestick chart
1 parent 4f8f45c commit 7ce846f

File tree

5 files changed

+173
-176
lines changed

5 files changed

+173
-176
lines changed

docs/07_1_candlestick.fsx

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ is a group of high, open, close and low values over a period of time, e.g. 1 min
6060
The x-axis is usually dateime values and y is a sequence of candle structures.
6161
*)
6262

63-
let candles1 = Chart.Candlestick candles
63+
open Plotly.NET
64+
open Plotly.NET.TraceObjects
65+
66+
let candles1 =
67+
Chart.Candlestick(
68+
openData |> Seq.take 30,
69+
highData |> Seq.take 30,
70+
lowData |> Seq.take 30,
71+
closeData |> Seq.take 30,
72+
dateData |> Seq.take 30
73+
)
6474

6575
(*** condition: ipynb ***)
6676
#if IPYNB
@@ -72,23 +82,44 @@ candles1 |> GenericChart.toChartHTML
7282
(***include-it-raw***)
7383

7484
(**
75-
If you want to hide the rangeslider, use `withXAxisRangeSlider` and hide it:
85+
## Changing the increasing/decresing colors
7686
*)
7787

88+
let candles2 =
89+
Chart.Candlestick(
90+
candles,
91+
IncreasingColor = Color.fromKeyword Cyan,
92+
DecreasingColor = Color.fromKeyword Gray
93+
)
94+
95+
(*** condition: ipynb ***)
96+
#if IPYNB
97+
candles2
98+
#endif // IPYNB
99+
100+
(***hide***)
101+
candles2 |> GenericChart.toChartHTML
102+
(***include-it-raw***)
103+
104+
(**
105+
## Removing the rangeslider
106+
107+
If you want to hide the rangeslider, use `withXAxisRangeSlider` and hide it:
108+
*)
78109
open Plotly.NET.LayoutObjects
79110

80111
let rangeslider = RangeSlider.init(Visible=false)
81112

82-
let candles2 =
83-
Chart.Candlestick candles
113+
let candles3 =
114+
candles2
84115
|> Chart.withXAxisRangeSlider rangeslider
85116

86117
(*** condition: ipynb ***)
87118
#if IPYNB
88-
candles2
119+
candles3
89120
#endif // IPYNB
90121

91122
(***hide***)
92-
candles2 |> GenericChart.toChartHTML
123+
candles3 |> GenericChart.toChartHTML
93124
(***include-it-raw***)
94125

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 58 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,26 +2523,6 @@ module Chart2D =
25232523
|> GenericChart.ofTraceObject useDefaults
25242524

25252525
/// Creates an OHLC (open-high-low-close) chart. OHLC charts are typically used to illustrate movements in the price of a financial instrument over time.
2526-
///
2527-
/// ``open`` : Sets the open values.
2528-
///
2529-
/// high : Sets the high values.
2530-
///
2531-
/// low : Sets the low values.
2532-
///
2533-
/// close : Sets the close values.
2534-
///
2535-
/// x : Sets the x coordinates. If absent, linear coordinate will be generated.
2536-
///
2537-
/// ?Increasing : Sets the Line style of the Increasing part of the chart
2538-
///
2539-
/// ?Decreasing : Sets the Line style of the Decreasing part of the chart
2540-
///
2541-
/// ?Line : Sets the Line style of both the Decreasing and Increasing part of the chart
2542-
///
2543-
/// ?Tickwidth : Sets the width of the open/close tick marks relative to the "x" minimal interval.
2544-
///
2545-
/// ?XCalendar : Sets the calendar system to use with `x` date data.
25462526
[<Extension>]
25472527
static member OHLC
25482528
(
@@ -2590,18 +2570,6 @@ module Chart2D =
25902570
|> GenericChart.ofTraceObject useDefaults
25912571

25922572
/// Creates an OHLC (open-high-low-close) chart. OHLC charts are typically used to illustrate movements in the price of a financial instrument over time.
2593-
///
2594-
/// stockTimeSeries : tuple list of time * stock (OHLC) data
2595-
///
2596-
/// ?Increasing : Sets the Line style of the Increasing part of the chart
2597-
///
2598-
/// ?Decreasing : Sets the Line style of the Decreasing part of the chart
2599-
///
2600-
/// ?Line : Sets the Line style of both the Decreasing and Increasing part of the chart
2601-
///
2602-
/// ?Tickwidth : Sets the width of the open/close tick marks relative to the "x" minimal interval.
2603-
///
2604-
/// ?XCalendar : Sets the calendar system to use with `x` date data.
26052573
[<Extension>]
26062574
static member OHLC
26072575
(
@@ -2647,102 +2615,91 @@ module Chart2D =
26472615
/// Creates a candlestick chart. A candlestick cart is a style of financial chart used to describe price movements of a
26482616
/// security, derivative, or currency. Each "candlestick" typically shows one day, thus a one-month chart may show the 20
26492617
/// trading days as 20 candlesticks. Candlestick charts can also be built using intervals shorter or longer than one day.
2650-
///
2651-
/// ``open`` : Sets the open values.
2652-
///
2653-
/// high : Sets the high values.
2654-
///
2655-
/// low : Sets the low values.
2656-
///
2657-
/// close : Sets the close values.
2658-
///
2659-
/// x : Sets the x coordinates. If absent, linear coordinate will be generated.
2660-
///
2661-
/// ?Increasing : Sets the Line style of the Increasing part of the chart
2662-
///
2663-
/// ?Decreasing : Sets the Line style of the Decreasing part of the chart
2664-
///
2665-
/// ?Line : Sets the Line style of both the Decreasing and Increasing part of the chart
2666-
///
2667-
/// ?WhiskerWidth : Sets the width of the whiskers relative to the box' width. For example, with 1, the whiskers are as wide as the box(es).
2668-
///
2669-
/// ?XCalendar : Sets the calendar system to use with `x` date data.
2670-
[<Extension>]
26712618
static member Candlestick
26722619
(
26732620
``open`` : #IConvertible seq,
26742621
high : #IConvertible seq,
26752622
low : #IConvertible seq,
26762623
close : #IConvertible seq,
26772624
x : #IConvertible seq,
2678-
[<Optional;DefaultParameterValue(null)>]?Increasing : Line,
2679-
[<Optional;DefaultParameterValue(null)>]?Decreasing : Line,
2680-
[<Optional;DefaultParameterValue(null)>]?WhiskerWidth : float,
2681-
[<Optional;DefaultParameterValue(null)>]?Line : Line,
2682-
[<Optional;DefaultParameterValue(null)>]?XCalendar : StyleParam.Calendar,
2683-
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
2625+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
2626+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
2627+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
2628+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
2629+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
2630+
[<Optional;DefaultParameterValue(null)>] ?Line : Line,
2631+
[<Optional;DefaultParameterValue(null)>] ?IncreasingColor : Color,
2632+
[<Optional;DefaultParameterValue(null)>] ?Increasing : FinanceMarker,
2633+
[<Optional;DefaultParameterValue(null)>] ?DecreasingColor : Color,
2634+
[<Optional;DefaultParameterValue(null)>] ?Decreasing : FinanceMarker,
2635+
[<Optional;DefaultParameterValue(null)>] ?WhiskerWidth : float,
2636+
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
26842637
) =
26852638

26862639
let useDefaults = defaultArg UseDefaults true
2640+
let increasing = Increasing |> Option.defaultValue (FinanceMarker.init()) |> FinanceMarker.style(?LineColor = IncreasingColor)
2641+
let decreasing = Decreasing |> Option.defaultValue (FinanceMarker.init()) |> FinanceMarker.style(?LineColor = DecreasingColor)
26872642

26882643
Trace2D.initCandlestick(
26892644
Trace2DStyle.Candlestick(
2690-
``open`` = ``open`` ,
2691-
high = high ,
2692-
low = low ,
2693-
close = close ,
2694-
x = x ,
2695-
?Increasing = Increasing ,
2696-
?Decreasing = Decreasing ,
2697-
?WhiskerWidth = WhiskerWidth,
2698-
?Line = Line ,
2699-
?XCalendar = XCalendar
2645+
Open = ``open``,
2646+
High = high,
2647+
Low = low,
2648+
Close = close,
2649+
X = x,
2650+
?Name = Name ,
2651+
?ShowLegend = ShowLegend,
2652+
?Opacity = Opacity ,
2653+
?Text = Text ,
2654+
?MultiText = MultiText ,
2655+
?Line = Line ,
2656+
Increasing = increasing,
2657+
Decreasing = decreasing,
2658+
?WhiskerWidth = WhiskerWidth
27002659
)
27012660
)
27022661
|> GenericChart.ofTraceObject useDefaults
27032662

27042663
/// Creates an OHLC (open-high-low-close) chart. OHLC charts are typically used to illustrate movements in the price of a financial instrument over time.
2705-
///
2706-
/// stockTimeSeries : tuple list of time * stock (OHLC) data
2707-
///
2708-
/// ?Increasing : Sets the Line style of the Increasing part of the chart
2709-
///
2710-
/// ?Decreasing : Sets the Line style of the Decreasing part of the chart
2711-
///
2712-
/// ?Line : Sets the Line style of both the Decreasing and Increasing part of the chart
2713-
///
2714-
/// ?Tickwidth : Sets the width of the open/close tick marks relative to the "x" minimal interval.
2715-
///
2716-
/// ?XCalendar : Sets the calendar system to use with `x` date data.
27172664
[<Extension>]
27182665
static member Candlestick
27192666
(
27202667
stockTimeSeries: seq<System.DateTime*StockData>,
2721-
[<Optional;DefaultParameterValue(null)>]?Increasing : Line,
2722-
[<Optional;DefaultParameterValue(null)>]?Decreasing : Line,
2723-
[<Optional;DefaultParameterValue(null)>]?WhiskerWidth : float,
2724-
[<Optional;DefaultParameterValue(null)>]?Line : Line,
2725-
[<Optional;DefaultParameterValue(null)>]?XCalendar : StyleParam.Calendar,
2726-
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
2668+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
2669+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
2670+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
2671+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
2672+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
2673+
[<Optional;DefaultParameterValue(null)>] ?Line : Line,
2674+
[<Optional;DefaultParameterValue(null)>] ?IncreasingColor : Color,
2675+
[<Optional;DefaultParameterValue(null)>] ?Increasing : FinanceMarker,
2676+
[<Optional;DefaultParameterValue(null)>] ?DecreasingColor : Color,
2677+
[<Optional;DefaultParameterValue(null)>] ?Decreasing : FinanceMarker,
2678+
[<Optional;DefaultParameterValue(null)>] ?WhiskerWidth : float,
2679+
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
27272680
) =
27282681

27292682
let useDefaults = defaultArg UseDefaults true
27302683

2731-
Trace2D.initCandlestick(
2732-
Trace2DStyle.Candlestick(
2733-
``open`` = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.Open))) ,
2734-
high = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.High))) ,
2735-
low = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.Low))) ,
2736-
close = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.Close))) ,
2737-
x = (stockTimeSeries |> Seq.map fst) ,
2738-
?Increasing = Increasing ,
2739-
?Decreasing = Decreasing ,
2740-
?WhiskerWidth = WhiskerWidth,
2741-
?Line = Line ,
2742-
?XCalendar = XCalendar
2743-
)
2684+
Chart.Candlestick(
2685+
``open`` = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.Open))) ,
2686+
high = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.High))) ,
2687+
low = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.Low))) ,
2688+
close = (stockTimeSeries |> Seq.map (snd >> (fun x -> x.Close))) ,
2689+
x = (stockTimeSeries |> Seq.map fst),
2690+
?Name = Name ,
2691+
?ShowLegend = ShowLegend ,
2692+
?Opacity = Opacity ,
2693+
?Text = Text ,
2694+
?MultiText = MultiText ,
2695+
?Line = Line ,
2696+
?IncreasingColor= IncreasingColor,
2697+
?Increasing = Increasing ,
2698+
?DecreasingColor= DecreasingColor,
2699+
?Decreasing = Decreasing ,
2700+
?WhiskerWidth = WhiskerWidth ,
2701+
?UseDefaults = UseDefaults
27442702
)
2745-
|> GenericChart.ofTraceObject useDefaults
27462703

27472704

27482705

src/Plotly.NET/Playground.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ let lowData : seq<float> = data.["AAPL.Low"] |> Series.values
192192
let closeData : seq<float> = data.["AAPL.Close"] |> Series.values
193193
let dateData = data |> Frame.getCol "Date" |> Series.values |> Seq.map System.DateTime.Parse
194194

195-
Chart.OHLC(
195+
Chart.Candlestick(
196196
openData |> Seq.take 30,
197197
highData |> Seq.take 30,
198198
lowData |> Seq.take 30,
@@ -201,7 +201,7 @@ Chart.OHLC(
201201
)
202202
|> Chart.show
203203

204-
Chart.OHLC(
204+
Chart.Candlestick(
205205
openData,
206206
highData,
207207
lowData,

0 commit comments

Comments
 (0)