Skip to content

TryChangeTimeFrame Method

TryChangeTimeFrame

Summary

Changes the time frame on the chart.

Signature

1
public abstract bool TryChangeTimeFrame(TimeFrame timeFrame)

Parameters

Name Type Description
timeFrame TimeFrame The time frame to change the current chart time frame to

Return Value

bool

Declaring Type

cAlgo.API.Chart

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 using cAlgo.API;
 namespace cAlgo
 {
     // This sample indicator display's the chart data by using the current Chart object
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class ChartSample : Indicator
     {
         private Grid _grid;
         private TextBlock _mouseLocationTextBlock;
         private TextBlock _mouseWheelDeltaTextBlock;
         private TextBlock _objectsNumberTextBlock;
         protected override void Initialize()
         {
             Chart.ChartTypeChanged += args => CreateAndAddGridToChart();
             Chart.ColorsChanged += args => CreateAndAddGridToChart();
             Chart.DisplaySettingsChanged += args => CreateAndAddGridToChart();
             Chart.Drag += args => CreateAndAddGridToChart();
             Chart.DragEnd += args => CreateAndAddGridToChart();
             Chart.DragStart += args => CreateAndAddGridToChart();
             Chart.IndicatorAreaAdded += args => CreateAndAddGridToChart();
             Chart.IndicatorAreaRemoved += args => CreateAndAddGridToChart();
             Chart.MouseMove += args =>
             {
                 if (_mouseLocationTextBlock == null)
                     return;
                 _mouseLocationTextBlock.Text = string.Format("({0}, {1})", args.MouseX, args.MouseY);
             };
             Chart.MouseLeave += args =>
             {
                 if (_mouseLocationTextBlock == null)
                     return;
                 _mouseLocationTextBlock.Text = "(Null, Null)";
                 _mouseWheelDeltaTextBlock.Text = "0";
             };
             Chart.MouseWheel += args =>
             {
                 if (_mouseWheelDeltaTextBlock == null)
                     return;
                 _mouseWheelDeltaTextBlock.Text = args.Delta.ToString();
             };
             Chart.ObjectsAdded += args => _objectsNumberTextBlock.Text = Chart.Objects.Count.ToString();
             Chart.ObjectsRemoved += args => _objectsNumberTextBlock.Text = Chart.Objects.Count.ToString();
             Chart.ZoomChanged += args => CreateAndAddGridToChart();
             CreateAndAddGridToChart();
         }
         public override void Calculate(int index)
         {
         }
         private void CreateAndAddGridToChart()
         {
             if (_grid != null)
                 Chart.RemoveControl(_grid);
             _grid = new Grid(10, 2)
             {
                 BackgroundColor = Color.Gold,
                 Opacity = 0.6,
                 HorizontalAlignment = HorizontalAlignment.Left,
                 VerticalAlignment = VerticalAlignment.Bottom
             };
             var style = new Style();
             style.Set(ControlProperty.Margin, 5);
             style.Set(ControlProperty.FontWeight, FontWeight.ExtraBold);
             style.Set(ControlProperty.ForegroundColor, Color.Red);
             _grid.AddChild(new TextBlock
             {
                 Text = "Height",
                 Style = style
             }, 0, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.Height.ToString(),
                 Style = style
             }, 0, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Width",
                 Style = style
             }, 1, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.Width.ToString(),
                 Style = style
             }, 1, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Zoom Level",
                 Style = style
             }, 2, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.ZoomLevel.ToString(),
                 Style = style
             }, 2, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Objects #",
                 Style = style
             }, 3, 0);
             _objectsNumberTextBlock = new TextBlock
             {
                 Style = style,
                 Text = Chart.Objects.Count.ToString()
             };
             _grid.AddChild(_objectsNumberTextBlock, 3, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Top Y",
                 Style = style
             }, 4, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.TopY.ToString(),
                 Style = style
             }, 4, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Bottom Y",
                 Style = style
             }, 5, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.BottomY.ToString(),
                 Style = style
             }, 5, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Type",
                 Style = style
             }, 6, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.ChartType.ToString(),
                 Style = style
             }, 6, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Mouse Location",
                 Style = style
             }, 7, 0);
             _mouseLocationTextBlock = new TextBlock
             {
                 Style = style,
                 Text = "(Null, Null)"
             };
             _grid.AddChild(_mouseLocationTextBlock, 7, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Indicator Areas #",
                 Style = style
             }, 8, 0);
             _grid.AddChild(new TextBlock
             {
                 Text = Chart.IndicatorAreas.Count.ToString(),
                 Style = style
             }, 8, 1);
             _grid.AddChild(new TextBlock
             {
                 Text = "Mouse Wheel Delta",
                 Style = style
             }, 9, 0);
             _mouseWheelDeltaTextBlock = new TextBlock
             {
                 Style = style,
                 Text = "0"
             };
             _grid.AddChild(_mouseWheelDeltaTextBlock, 9, 1);
             Chart.AddControl(_grid);
         }
     }
 }

Last update: March 17, 2023