Distance between 2 moving averages coding question

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18561 quote
    ck1066
    Participant
    Average

    Hi,

    I’m using two exponential moving averages (30EMA and 50 EMA). My question is how do I code to check the distance between the 30EMA and 50EMA is less than 20 PIPS over the last 20 bars, and the 30 EMA has remained above the 50 EMA over the same period, i.e. last 20 bars?

    #18570 quote
    Nicolas
    Keymaster
    Master

    Do the distance must be strictly less than 20 pips during all the last 20 bars?

    #18623 quote
    ck1066
    Participant
    Average

    Ideally I want to be able to control the distance between the two EMA’s, 20 PIPs was an example. The main aim is not to see the two ema’s drift wider and wider apart.

    #18642 quote
    Nicolas
    Keymaster
    Master

    So this code should do the test for you:

    testperiod = 20 //number of bars for the test 
    distance = 20 //distance in points between the 2 EMA
    ema30 = exponentialaverage[30]
    ema50 = exponentialaverage[50]
    
    test = summation[testperiod](ema30>ema50)=testperiod and summation[testperiod](ema30-ema50<=distance*pointsize)=testperiod
    
    return test
    #18837 quote
    ck1066
    Participant
    Average

    Many thanks Nicolas.

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

Distance between 2 moving averages coding question


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ck1066 @ck1066 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by ck1066
9 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/15/2016
Status: Active
Attachments: No files
Logo Logo
Loading...