moving average loop

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #210925 quote
    rob.es
    Participant
    New

    hi I’m trying to screen a range of Emas (20 to 65) which may meet my condition but my results are only Ema 65. how can I have all the Ema that meet my condition?

    thanks

    period=0
    
    for a=20 to 65 do
    c1=ExponentialAverage[a](close)
    c2=summation[100](close CROSSES UNDER c1 or (open < c1 and  close[1]>c1)) =0 and summation[100](close crosses over c1 or (open>c1 and close[1]<c1)) =1 and summation[100]((c1-high>0)and (c1-high<=0.40*AverageTrueRange[14](close) ))>=2 and abs(low-c1)<=0.35*AverageTrueRange[14](close)
    if c2 then
    period=a
    else
    period=0
    endif
    screener[period>1](period as "period")
    next
    
    #210929 quote
    robertogozzi
    Moderator
    Master

    A 46-element (20 to 65) array would do the trick, but only 1 datum is allowed as a criterion.

    A solution is to add all EMAs’periods as a single number so to get, say:   202532445165  for EMAs  20, 25, 32, 44, 51, 65

    There are a couple of issues, though:

    • too many EMAs meeting the conditions would exceed the biggest number allowed (which I don’t know, maybe 15+ digits)
    • big numbers (such as dates in the format yyyymmdd) are usually reported in rounded scientific notation such as 20E+6 (or similar) which would make any coding effort vain.
    period = 0
    for a = 20 to 65 do
       c1=ExponentialAverage[a](close)
       c2=summation[10](close CROSSES UNDER c1 or (open < c1 and  close[1]>c1)) =0 and summation[10](close crosses over c1 or (open>c1 and close[1]<c1)) =1 and summation[10]((c1-high>0)and (c1-high<=0.40*AverageTrueRange[14](close) ))>=2 and abs(low-c1)<=0.35*AverageTrueRange[14](close)
       if c2 then
          period = (period * 100) + a
       endif
    next
    screener[period](period as "period")
    x-1.jpg x-1.jpg
    #210931 quote
    robertogozzi
    Moderator
    Master

    I coded just [10]  periods with SUMMATION, as I fear the 254-bar limit (unless you have the 1024-bar premium version provided by PRT direct) won’t allow much more more as EMAs require more than twice their periods to be calculated. So a 65-period EMA will require more than 130 bars + 100-lookback periods may exceed 254, but you can try more, say 20 or 40,…. even 100 could do (it’s not an easy accurate calculation).

    #210958 quote
    rob.es
    Participant
    New

    thank you Roberto but the period results are all like this:44 45 46 47 48 …

    some results are not quite accurate. when I write my previous code only for one Ema: say Ema34 all the results are accurate.

    but when using for loop, with same condition some of the results are off

     

    b11=ExponentialAverage[34](close)
    b12=summation[100](close crosses under b11 or (open<=b11 and close[1]>=b11 ))=0
    b13=summation[100](close crosses over b11 or (open>=b11 and close[1]<=b11))=1
    b14=summation[100](abs(b11-high) <=0.35*AverageTrueRange[100](close) and b11-high>0) >=2
    b15=abs(low-b11)<=0.35*AverageTrueRange[14](close)
    period=34
    if b12 and b13 and b14 and b15 then
    screener (period as "period")
    endif
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

moving average loop


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
rob.es @rob-es Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by rob.es
3 years ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 03/05/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...