Click here to Skip to main content
15,845,469 members
Home / Discussions / C#
   

C#

 
GeneralRe: Converting string into non-string Form.Object types for passing to methods or updating non-string object.Property with strings Pin
Gerry Schmitz29-Nov-23 6:25
mveGerry Schmitz29-Nov-23 6:25 
QuestionQuestion Pin
Mo Fouad25-Nov-23 22:35
Mo Fouad25-Nov-23 22:35 
AnswerRe: Question Pin
Richard MacCutchan25-Nov-23 23:11
mveRichard MacCutchan25-Nov-23 23:11 
AnswerRe: Question Pin
Dave Kreskowiak26-Nov-23 5:42
mveDave Kreskowiak26-Nov-23 5:42 
GeneralRe: Question Pin
Richard Andrew x6426-Nov-23 7:28
professionalRichard Andrew x6426-Nov-23 7:28 
AnswerRe: Question Pin
Gerry Schmitz26-Nov-23 10:36
mveGerry Schmitz26-Nov-23 10:36 
GeneralRe: Question Pin
jschell27-Nov-23 7:17
jschell27-Nov-23 7:17 
QuestionC# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202324-Nov-23 21:45
j k Nov202324-Nov-23 21:45 
C#
  1  namespace ATAS.Indicators.Technical;
  2  
  3  using ATAS.Indicators.Drawing;
  4  using OFT.Localization;
  5  using OFT.Rendering.Context;
  6  using OFT.Rendering.Settings;
  7  using OFT.Rendering.Tools;
  8  using System;
  9  using System.ComponentModel;
 10  using System.ComponentModel.DataAnnotations;
 11  using System.Drawing;
 12  using System.Runtime.Intrinsics.X86;
 13  using Color = System.Drawing.Color;
 14  
 15  [DisplayName("Candle  X")]
 16  public class CandleStatist : Indicator
 17  {
 18      #region Nested types
 19  
 20      public enum LabelLocations
 21      {
 22          [Display(ResourceType = typeof(Strings), Name = nameof(Strings.AboveCandle))] 
 23          Top,
 24  
 25          [Display(ResourceType = typeof(Strings), Name = nameof(Strings.BelowCandle))]
 26          Bottom,
 27  
 28          [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ByCandleDirection))]
 29          CandleDirection
 30      }
 31  
 32      #endregion
 33  
 34      #region Fields
 35  
 36      private readonly PenSettings _bgPen = new() { Color = DefaultColors.Gray.Convert() };
 37      private readonly BrushSettings _bgBrush = new();
 38      private readonly RenderStringFormat _format = new()
 39      
 40  
 41      {
 42          Alignment = StringAlignment.Center,
 43          LineAlignment = StringAlignment.Center,
 44      };
 45      private int _backGroundTransparency = 8;
 46  
 47  
 48     
 49      const   int     X = 100;
 50      public  double  uhv;
 51      private double  av;
 52      public  double  r;
 53      public  double  ar;
 54      public  double  uwrb;
 55      public  double  wrb;
 56      public  double  u3;
 57      public  double  m3;
 58      public  double  l20d;
 59  
 60  
 61      #endregion
 62  
 63      #region Properties
 64  
 65      #region Settings
 66  
 67      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.LabelLocation), GroupName = nameof(Strings.Settings))]
 68      public LabelLocations LabelLocation { get; set; } = LabelLocations.Top;
 69  
 70      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ShowVolume), GroupName = nameof(Strings.Settings))]
 71      public bool ShowVolume { get; set; } = true;
 72  
 73      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ShowDelta), GroupName = nameof(Strings.Settings))]
 74      public bool ShowDelta { get; set; } = true;
 75  
 76      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ClustersMode), GroupName = nameof(Strings.Settings))]
 77      public bool ClusterModeOnly { get; set; }
 78  
 79      #endregion
 80  
 81      #region Visualization
 82  
 83      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Volume), GroupName = nameof(Strings.Visualization))]
 84      public Color VolumeColor { get; set; } = DefaultColors.White;
 85  
 86      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.PositiveDelta), GroupName = nameof(Strings.Visualization))]
 87      public Color PositiveDeltaColor { get; set; } = Color.Green;
 88  
 89      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.NegativeDelta), GroupName = nameof(Strings.Visualization))]
 90      public Color NegativeDeltaColor { get; set; } = Color.Red;
 91  
 92      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.BackGround), GroupName = nameof(Strings.Visualization))]
 93      public Color BackGroundColor 
 94      { 
 95          get => _bgPen.Color.Convert();
 96          set
 97          {
 98              _bgPen.Color = value.Convert();
 99              _bgBrush.StartColor = GetColorTransparency(value, BackGroundTransparency).Convert();
100          }
101      }
102  
103      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.HideBackGround), GroupName = nameof(Strings.Visualization))]
104      public bool HideBackGround { get; set; } = true;
105  
106      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Font), GroupName = nameof(Strings.Visualization))]
107      public FontSetting FontSetting { get; set; } = new("Times New Roman", 6);
108  
109      [Range(0, int.MaxValue)]
110      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Offset), GroupName = nameof(Strings.Visualization))]
111      public int Offset { get; set; } = 10;
112  
113      [Range(1, 10)]
114      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.BorderWidth), GroupName = nameof(Strings.Visualization))]
115      public int BorderWidth 
116      { 
117          get => _bgPen.Width;
118          set => _bgPen.Width = value;
119      }
120  
121      [Range(0, 10)]
122      [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Transparency), GroupName = nameof(Strings.Visualization))]
123      public int BackGroundTransparency 
124      { 
125          get => _backGroundTransparency;
126          set
127          {
128              _backGroundTransparency = value;
129              _bgBrush.StartColor = GetColorTransparency(BackGroundColor, BackGroundTransparency).Convert();
130          } 
131      }
132  
133      #endregion
134  
135      #endregion
136  
137      #region ctor
138  
139      public CandleStatist() : base(true)
140      {
141          DenyToChangePanel = true;
142          DataSeries[0].IsHidden = true;
143          ((ValueDataSeries)DataSeries[0]).ShowZeroValue = false;
144  
145          EnableCustomDrawing = true;
146          SubscribeToDrawingEvents(DrawingLayouts.Final);
147  
148          _bgPen.Color = BackGroundColor.Convert();
149          _bgBrush.StartColor = GetColorTransparency(BackGroundColor, _backGroundTransparency).Convert();
150      }
151  
152      #endregion
153  
154      #region Protected methods
155  
156      protected override void OnCalculate(int bar, decimal value)
157      {
158      }
159  
160      protected override void OnRender(RenderContext context, DrawingLayouts layout)
161      {
162          if (ChartInfo == null)
163              return;
164  
165          if (ClusterModeOnly && ChartInfo.ChartVisualMode != ChartVisualModes.Clusters)
166              return;
167  
168          DrawLabels(context);
169      }
170  
171      #endregion
172  
173      #region Private methods
174  
175      public readonly SMA       _sma = new SMA() { Period = X };
176      public readonly HighestX  _highestX = new HighestX() ;
177      public readonly LowestX   _lowestX  = new LowestX();
178  
179      private void DrawLabels(RenderContext  context)
180      {
181          if (!(ShowDelta || ShowVolume))
182              return;
183  
184          for (int bar = FirstVisibleBarNumber; bar <= LastVisibleBarNumber; bar++)
185          {
186              var candle = GetCandle(bar);
187  
188  
189              var av     =    _sma.Calculate(X, (candle.Volume));
190              var uhv    =    ((candle.Volume) > (2 * av));
191              var r      =    (candle.High - candle.Low);
192              var ar     =    _sma.Calculate(X, (candle.High - candle.Low));
193  
194  
195              var uwrb   =    (r > (2m * ar));
196              var wrb    =    (r > (1.33m * ar)) &&   (r < (2m * ar));
197              var u3     =    (candle.Close > (candle.High - (r / 3)));
198              var m3     =    (candle.Close > (candle.High - (r / 3)))  && (candle.Close > (candle.Low + (r / 3)));
199  
200              var prevCandle =  GetCandle(bar-1);
201              var l20d   =    (candle.Low) < prevCandle.(_lowestX.Calculate(20, candle.Low));
202  
203  
204  
205  
206              var delta =    candle.Delta;
207              var volumeStr = ChartInfo.TryGetMinimizedVolumeString(candle.Volume);
208              var deltaStr = ChartInfo.TryGetMinimizedVolumeString(delta);
209  
210              var shiftBetweenStr = (int)(FontSetting.RenderObject.Size / 100 * 20);
211              var shift = 2;
212  
213              var volumeSize = new Size();
214              var deltaSize = new Size();
215  
216              if (ShowVolume)
217                  volumeSize = context.MeasureString(volumeStr, FontSetting.RenderObject);
218  
219              if (ShowDelta)
220                  deltaSize = context.MeasureString(deltaStr, FontSetting.RenderObject);
221  
222              var h = volumeSize.Height + deltaSize.Height + shift * 2 + shiftBetweenStr;
223              var y = (int)GetStartY(candle, h);
224              var w = Math.Max(volumeSize.Width, deltaSize.Width) + shift * 2;
225              w = GetTrueWidth(w);
226              var x = ChartInfo.GetXByBar(bar) + (int)((ChartInfo.PriceChartContainer.BarsWidth - w) / 2);
227  
228              var rectangle = new Rectangle(x, y, w, h);
229  
230              if (!HideBackGround)
231                  context.DrawFillRectangle(_bgPen.RenderObject, _bgBrush.RenderObject.StartColor, rectangle);
232  
233              if (ShowVolume)
234              {
235                  y += shift;
236                  var rec = new Rectangle(x, y, w, volumeSize.Height);
237                  context.DrawString(volumeStr, FontSetting.RenderObject, VolumeColor, rec, _format);
238              }
239  
240              if (ShowDelta)
241              {
242                  y += volumeSize.Height > 0 ? volumeSize.Height + shiftBetweenStr : shift;
243                  var rec = new Rectangle(x, y, w, deltaSize.Height);
244                  var color = delta < 0 ? NegativeDeltaColor : PositiveDeltaColor;
245                  context.DrawString(deltaStr, FontSetting.RenderObject, color, rec, _format);
246              }
247          }
248      }
249  
250      private string GetTrueString(decimal value)
251      {
252          var absValue = Math.Abs(value);
253  
254          if ((int)absValue < absValue)
255              return value.ToString().TrimEnd('0');
256  
257          return value.ToString();
258      }
259  
260      private int GetTrueWidth(int width)
261      {
262          return Math.Min(width, (int)ChartInfo.PriceChartContainer.BarsWidth);
263      }
264  
265      private decimal GetStartY(IndicatorCandle candle, int height)
266      {
267          var topHeight = ChartInfo.GetYByPrice(candle.High) - Offset - height;
268          var bottomHeight = ChartInfo.GetYByPrice(candle.Low) + Offset + ChartInfo.PriceChartContainer.PriceRowHeight;
269  
270          return LabelLocation switch
271          {
272              LabelLocations.Top => topHeight,
273              LabelLocations.Bottom => bottomHeight,
274              LabelLocations.CandleDirection => candle.Open > candle.Close
275                                              ? bottomHeight
276                                              : topHeight,
277              _ => 0,
278          };
279      }
280  
281      private Color GetColorTransparency(Color color, int tr = 5)
282      {
283          var colorA = Math.Max(color.A - (tr * 25), 0);
284  
285          return Color.FromArgb((byte)colorA, color.R, color.G, color.B);
286      }
287  
288      #endregion
289  }


modified 25-Nov-23 3:57am.

AnswerRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
Richard MacCutchan24-Nov-23 22:58
mveRichard MacCutchan24-Nov-23 22:58 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202324-Nov-23 23:13
j k Nov202324-Nov-23 23:13 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
Richard MacCutchan25-Nov-23 0:22
mveRichard MacCutchan25-Nov-23 0:22 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202325-Nov-23 0:29
j k Nov202325-Nov-23 0:29 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
Richard MacCutchan25-Nov-23 0:44
mveRichard MacCutchan25-Nov-23 0:44 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202325-Nov-23 1:11
j k Nov202325-Nov-23 1:11 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
Richard MacCutchan25-Nov-23 1:13
mveRichard MacCutchan25-Nov-23 1:13 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202325-Nov-23 1:17
j k Nov202325-Nov-23 1:17 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
Richard MacCutchan25-Nov-23 1:21
mveRichard MacCutchan25-Nov-23 1:21 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202325-Nov-23 1:56
j k Nov202325-Nov-23 1:56 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202325-Nov-23 0:32
j k Nov202325-Nov-23 0:32 
QuestionUpdate text box from serial data Pin
Iskander1234519-Nov-23 22:41
Iskander1234519-Nov-23 22:41 
AnswerRe: Update text box from serial data Pin
Victor Nijegorodov20-Nov-23 1:18
Victor Nijegorodov20-Nov-23 1:18 
AnswerRe: Update text box from serial data Pin
lmoelleb20-Nov-23 6:44
lmoelleb20-Nov-23 6:44 
AnswerRe: Update text box from serial data Pin
Gerry Schmitz20-Nov-23 7:39
mveGerry Schmitz20-Nov-23 7:39 
AnswerRe: Update text box from serial data Pin
jschell20-Nov-23 8:34
jschell20-Nov-23 8:34 
GeneralRe: Update text box from serial data Pin
Iskander1234520-Nov-23 20:29
Iskander1234520-Nov-23 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.