gfxParticipant
Average
Hi,
Let’s take an ema and compare current value with its previous value.
As long as it goes down, slode negative, we draw a ceiling on top of price with highest high of last 20 bars.
ema = Average[20](close)
IF ema < ema[1] THEN
ceils = Highest[20](high)
ELSE
ceils = ceils[1]
ENDIF
Return ceils
Result in attached file.
It looks great until the slope turns positive for a few candles, and then negative again, whereas during these few candles the highhest high over the 20 last high has increased.
The orange line turns blue. But I don’t want the ceiling value to increase.
So I decide, when the slope is negative, to draw as ceiling the minimum value beetween the previous ceilling and the highest high.
ema = Average[20](close)
IF ema < ema[1] THEN
ceils = Min(ceils[1], Highest[20](high))
ELSE
ceils = ceils[1]
ENDIF
Return ceils
When I validate the indicator, no ceiling line is drawn on the chart.
I don’t undestrand why …
I tried to initialise with a high value, and/or use a temporary variable to calculate the min …
ema = Average[20](close)
once ceils = 1000000000000000
IF ema < ema[1] THEN
k = Min(ceils[1], Highest[20](high))
ceils = k
ELSE
ceils = ceils[1]
ENDIF
Return ceils
Ceiling line still not drawn on chart 🙂
Any idea why ?
Thks.
gfx
gfx – Once again this is an indicator coding question and not a platform issue. That is the second one tonight posted in the wrong place. Please try to understand which forums are for which subjects. I moved your topic….again.
Post your topic in the correct forum:
_ ProRealTime Platform Support: only platform related issues.
_ ProOrder: only strategy topics.
_ ProBuilder: only indicator topics.
_ ProScreener: only screener topics
_ General Discussion: any other topics.
_ Welcome New Members: for new forum members to introduce themselves.
Have you tried enclosing your code in:
if barindex >= 20 then
....
endif
In the first two examples, lines 5 and 6 can be removed.
Example 1 works fine. Please post instrument, TF, date and time of the candle where it plots incorrectly.
If you replace your second example with this one, it’lll work, but due to MIN() the indicator is quite BELOW the current price so you’ll have to shrink the chart slightly (and use 10K units):
IF BarIndex > 20 then
ema = Average[20](close)
once ceils = Highest[20](high)
IF ema < ema[1] THEN
ceils = Min(ceils, Highest[20](high))
ENDIF
endif
Return ceils
Third example is like the second one:
if barindex > 20 then
ema = Average[20](close)
once ceils = Highest[20](high)//1000000000000000
IF ema < ema[1] THEN
k = Min(ceils, Highest[20](high))
ceils = k
endif
endif
Return ceils