Swing Indicator

Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #50496 quote
    Henry
    Participant
    Average

    A request that was addressed to ProRealTime:

    Good morning, I would like to recode this swing indicator in tradestation format to prorealcode language.

    inputs: filter(2), stats(0);
    vars : xBar(0) , xHigh(0), xLow(0), xCount(0), xSwitch(0);
    vars : xSkip(0), xConfirm(0);
    vars : pBar(0) , pHigh(0), pLow(0);
    vars : bFirst(1);

    if xSwitch = 0 then
    begin
    if High >= xHigh then
    begin
    xHigh = High;
    xLow = Low;
    xBar = BarNumber;
    xSkip = 0;
    end
    else
    begin
    xSkip = xSkip + 1;
    if xSkip >= filter then
    begin
    xConfirm = 1;
    xCount = 1;
    while xCount < filter
    begin
    if (Low[xCount] <= Low[xCount-1]) or (xLow <= Low[filter-1])
    then
    begin
    xCount = filter;
    xConfirm = 0;
    end;
    xCount = xCount + 1;
    end;
    if xConfirm = 1 then
    begin
    xSwitch = 1;
    if stats = 0 then
    plot1[BarNumber-xBar](xHigh,”Swing”)
    else
    begin
    if bFirst = 0 then
    begin
    plot2[BarNumber-xBar](xHigh-pLow,”Range”);
    plot3[BarNumber-xBar](xBar -pBar,”Duration”);
    end;
    bFirst = 0;
    end;
    pHigh = xHigh;
    pLow = xLow;
    pBar = xBar;
    xHigh = High;
    xLow = Low;
    xBar = BarNumber;
    xSkip = 0;
    end;
    end;
    end;
    end
    else
    begin
    if Low <= xLow then
    begin
    xHigh = High;
    xLow = Low;
    xBar = BarNumber;
    xSkip = 0;
    end
    else
    begin
    xSkip = xSkip + 1;
    if xSkip >= filter then
    begin
    xConfirm = 1;
    xCount = 1;
    while xCount < filter
    begin
    if (High[xCount] >= High[xCount-1]) or (xHigh >=
    High[filter-1]) then
    begin
    xCount = filter;
    xConfirm = 0;
    end;
    xCount = xCount + 1;
    end;
    if xConfirm = 1 then
    begin
    xSwitch = 0;
    if stats = 0 then
    plot1[BarNumber-xBar](xLow,”Swing”)
    else
    begin
    plot2[BarNumber-xBar](pHigh-xLow,”Range”);
    plot3[BarNumber-xBar](xBar -pBar,”Duration”);
    end;
    pHigh = xHigh;
    pLow = xLow;
    pBar = xBar;
    xLow = Low;
    xHigh = High;
    xBar = BarNumber;
    xSkip = 0;
    end;
    end;
    end;
    end;

    if ((date = lastcalcdate) and (time = lastcalctime)) then
    begin
    if xSwitch = 0 then
    begin
    if stats = 0 then
    plot1[BarNumber-xBar](xHigh,”Swing”)
    else
    begin
    plot2[BarNumber-xBar](xHigh-pLow,”Range”);
    plot3[BarNumber-xBar](xBar -pBar,”Duration”);
    end;
    end
    else
    begin
    if stats = 0 then
    plot1[BarNumber-xBar](xLow,”Swing”)
    else
    begin
    plot2[BarNumber-xBar](pHigh-xLow,”Range”);
    plot3[BarNumber-xBar](xBar -pBar,”Duration”);
    end;
    end;
    end;

    Suggestion for an anwser:

    Add a filter variable and then add the indicator on the price graph:

    if xSwitch = 0  then
    if High >= xHigh then
    xHigh  = High
    xLow   = Low
    xSkip  = 0
    else
    xSkip  = xSkip + 1
    if xSkip      >= filter then
    xConfirm    = 1
    xCount      = 1
    while xCount < filter
    
    if (Low[xCount] <= Low[xCount-1]) or (xLow <= Low[filter-1])then
    xCount   = filter
    xConfirm = 0
    endif
    xCount      = xCount + 1
    wend
    if xConfirm   = 1 then
    xSwitch = 1
    MyxHigh=xHigh
    xHighBar=Barindex-xskip
    
    xHigh   = High
    xLow    = Low
    xSkip   = 0
    endif
    endif
    endif
    else
    if Low <= xLow then
    xHigh = High
    xLow  = Low
    xSkip = 0
    else
    xSkip = xSkip + 1
    if xSkip >= filter then
    xConfirm = 1
    xCount   = 1
    while xCount < filter
    if (High[xCount] >= High[xCount-1]) or (xHigh >= High[filter-1]) then
    xCount   = filter
    xConfirm = 0
    endif
    xCount   = xCount + 1
    wend
    if xConfirm = 1 then
    xSwitch = 0
    myxlow=xLow
    xLowBar=Barindex-xskip
    xLow    = Low
    xHigh   = High
    xSkip   = 0
    endif
    endif
    endif
    endif
    DRAWSEGMENT(xLowBar, myxlow, xHighBar, MyxHigh) COLOURED(255,0,0)
    return
    
    Nicolas, swapping, Lighthouse and ckat55 thanked this post
    #50721 quote
    Marco
    Participant
    Junior

    hi ,

    good

     

    thanks Henry

    #50740 quote
    Nicolas
    Keymaster
    Master

    This is how it looks, thanks to Henry 🙂 , I’ll add it in the library soon for everyone’s benefit.

    swing-indicator.png swing-indicator.png
    #94386 quote
    massimo mamprin
    Participant
    Junior

    Come si definisce la variabile filter ???

    #94395 quote
    Vonasi
    Moderator
    Master

    massimo mamprin – English only in the English forums please.

    #94396 quote
    robertogozzi
    Moderator
    Master

    Filter seems to be what is commonly called Period.

    Write

    Filter=20

    as the first line. Change it whenever you want to.

    #94554 quote
    massimo mamprin
    Participant
    Junior

    Thank you

    How can I change the colour of the line

    In PRT i can make the input about the number of the bar when i change the colour the line is the same colour

    Do you know can I change

    Thanks

    #94557 quote
    robertogozzi
    Moderator
    Master

    You can add 3 variables for colours:

    – Red

    – Green

    – Blue

    you can then set them with the properties.

    Change the last part of line 58 as follows:

    COLOURED(Red,Green,Blue)
    #94568 quote
    massimo mamprin
    Participant
    Junior

    I try but give me error (sintassi)

    #94572 quote
    robertogozzi
    Moderator
    Master

    Post the code you have written.

    #94585 quote
    massimo mamprin
    Participant
    Junior

     

    if High >= xHigh then
    xHigh  = High
    xLow   = Low
    xSkip  = 0
    else
    xSkip  = xSkip + 1
    if xSkip      >= filter then
    xConfirm    = 1
    xCount      = 1
    
    while xCount < filter
    if (Low[xCount] <= Low[xCount-1]) or (xLow <= Low[filter-1])then
    xCount   = filter
    xConfirm = 0
    endif
    xCount      = xCount + 1
    wend
    
    if xConfirm   = 1 then
    xSwitch = 1
    MyxHigh=xHigh
    xHighBar=Barindex-xskip
    xHigh   = High
    xLow    = Low
    xSkip   = 0
    endif
    endif
    endif
    else
    if Low <= xLow then
    xHigh = High
    xLow  = Low
    xSkip = 0
    else
    xSkip = xSkip + 1
    if xSkip >= filter then
    xConfirm = 1
    xCount   = 1
    
    while xCount < filter
    if (High[xCount] >= High[xCount-1]) or (xHigh >= High[filter-1]) then
    xCount   = filter
    xConfirm = 0
    endif
    xCount   = xCount + 1
    wend
    
    if xConfirm = 1 then
    xSwitch = 0
    myxlow=xLow
    xLowBar=Barindex-xskip
    xLow    = Low
    xHigh   = High
    xSkip   = 0
    endif
    endif
    endif
    endif
    
    DRAWSEGMENT(xLowBar, myxlow, xHighBar, MyxHigh) COLOURED(255,0,0)
    
    return

    EDIT by Vonasi: Code tidied up using ‘Insert PRT Code’ button for you. 🙂

    #94587 quote
    robertogozzi
    Moderator
    Master

    I want to point out two issues:

    • To write code, please use the <> “insert PRT code” button, to make code easier to read and understand
    • When you Copy remove any line number (try not to select them if possible) after Pasting the code

    the latter being the cause of reported syntax errors.

    #95013 quote
    Matriciel
    Participant
    Master
    Hi,
    What is the difference with a traditional “ZigZag”?
    #95029 quote
    Nicolas
    Keymaster
    Master

    ZigZag like many other indicators plots the tops and bottoms. You can take any calculation method to find and link them with segments and you’ll get something similar to zigzag.

    Matriciel thanked this post
    #109561 quote
    Robb
    Participant
    Average

    Hi All, Hi Nicolas,

    I copied and pasted the code, added the variable filter=20.

    No sintax errors, but on the chart nothing appears and I don’t understand why.

    Thank you in advance

    Roberto

Viewing 15 posts - 1 through 15 (of 27 total)
  • You must be logged in to reply to this topic.

Swing Indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Henry @henry Participant
Summary

This topic contains 26 replies,
has 1 voice, and was last updated by Khaled
4 years ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/25/2017
Status: Active
Attachments: 4 files
Logo Logo
Loading...