How to show MA5 value for last candle

Dear all,
Please help me.
I want to try write afl code for explorer stock with criteria cross ma5 and ma20 (from to date) for a week ago. Let say the some stock signal occurs 3-5 days ago. How to i show current day ma5 and ma20 value .

Thank in advance
Nyoman

@nyomanjs,

See documentation on how to create own exploration
http://www.amibroker.com/guide/h_exploration.html


So e.g.

/// @link https://forum.amibroker.com/t/how-to-show-ma5-value-for-last-candle/19700/3
ma1 = MA(C, 5);
ma2 = MA(C, 20);
crss = Cross(ma1, ma2);

format = 1.2;
SetOption( "NoDefaultColumns", True );

AddTextColumn( Name(), "Ticker", 1.0 );
AddColumn(dt = DateTime(), "Current Date/Time", formatDateTime);
AddColumn(ValueWhen(crss, dt), "Last Cross Date", formatDateTime, colorWhite, colorDarkRed);
AddColumn(ValueWhen(crss, ma1), "MA5 Value@Cross", format);
AddColumn(ValueWhen(crss, ma2), "MA20 Value@Cross", format);
AddColumn(ma1, "MA5 Current", format);
AddColumn(ma2, "MA20 Current", format);

Filter = Status( "lastbarinrange" ); 

13

2 Likes

Wow Thank you so much, i will try it first.

Regards
Nyoman

That's works for me. But how to limit cross no more than 14 bar or 2 weeks ago.
And how to counting bar to cross ma occurs from current bar.

Need your help.

Thanks a lot

This is actually my coding :
ma5 = MA(C, 5);
ma20 = MA(C, 20);
gc = Cross(ma5, ma20);

VolMin=10000000;
ValueMin = 50000000000;
ValueTrx = ((O+H+L+C)/4) * V; //value transaksi

Filter = gc AND (ValueTrx>ValueMin OR Volume>volMin);

AddColumn(ma5, "MA5@GC", 1.2);
AddColumn(ma20, "MA20@GC", 1.2);
AddColumn(Ref(ma5,60), "Current MA5", 1.2);
AddColumn(Ref(ma20,60), "Current MA20", 1.2);

Filter using base on my criteria (signal) and then in window explorer like screen capture below
image

Temporary give me a valid value of current MA5 and MA20 but sometime wrong value.

Need your help

Thank in advance

What value do you intend to output here?
Using Ref( x, 60) is just going to return the value 60 periods ago from that bar so you will not get the intended result.

there is for last candle (future bar from MA gc occurs)
Like my post before i intent to get ma value for current bar.

Thank you