TradingView
andre_007
28 Mar 2023 pukul 03.42

TrendIndicators 

S&P 500 IndexTVC

Deskripsi

Library "TrendIndicators"
This is a library of 'Trend Indicators'.
It aims to facilitate the grouping of this category of indicators, and also offer the customized supply of
the source, not being restricted to just the closing price.

Indicators (this is a work in progress):

1. Absolute DI (Directional Moviment Index) (Difference between DI+ and DI-).
Used in 'DMI Stochastic Extreme' by Barbara Star.
2. DMI

DI_Abs(lengthDI, smoothDI, typeMA, lengthMA)
  @description Absolute DI (Directional Moviment Index).
Used in 'DMI Stochastic Extreme' by Barbara Star.
Difference between DI+ and DI-
  Parameters:
    lengthDI: (int) Length of DI+/DI-
    smoothDI: (bool) Sets whether absolute DI should be smoothed
    typeMA: (int) Type of moving average of smoothing
    lengthMA: (int) Length for moving average of smoothing
  Returns: (float) Absolute value of DI

dmi(diLength, adxSmoothing)
  @description DMI (Directional Movement Index)
Same as ta.dmi()
  Parameters:
    diLength: (int) Length of DI+/DI-
    adxSmoothing: (int) ADX Smoothing
  Returns: [series float, series float, series float] Tuple of three DMI series: Positive Directional
Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).

dmi(source, diLength, adxSmoothing)
  @description DMI (Directional Movement Index)
Customized version of ta.dmi(), with custom source
  Parameters:
    source: (float) Source for DI+/DI-
    diLength: (int) Length of DI+/DI-
    adxSmoothing: (int) ADX Smoothing
  Returns: [series float, series float, series float] Tuple of three DMI series: Positive Directional
Movement (+DI), Negative Directional Movement (-DI) and Average Directional Movement Index (ADX).

Catatan Rilis

v2
New overloaded function:
Absolute DI (Directional Moviment Index) with custom source.

Catatan Rilis

v3
Minor fix
Komentar
serkany88
you should change de custom source dma function name it's the same as the one above.
andre_007
serkany88
@andre_007, The problem is this is an isolated library export function not really a "method". Methods have to be part of objects or "custom types" in pinescript's way of looking at it. When i try to call custom dmi using the same name i get an error because there isn't really a parameter for custom input using your library.

If you look at the example you have linked it uses this parameter. You can't use 'this' parameter in isolated functions because this applies the method to the attached object.
andre_007
That's weird. I'm using it normally. Can you send me the print of the error so I can analyze it, please?
Below is the example that looks normal:
serkany88
@andre_007, That one will work when you spesifically point the identifier like "source=something something" because then interpreter understands it should look for something else than the first encountered function with said name but it doesn't work when you don't place an identifier and that's the most common practice when using functions for most people.

So in a sense it will work when you do it like you do but i was so used to not using identifiers for example i haven't even thought of that. But the overall point is methods and functions are while being pretty similar are not the same thing. You can overload a function like you do because all inbuilt types are actually objects too but they are not really "methods". It may sound confusing or i may not be explaining it in the best way that i could but if you look for some OOP concepts i think it gets easier to understand my point.

Thank you for the work by the way.
andre_007
@serkany88, If you are then required to pass the parameter name in overloaded functions, then do we have a bug in PineScript?


For now I suggest putting the name of the parameter. I will inform myself better about this.
serkany88
@andre_007, No i just retried and it worked. But previously it didn't work when i tried a similar thing a few days ago. I think they adapted their compiler with similar interpretation.
serkany88
@andre_007, Btw i think tradingview changed some stuff about their compiler. i just realized that when i tried it before it didn't work but now i retried and it started to work without identifiers too. I think they applied the same logic to inbuilt types as well.
andre_007
@serkany88, Yeah... I did a test just now removing the parameter names, and the compiler signaled OK. Well, what matters is that it's working now. Greetings.
Lebih lanjut