momentum indicator buf

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #211229 quote
    Banie
    Participant
    Average

    Hello friends,

    If possible can someone help me fix a bug in my coding. I want to create a code using the daily volatility/atr to create a momentum indicator with levels 1,2,3,4 and 5. This is how far i got:

    Volatility[10,10] = AverageTrueRange[20](close)
    MomentumLevel = close – close[20]
    Level1 = 0.5 * Volatility
    Level2 = 1 * Volatility
    Level3 = 1.5 * Volatility
    Level4 = 2 * Volatility
    Level5 = 2.5 * Volatility

    If Momentum > Level5 Then
    MomentumLevel = 5
    Else If Momentum > Level4 Then
    MomentumLevel = 4
    Else If Momentum > Level3 Then
    MomentumLevel = 3
    Else If Momentum > Level2 Then
    MomentumLevel = 2
    Else If Momentum > Level1 Then
    MomentumLevel = 1
    Else
    MomentumLevel = 0
    EndIf

    Return MomentumLevel

    #211232 quote
    robertogozzi
    Moderator
    Master

    Line 1 is not correct, you can’t assign any value to indicators, as they can only return values.

    Else If is not allowed, the correct syntax is Elsif.

    #211251 quote
    JS
    Participant
    Senior

    Hi @Banie,

    Hereby your custom code…

     
    xVolatility = AverageTrueRange[20](close)
    MomentumLevel = close - close[20]
    Level1 = 0.5 * xVolatility
    Level2 = 1 * xVolatility
    Level3 = 1.5 * xVolatility
    Level4 = 2 * xVolatility
    Level5 = 2.5 * xVolatility
    
    If Momentum > Level5 Then
    MomentumLevel = 5
    ElsIf Momentum > Level4 Then
    MomentumLevel = 4
    ElsIf Momentum > Level3 Then
    MomentumLevel = 3
    ElsIf Momentum > Level2 Then
    MomentumLevel = 2
    ElsIf Momentum > Level1 Then
    MomentumLevel = 1
    Else
    MomentumLevel = 0
    EndIf
    
    Return MomentumLevel
    Banie thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

momentum indicator buf


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Banie @banie Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by JS
2 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/09/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...