Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Translation from probuilder to ninjascript

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

    Translation from probuilder to ninjascript

    Hi everyone, I tried to translate one of my trend indicators based on std deviations from probuilder to ninjascript but the trend change logic doesn't always work on ninja as it does on prorealtime.​
    I attach here the original probuilder code, can someone help me pls? Thanks a lot

    // Costants.
    // The six trend values ​​are fictional

    period = 13
    deviation1 = 1
    deviation2 = 2
    longupper= 30
    longmiddle=20
    longlower=10
    shortlower=-30
    shortmiddle=-20
    shortupper=-10

    // (i) indicators
    iSTD1 = deviation1 * STD[period](close)
    iSTD2 = deviation2 * STD[period](close)
    iSTD3 = deviation3 * STD[period](close)
    iSMA = Average[period,0](close)

    // (c) conditions

    cUpperBand2 = iSMA + iSTD2 // ----2----
    cUpperBand1 = iSMA + iSTD1 // ----1----
    cMiddleBand = iSMA // ----0----
    cLowerBand1 = iSMA - iSTD1 // ----1----
    cLowerBand2 = iSMA - iSTD2 // ----2----

    // Bollinger's Logic

    // Initial set trend, based on first std dev

    if trend=0 and close crosses over cUpperband1 then
    trend = longupper
    elsif trend=0 and close crosses under cLowerBand1 then
    trend = shortlower
    endif

    // Follows first set trend
    // Change of trend

    if trend = longupper and close crosses under cUpperBand1 then
    trend = longmiddle
    endif



    if trend=longmiddle then
    if close crosses under cMiddleBand then
    trend=longlower
    elsif close crosses over cUpperBand2 then
    trend=longupper
    else
    trend = longmiddle
    endif
    endif

    if trend=longlower then
    if close crosses under cLowerBand1 then
    trend=shortlower
    elsif close crosses over cUpperBand1 and close < cUpperBand2 then
    trend = longmiddle
    elsif close crosses over cUpperBand2 then
    trend=longupper
    else
    trend=longlower
    endif
    endif

    if trend=shortlower and Close crosses over cLowerBand1 then
    trend=shortmiddle
    endif

    if trend=shortmiddle then
    if close crosses over cMiddleBand then
    trend=shortupper
    elsif close crosses under cLowerBand2 then
    trend = shortlower
    else
    trend=shortmiddle
    endif
    endif

    if trend = shortupper then
    if close crosses over cUpperBand1 then
    trend=longupper
    elsif close crosses under cLowerBand1 and close > cLowerBand2 then
    trend=shortmiddle
    elsif close crosses under cLowerBand2 then
    trend=shortlower
    else
    trend = shortupper
    endif
    endif

    // defines the values ​​of 'ts' at the appropriate Bollinger band level

    if trend = longupper or trend = shortupper then
    ts = cUpperBand1
    elsif trend = longmiddle or trend = shortmiddle then
    ts = cMiddleBand
    elsif trend = longlower or trend = shortlower then
    ts = cLowerBand1
    endif

    // colors

    if trend = longupper or trend = longmiddle or trend = longlower then
    r = 0
    g = 255 // colors the "ts" trendline in green


    elsif trend = shortupper or trend=shortmiddle or trend=shortlower then
    r = 255 // colors the "ts" trendline in red
    g = 0

    endif

    return ts coloured(r,g,0) style(line,2) as "BTrend"​
    Last edited by PScilly; 12-17-2024, 10:52 PM.

    #2
    Hello PScilly,

    Thank you for your post.

    While our support does not provide conversion services, if you have a question about how to accomplish something specific in NinjaScript we can assist.

    This thread will also remain open for any members of the community who may wish to convert this script on your behalf.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    557 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X