momentum indicator buf

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #211229 quote
    BanieBanie
    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
    robertogozzirobertogozzi
    Moderator
    Legend

    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
    JSJS
    Participant
    Master

    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
    Scherm­afbeelding-2023-03-09-om-15.10.12.png Scherm­afbeelding-2023-03-09-om-15.10.12.png
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 JSJS
3 years, 6 months ago.

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