Look back in time for condition

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #54835 quote
    genegene
    Participant
    New

    Hi,

    I would like to create a simple indicator that would simply look back in time basically put a ARROW up on the day of the triggers. The case:

    Has the 20 sma crossed the 50 sma in the last X days.

    • Each day that this would be true for would have an arrow.
    • So if it crossed 3 days ago and x was 5 the indicator would draw an arrow everyday after the cross for 5 days.

    Thanks for you help.

    Gene.

     

    #54891 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Here is the code, you can either copy & paste it or import the file. In the attached file I set the variables so that you can change them each time you launch the indicator, without having to modify the code.

    ONCE AvgCross = 0
    ONCE DayCount = 0
    ONCE Offset   = 20 * pipsize                                  //Distance from High/Low to display arrows
    ONCE FastSma  = 20
    ONCE SlowSma  = 50
    ONCE AvgType  = 0                                             //0 = sma   (see table at https://www.prorealcode.com/documentation/average/)
    ONCE MaxDays  = 5                                             //Display arrows for max 5 consecutive days
    FastAvg = average[FastSma,AvgType]
    SlowAvg = average[SlowSma,AvgType]
    IF FastAvg CROSSES OVER SlowAvg THEN
       AvgCross = 1                                               //1  = bullish crossing
       DayCount = 0
    ELSIF FastAvg CROSSES UNDER SlowAvg THEN
       AvgCross = -1                                              //-1 = Bearish crossing
       DayCount = 0
    ENDIF
    IF AvgCross = 1 THEN
       DayCount = DayCount + 1                                    //Increment counter at each new bullish candlestick
       DRAWARROWUP(barindex, high + Offset) COLOURED(50,205,50)
       IF DayCount = MaxDays THEN                                 //Stop counting and drawing arrows after MAXDAYS have elapsed
          DayCount = 0
          AvgCross = 0
       ENDIF
    ELSIF AvgCross = -1 THEN
       DayCount = DayCount + 1                                    //Increment counter at each new bearish candlestick
       DRAWARROWDOWN(barindex, low - Offset) COLOURED(255,0,0)
       IF DayCount = MaxDays THEN                                 //Stop counting and drawing arrows after MAXDAYS have elapsed
          DayCount = 0
          AvgCross = 0
       ENDIF
    ENDIF
    RETURN

    I only tested it on EurUsd DAILY.

    Roberto

    Averages-crossing-arrows.itf
    #54895 quote
    LeoLeo
    Participant
    Veteran
    p1=20
    p2=50
    X=5
    SMA1=average[p1](Close)
    SMA2=average[p2](Close)
    IF SMA1 crosses over SMA2 or SMA1 crosses under SMA2 then
    Position=BARINDEX
    ENDIF
    IF Barindex-Position =< X then
    DRAWARROW(barindex, typicalprice) COLOURED(151,17,228,100)
    ENDIF
    Return SMA1, SMA2
Viewing 3 posts - 1 through 3 (of 3 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

Look back in time for condition


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
gene @gene Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by LeoLeo
8 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/05/2017
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...