how to get Range of each and every day of first candle
@sandy we've already shown you how to identify the first candle of the day. If you combine that logic with the ValueWhen
function, it should be quite easy to get the range of that candle. Give it a try, and if it doesn't work come back and let us know what's going wrong. We're here to help teach you how to write your own AFL, not just do it for you.
@mradtke
i guess this is the code snipplet which will give me range of first candle
FBL=ValueWhen(Day()!=Ref(Day(),-1),L);
FBH=ValueWhen(Day()!=Ref(Day(),-1),H);
range=FBH-FBL;
Moderator comment: you need to use CODE tags
FBR=ValueWhen(Day()!=Ref(Day(),-1),H-L);
need to calculate the average for 5 day ranges and need to compare with current candle
if range of current candle is two times average ranges then need to highlight that candle
this is my code let me know where iam wrong it is plotting shape for all the candles
FBR=ValueWhen(Day()!=Ref(Day(),-1),H-L);
rangeavg=FBR+FBR/5;
PlotShapes(IIf(FBR>=2*rangeavg,shapeHollowStar,shapeNone),colorGreen,0,L);
Moderator comment: you need to use CODE tags
Your problem is here:
rangeavg=FBR+FBR/5;
That finds the average of the last 5 bars in your intraday timeframe. You need to use TimeFrameCompress() and TimeFrameExpand() to create an array of daily values, find the average (just use the MA function), and then expand the result back to your intraday timeframe.
That's great. When you get a working solution to a question, you should mark the topic as "solved".
Yes, just use the Ref()
function on the compressed array, similarly to how I assume you're using the MA()
function. I wouldn't have to assume if you'd post your code.
@mradtke hi sir this is my code let me know where iam wrong
//code to compare current day all candles ranges with prev day candle avgrange
FBR=ValueWhen(Day()!=Ref(Day(),-1),H-L);
wc = TimeFrameCompress( FBR, inDaily );
//allcandles=Ref(Day()!=Ref(Day(),-1),H-L);
wc = TimeFrameCompress( FBR, inDaily);
weeklyma = MA( wc, 5 );
weeklyma = TimeFrameExpand( weeklyma, inDaily);
PlotShapes(IIf(FBR>=weeklyma ,shapeHollowStar,shapeNone),colorGreen,0,L);
Moderator comment: you need to use CODE tags
The only outright error is that you called TimeFrameCompress()
twice. But your choice of variable names is a bit confusing... you're doing a compression to daily timeframe, but then calculate a 5-day average and call it weeklyma
. Most people would consider a "Weekly MA" to be a moving average of weekly values.
Instead of just putting data on a chart with PlotShapes, you should add code for an exploration so that you can see how your TimeFrameExpand()
is working. That will let you know whether you need to use Ref()
to offset the values at all.
By the way, this code doesn't do what your comment says:
//code to compare current day all candles ranges with prev day candle avgrange
Because you're not finding the average range of all the candles on any given day. You're finding the range of the opening candle on each day, and then averaging those opening ranges across days. Please try to be clear on what you're trying to achieve, and also tell us how you think your output is incorrect.
@mradtke the thing is i want to compare range of first candle of current day with previous day range averages of first candles of previous day and next day and so on let say for 5 previous first candles
i was able to write code to compare first candle with avg range of previous previous days first candle but now
i want to compare with each and every candle of current day to their corresponding ranges of previous days
example i have
candles like this
current day candles previous day next previous day
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
compare 1 st of curr day with avg range of previous day 1st candle and next previous day 1st candle and so on
Sorry, I don't think I understand what you're trying to do. Perhaps someone else on the forum can jump in if they understand your request.
I'm pretty sure you could do that with SparseCompress()
, MA()
and SparseExpand()
inside of a loop that iterates over all intraday time stamps in a single trading day. If you're not comfortable with array manipulation in AmiBroker, you might want to find someone willing to help you write that code.
This is my code iam getting movingaverage values and range values as correct but i do have problem while ploting
it is plotting shape on each and every candle i want to plot on particular candle whose range is more than or equal mavg
time = TimeNum();
time2 = SelectedValue(time);
val = ValueWhen(TimeNum()==time2, H-L);
Range = TimeFrameCompress(val,inDaily);
MovingAvg = MA(Range, 15);
MovingAvg = TimeFrameExpand(MovingAvg, inDaily);
PlotShapes(IIf(val >= MovingAvg, shapeUpArrow, shapeNone),colorRed, 0, L);
Moderator comment: you need to use CODE tags
And what does an Exploration show you about your assumptions? Your plot depends on the variable named val
, but that variable will have the same value for every bar from time2 of the current day until it gets changed at time2 of the next day.