help with loop testing for condition over time.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36186 quote
    balancebalance
    Participant
    Junior
    Lma= (Average[20](close))
    Sma= (average[10](close))
    
    a= 0
    
    for variable= 0 to 15 do
    if (Sma > Lma) then
    a=1
    else
    a=0
    endif
    
    next
    
    condition1= a=1
    
    screener [condition1]
    

    I try to create a loop that will check the existence of a condition for a certain length of time.

    In this case, the short average is above the long average for the last 16 days.
    (Indicating an upward trend)

    At the moment there are at least two technical problems that I can not find a solution to,
    I would be very happy if anyone could explain or suggest a way to solve the problem.

    1. As you will see in the code, at the moment he can check the existence of the condition only in one candle (16 candles back)
    But he does not do that either – I checked and I get the wrong results.

    2. The second problem – I can not find a way to stop the loop if the program found one day when the condition is not met. (I’ve tried teaching BREAK in some variations, but without success)

    Maybe a loop does not work at the scanner?

    Could someone please help?

    Image-006.png Image-006.png
    #36253 quote
    NicolasNicolas
    Keymaster
    Legend

    The “a” variable should be incremented each time you find that your SMA>LMA condition is true, to get the days quantity of this condition to be valid in the past.

    SMA and LMA variables should also been compared in the loop iteration, not at their actual values:

    Lma= (Average[20](close))
    Sma= (average[10](close))
    
    a= 0
    
    for variable= 0 to 15 do
    if (Sma[variable] > Lma[variable]) then
    a=a+1
    break
    else
    a=0
    endif
    
    next
    
    condition1= a=variable
    
    screener [condition1]
    Derek and ZeroCafeine thanked this post
Viewing 2 posts - 1 through 2 (of 2 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

help with loop testing for condition over time.


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
balance @balance Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by NicolasNicolas
9 years, 4 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 05/20/2017
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...