Simple Coding Help - No Promise.

SwagatN

Well-Known Member
Dear travi bro,
am totally dumb in tech :) actually I want 34ema of 1m tf on 3m tf chart
@travi is right, This is a limitation of Amirbroker while dealing with timeframe.

From amirbroker guide -

"Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames. "

So the close work around will be what @manojtalreja suggested i.e. plotting a equivalent value moving average on 3m
which is 11 bar moving average for 3m chart.
 

VJAY

Well-Known Member
Why not plot 11 or 12 ema directly on 3 min chart. It would be 33 or 36 Ema of 1 min timeframe which should be close to what you are looking to achieve.
@travi is right, This is a limitation of Amirbroker while dealing with timeframe.

From amirbroker guide -

"Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames. "

So the close work around will be what @manojtalreja suggested i.e. plotting a equivalent value moving average on 3m
which is 11 bar moving average for 3m chart.
AFAIK, Amobroker does not support lower timeframe data in higher timeframe chart. But higher timeframe data is available in lower timeframe chart.

I use Amibroker 5.40, so my knowledge may be outdated.
Thanks a lot friends...
 

augubhai

Well-Known Member
There is one more method that I had tried... On lower timeframe charts, I had compressed data to create higher timeframe charts. My main objective here was to create time-shifted higher timframe chart, but I guess that can be also used to achieve @VJAY requirement.

But that solution is resource intensive, and very inelegant.

Here's the code:
Bugs usually happen in the compression logic of my code. I am pasting it here, so I can retrieve it whenever I need.

Period=5;
SetBarsRequired( sbrAll );
ShiftBase=0;
Shift=0;
Shift=IIf(Name()=="YESBANK13NOVFUT",1,Shift);
Shift=IIf(Name()=="DLF13NOVFUT",2,Shift);
Shift=IIf(Name()=="SBIN13NOVFUT",3,Shift);
Shift=IIf(Name()=="AXISBANK13NOVFUT",4,Shift);
Shift=IIf(Name()=="ICICIBANK13NOVFUT",5,Shift);
Shift=Shift+ShiftBase;
MinuteNum=Hour()*60+Minute();
shiftMinuteNum=MinuteNum-Shift;
newMinuteNum=floor(shiftMinuteNum/Period);
newBarStart=BarIndex()==0 OR newMinuteNum!=Ref(newMinuteNum,-1);
newBarEnd=BarIndex()==LastValue(BarIndex()) OR newMinuteNum!=Ref(newMinuteNum,1);
oldBarNum=Cum(1);
newBarNum=Cum(newBarStart);
oldNumbars=LastValue(oldBarNum);
newNumbars=LastValue(newBarNum);

for( i=0, j=(oldNumbars-newNumbars); i<BarCount; i++ )
{
if(newBarStart)
{
jo[j]=O;
jh[j]=H;
jl[j]=L;
}
else
{
jh[j]=Max(H,jh[j]);
jl[j]=Min(L,jl[j]);
}
jc[j]=C;


if(newBarEnd)
{
j++;
}
}


Open=O=jo;
High=H=jh;
Low=L=jl;
Close=C=jc;
Avg=(H+L+C)/3;
 

travi

Well-Known Member
@travi is right, This is a limitation of Amirbroker while dealing with timeframe.
Technically, its not a limitation but "Logical by Design" :D:D

The same applies to periodicity setting of Analysis window.

Both Charts and Periodicity should define the lowest TF that's to be worked on for that case, and all additional logic built on a Higher TF. That is also logically linked with the Base Time interval of DB.
all settings need to be I sync, ofc, that TF data should also be supplied.
 
Need coding help for ORB strategy :

I have ORB strategy which will mark high and low level at breakout time.
But I want to skip first 15 min candle from ORB calculation ..
How can write it in afl to skip first candle ?


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Plot( C, "Close", colorDefault, styleCandle );
NewDay = Day()!= Ref(Day(), -1);
EndDay = (Day()!= Ref(Day(), 1));
DayH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); // low
DayC = TimeFrameGetPrice("C", inDaily, -1); // close
DayO=ValueWhen(NewDay,O,1);//Todays Open
GPUP=DayO>DayH;
GPDN=DayO<DayL;
GPUP=ExRem(GPUP,EndDay);
GPDN=ExRem(GPDN,EndDay);
Ingpup=Flip(gpup,endday);
IngpDn=Flip(gpdn,endday);

BT = Param("BreakoutTime",94500,09000,120000);
target = Param("Target in Percentage",1,0.1,10,0.1);
HighValue=HighestSince(newDay,H);
LowValue=LowestSince(newDay,L);
RangeHigh = ValueWhen(Cross(TimeNum() , BT), HighValue);
RangeLow = ValueWhen(Cross(TimeNum() , BT), LowValue);
Buy = TimeNum() > BT AND TimeNum() < 150000 AND Cross(H,RangeHigh);
Short = TimeNum() > BT AND TimeNum() < 150000 AND Cross(RangeLow,L);
Buy= ExRem(Buy,newDay);
Short = ExRem(Short,newday);
Sell = Cross(H,RangeHigh*(1+target/100)) OR TimeNum()>151400 ;
Cover = Cross(RangeLow*(1-target/100),L) OR TimeNum()>151400 ;
Sell = ExRem(Sell,Buy);
Cover = ExRem(Cover,Short);

BuyPrice=ValueWhen(Buy,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
SellPrice=ValueWhen(Sell,C);

Long = Flip(Buy,Sell);
Shrt = Flip(Short,Cover);
SetPositionSize(100,spsShares);
Plot(RangeHigh*(1+target/100),"Long Target",colorBlue,styleLine| styleDots);
Plot(RangeLow*(1-target/100),"Short Target",colorBlue,styleLine| styleDots);
Plot(RangeHigh,"Range High",colorGreen,styleLine| styleDots);
Plot(RangeLow,"Range Low",colorRed,styleLine| styleDots);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,Low,-10);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,High,-10);
PlotShapes(IIf(Cover, shapeUpTriangle, shapeNone),colorGreen, 0,High,-10);
PlotShapes(IIf(Sell, shapeUpTriangle, shapeNone),colorRed, 0,Low,-10);
dist = 1.5*ATR(10); for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n"+ " @" + C[ i ], i, L[ i ]-dist, colorGreen, colorYellow );
if( Short ) PlotText( "Short\n" + " @" + C[ i ], i, H[ i ]+dist, colorRed, colorYellow );
if( Cover ) PlotText( "Cover\n"+ " @" + C[ i ], i, L[ i ]-dist, colorGreen, colorYellow );
if( Sell ) PlotText( "Sell\n" + " @" + C[ i ], i, H[ i ]+dist, colorRed, colorYellow );

}
AddColumn(Buy,"Buy"); AddColumn(Sell,"sell"); AddColumn(Short,"short"); AddColumn(Cover,"cover");
 
Dear friends,
If any one know the AFL code for showing lower tf EMA on higher tf chart ?Please share....
eg.I want to get 34 ema of 1TF on 3 tf chart.....
There is a juggad mentioned by "Sherbaaz" in some other forum "the great indian jugaad is to plot multi time period candle. i plotted on 1 min chart 3 minute candle and then plotted 20 ema on this chart as base interval in 1 min now i can have 3 min candles with 1 min 20 ema "

AFL for plotting MTF candles is available on wisestocktrader
 
I want to highlight candle containing 2:01 PM time with a different color. How do I do it?
Sir Will this do!
Code:
_SECTION_BEGIN("Candle Color @ 14:01 ");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Bar1401 = TimeNum() == 140159;

cc=    IIF(C>O,IIf(Bar1401,colorYellow,colorLime),
    IIF(C<O,IIf(Bar1401,colorYellow,colorRed),Null));

Plot(C,"Close",Cc,styleCandle | ParamStyle("Style") | GetPriceStyle() ,0,0,0,0);

_SECTION_END();
 

Similar threads