Please help for a forloop scan

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #159748 quote
    HaHa
    Participant
    New

    Hi,

    I’m trying to scan that N number of consecutive candles are bullish and above 20EMA.

    I used a forloop to scan and I’m not getting a correct result.

    Can someone please tell me if you see a problem with my code? or is there other way to code it?

    Thank you.

    Long_20EMA.itf
    #159751 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I can’t read your code now (you’d better always post also the code, unless it’s over hundreds of lines).

    This is the code:

    N       = 5   //5 consecutive candles
    Ema20   = close > average[20,0](close)
    Bullish = close > open
    Cond    = Ema20 AND Bullish
    x       = (summation[N](Cond) = N)

    x is true whenever N consecutive bullish candles above ema20 are met.

    #159764 quote
    HaHa
    Participant
    New

    Hi

    Thank you for the help.

    I’d already tried the summation fonction before, it doesn’t work well.

    That’s why I tried a forloop.

    Here’s my entire code.

    // N number of candles close above 20EMA and are bullish green
    
    
    // Uptrend
    ema20 = ExponentialAverage[20](close)
    ema50 = ExponentialAverage[50](close)
    ema200 = ExponentialAverage[200](close)
    m1 = ema20 > ema50 and ema50 > ema200
    m2 = ema20 > ema20[1]
    
    // Bullish candles above 20EMA
    NofBar = 5
    rsltClose = 0
    rsltCandle = 0
    for i = 0 to NofBar do
    
    rsltClose = close[i] >  ema20
    rsltCandle = close[i] > open[i]
    
    next
    
    // Volume & Price
    vol = ExponentialAverage[60](Volume)
    t1 = vol > 500000
    t2 = close > 3 and close < 40
    
    
    SCREENER[m1 and m2 and rsltClose and rsltCandle and t1 and t2]
    #159780 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    My fault, I coded an SMA instead of EMA. Replace line 2 with:

    Ema20   = close > average[20,1](close)  //0=Sma, 1=Ema, 2=Wma, etc...
    Ha thanked this post
    #159827 quote
    HaHa
    Participant
    New

    Hi Roberto

    Your code works, thank you.

    Would  you mind explain how the last line works ?

    Can’t get my head around how you can give a condition in a price constant () then an arithmetic sum of that condition can bring back what I want.

    #159837 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    It sums up the condition for the last N bars and the result must be N, otherwise it would mean that the condition is not true for all N bars.

Viewing 6 posts - 1 through 6 (of 6 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

Please help for a forloop scan


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
Ha @ha Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
5 years, 7 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 01/29/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...