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.
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
LeoParticipant
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