Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error code CS0120 when calling an indicator from a custom class

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Error code CS0120 when calling an indicator from a custom class

    Hallo,

    I'm trying to build an indicator which detects trends, their possible direction etc. Therefore I created a custom class "TrendDirection" including the method "CalcValues()". This method calls the System Indicator Method "ZigZag". By attempting that I receive the error code CS0120 (in German it says "Für das nicht statische Feld, die Methode oder die Eigenschaft "Indicator.ZigZag(DeviationType, double, bool)" ist ein Objektverweis erforderlich.").

    Can anyone help my out how it's possible to access a System Indicator Method from a custom class?

    Here's the code of the class (unfortunately the formatting got lost when pasting it):
    Code:
    public class TrendDirection
    {
    static int[] PosHigh = new int[3];
    static int[] PosLow = new int[3];
    
    static double[] PriceHigh = new double[3];
    static double[] PriceLow = new double[3];
    
    static bool CalcValues (double ZigZagDevInPercent, int ZigZagLookBackPeriod)
    {
    PosHigh[0] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).HighBar(0, 1, ZigZagLookBackPeriod);
    PosHigh[1] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).HighBar(0, 2, ZigZagLookBackPeriod);
    PosHigh[2] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).HighBar(0, 3, ZigZagLookBackPeriod);
    
    PosLow[0] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).LowBar(0, 1, ZigZagLookBackPeriod);
    PosLow[1] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).LowBar(0, 2, ZigZagLookBackPeriod);
    PosLow[2] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).LowBar(0, 3, ZigZagLookBackPeriod);
    
    if (-1 == PosHigh[0] || -1 == PosHigh[1] || -1 == PosHigh[2] || -1 == PosLow[0] || -1 == PosLow[1] || -1 == PosLow[2])
    return false;
    
    PriceHigh[0] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).ZigZagHigh[PosHigh[0]];
    PriceHigh[1] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).ZigZagHigh[PosHigh[1]];
    PriceHigh[2] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).ZigZagHigh[PosHigh[2]];
    
    PriceLow[0] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).ZigZagLow[PosLow[0]];
    PriceLow[1] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).ZigZagLow[PosLow[1]];
    PriceLow[2] = ZigZag (DeviationType.Percent, ZigZagDevInPercent, true).ZigZagLow[PosLow[2]];
    
    return true;
    }
    
    public bool IsUpwards()
    {
    // TBD
    return false;
    }
    
    public bool IsDownwards()
    {
    // TBD
    return false;
    }
    }
    Thanks in advance,
    Frederik

    #2
    Hello LeeDeForest,

    Thank you for the post.

    To pass an indicator to a custom class it would look like the following:

    Code:
    static bool CalcValues (Indicator myIndicator, double ZigZagDevInPercent, int ZigZagLookBackPeriod)
    In your method you can then use the myIndicator parameter to access values or indicator methods like Print

    Code:
    static bool CalcValues (Indicator myIndicator, double ZigZagDevInPercent, int ZigZagLookBackPeriod)
    {
        myIndicator.Print("here");

    If your indicator has custom public properties or plots/methods you can instead use the indicators type:

    Code:
    static bool CalcValues (ZigZag myIndicator, double ZigZagDevInPercent, int ZigZagLookBackPeriod)
    {
        myIndicator.ZigZagHigh[int barsAgo];
    Please let me know if I may be of further assistance.

    Comment


      #3
      Awesome! Thanks for your quick reply. It works like a charm now.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      670 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      379 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      111 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      575 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      582 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X