Hello,
I am wondering that, is groupby or resample operation can be done in amibroker like python??
I have 1-minute data and wanted to convert it into 30 minutes of data but want to apply my custom function on those 30, one-minute candles close price instead of just OHLC of 30 min candles. Can this thing possible with amibroker??
you can use
AFL Function Reference - SPARSECOMPRESS (amibroker.com) to query data points
OR
Multiple Time Frame support (amibroker.com) manipulate data to Higher timeframe
OR
BOTH of them together ( Eg. Do sparse and then for SUM use compressVolume in TimeFrameCompress() to higher TF ).
could you please elaborate to solve the following problem, That would be very helpful for me...
Question-
Suppose I have one year of 1-minute intraday data and I wanted to convert this into one year of 30 minutes of data BUT what we see in the usual 30-minute candle is the OHLC of 30-minute duration instead of that I want my own function to build each 30 min of the candle using thirty 1-minute candles (Let say mean of thirty 1-minute candles)
@fxshrat could you please provide some light on the question, would be very helpful
Suppose I have one year of 1-minute intraday data and I wanted to convert this into one year of 30 minutes of data BUT what we see in the usual 30-minute candle is the OHLC of 30-minute duration instead of that I want my own function to build each 30 min of the candle using thirty 1-minute candles (Let say mean of thirty 1-minute candles)
This operation can be done very easily using groupby or resample function in PYTHON,,...............Is this possible in amibroker or we have to shift to python for this??
Re-read @nsm51 answer carefully. You have been given the solution 3 posts ago. You do NOT need Python to do what. AmiBroker handles that ALL and MUCH BETTER AND FASTER.
Please provide some steps to find the solution to the said problem I think it can not be done in amibroker , I am attaching an image of the PYTHONic way of tackle the problem............ If this can be done in amibroker??
See here or example
/// @link https://forum.amibroker.com/t/groupby-or-resample-operation/24384/6
function BarMarker(tmfrm) {
local bi, result;
TimeFrameSet( tmfrm );
bi = BarIndex();
TimeFrameRestore();
bi = Nz(TimeFrameExpand(bi, tmfrm, expandPoint));
result = Ref(bi>0,-1);
return result;
}
function IntraBarAvg(array, tmfrm) {
local newbar, bars, result;
newbar = BarMarker(tmfrm);
bars = BarsSince(newbar)+1;
result = Sum(array, bars)/bars;
return result;
}
tmfrm = in15Minute;
marker = BarMarker(tmfrm);
x = IntraBarAvg(C, tmfrm);
Plot( C, "Price", colorDefault, styleBar );
Plot( x, "Running Avg", colorRed );
Plot( ValueWhen(marker, x), "Last Avg", colorYellow, styleStaircase );
Plot( marker, "", colorRed, styleHistogram | styleOwnScale | styleDashed | styleNoLabel, 0, 1 );
Thanks for your support. Can you provide some direction(some link or post) on how to use StaticVarSet in 1-min TF to store the result of the posted code and StaticVarGet in 15-min TF to call it?
There is small mistake in upper code.
Following one:
ValueWhen(marker, x)
Should be replaced by:
ValueWhen(marker, Ref(x,-1))
Follow the commented instructions in the code (of course study the code also):
/// @link https://forum.amibroker.com/t/groupby-or-resample-operation/24384/9
function BarMarker(tmfrm) {
local bi, result;
TimeFrameSet( tmfrm );
bi = BarIndex();
TimeFrameRestore();
bi = Nz(TimeFrameExpand(bi, tmfrm, expandPoint));
return Ref(bi>0,-1);
}
function IntraBarAvg(array, tmfrm) {
local newbar, bars, result;
newbar = BarMarker(tmfrm);
bars = BarsSince(newbar)+1;
result = Sum(array, bars)/bars;
return result;
}
Plot( C, "Price", colorDefault, styleBar );
//
// Usage:
// First set Chart interval being shorter than "tmfrm"
// Then set Chart interval being equal to "tmfrm"
tmfrm = in15Minute;
is_lastBar = BarIndex() == LastValue(BarIndex());
if ( Interval() < tmfrm ) { // shorter TF
marker = BarMarker(tmfrm);
x = IntraBarAvg(C, tmfrm);
last = ValueWhen(marker, Ref(x,-1));
StaticVarSet("lastAvg_"+Name(), last);
StaticVarSet("lastValAvg_"+Name(), LastValue(last));
StaticVarSet("lastValRunningAvg_"+Name(), LastValue(x));
Plot(x, "Running Avg", colorRed );
Plot(IIf(is_lastBar, x, last), "Last Avg", colorYellow, styleStaircase );
Plot(marker, "", colorRed, styleHistogram | styleOwnScale | styleDashed | styleNoLabel, 0, 1 );
} else { // longer TF
//Note: in longer TF result output last avg. value is last **running** avg of shorter TF. The rest is shifted by one bar.
last1 = IIf(is_lastBar, StaticVarGet("lastValAvg_"+Name()), StaticVarGet("lastAvg_"+Name()));
last2 = IIf(is_lastBar, StaticVarGet("lastValRunningAvg_"+Name()), Ref(last1,1));
Plot(last2, "Avg IntraBar Close", colorYellow, styleStaircase );
}
Note: in longer TF result output last avg. value is last running avg of shorter TF. The rest is shifted by one bar.
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.