New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.

Simple Consolidation Scan - Syntax Error


Looking to create a simple consolidation scan, basically last 5 closes within a 4% range. Written a code but getting syntax error, probably something stupid i've done.

Code i've written:
[type is stock] and [sma(20,volume) > 40000]
and [((max(5,close)-min(5,close))/((max(5,close)+min(5,close))/2)*100) < 4]

Syntax error recieved:
Could not parse "" located in the clause "((MAX(5,CLOSE)-MIN(5,CLOSE))/((MAX(5,CLOSE)+MIN(5,CLOSE))/2)*100) < 4"

Tried a search on the forum but can't see what the error would be?

Thanks in advance,

Best Answer

  • lmkwinlmkwin ✭✭
    edited March 8 Answer ✓
    Could not parse is usually a ( ) parenthesis error. Either too many, not enough, or wrongly placed.

    I'd say that is an overly complex equation also.

    There are a couple ways to arrive at your desired results but I'd recommend using the Pct Difference function already in the Technical Indicators dropdown.

    when you add it to the workbench it defaults in like this

    and [PctDiff(close,sma(50,close)) < 5]

    This is asking that the % difference between two things, the close and the sma 50 of the close to be less than 5% apart.

    You would change the two things to meet your requirements.

    and [PctDiff(max(5,close),min(5,close)) < 5]

    They talk about the PctDiff function here

    and here

    You can use the PctDiff in the Rank By statement in the scan to see the result of the code

    rank by [PctDiff(max(5,close),min(5,close))
    will show the PctDiff number in descending order.

    rank by [PctDiff(max(5,close),min(5,close)) ascending
    will show the results in ascending order. Of course you can also click on the headers to sort on the results page as well.


  • That's brilliant, exactly what i was after, thank you for the great response
  • lmkwinlmkwin ✭✭
    something else to keep in mind. In a scan the quantity of the left ( and right ) parenthesis must equal. Same thing for left [ and right ] brackets. The system will usually provide a syntax error stating that the brackets don't equal. For the parenthesis it will usually say that it can't parse.

    Could not parse "" located in the clause
    "((MAX(5,CLOSE)- MIN(5,CLOSE))/((MAX(5,CLOSE)+MIN(5,CLOSE))/2)*100) < 4"

    In the ((max(5,close) there is an extra ( at the beginning and a missing ) at the end for example. So it doesn't know what to do with that.

    To attempt to get the engine to think of an arithmetic expression a - b / c - d you can try to use brackets

    [a-b] / [c-d] I don't recommend trying to do this as it's difficult to check the results on many of these situations. If you have it perfectly formatted (meaning the system isn't showing an error) and it's producing results but you have no reliable way to check the results, is that good?

Sign In or Register to comment.