Simple Coding Help - No Promise.

can somebody please help me...
i am looking for an afl that put circle/dot above the high and below the low of every 30M bar. but on a 5-minute time frame chart.

please help
 
can somebody please help me...
i am looking for an afl that put circle/dot above the high and below the low of every 30M bar. but on a 5-minute time frame chart.

please help
@primitivetrader : Hope this helps. You can select any higher TimeFrame thru Parameters. Thnx.
Code:
_SECTION_BEGIN("Selected TF Bar High Low Markings");
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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


tf = Param("Select Time frame (min)",30,1,1440,1);
tfrm=in1Minute*tf;

TimeFrameSet(tfrm);
H1 = Ref(H,-1);
L1 = Ref(L,-1);
TimeFrameRestore();

H1 = TimeFrameExpand(H1, tfrm,expandFirst);
L1 = TimeFrameExpand(L1, tfrm,expandFirst);

Plot(H1,"",colororange,styledots|stylenoline|stylenorescale);
Plot(L1,"",colorbrightgreen,styledots|stylenoline|stylenorescale);


_SECTION_END();
30MinTFHiLoMarkings.png
 
@primitivetrader : Hope this helps. You can select any higher TimeFrame thru Parameters. Thnx.
Code:
_SECTION_BEGIN("Selected TF Bar High Low Markings");
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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


tf = Param("Select Time frame (min)",30,1,1440,1);
tfrm=in1Minute*tf;

TimeFrameSet(tfrm);
H1 = Ref(H,-1);
L1 = Ref(L,-1);
TimeFrameRestore();

H1 = TimeFrameExpand(H1, tfrm,expandFirst);
L1 = TimeFrameExpand(L1, tfrm,expandFirst);

Plot(H1,"",colororange,styledots|stylenoline|stylenorescale);
Plot(L1,"",colorbrightgreen,styledots|stylenoline|stylenorescale);


_SECTION_END();
View attachment 42930
thanks a lot ! worked well
 

augubhai

Well-Known Member
Simple question - how do you round price to 0.05 in AB ? Round function outputs int.
Below generally works, but is wrong as we are multiplying by a float at the end without another round/floor/ceil.
0.05 * floor( 0.5 + price * 20 );
Ex - breaks for 9744.351. Output is 9744.351

I use AHK/python which supports round to decimal places and works well but so far unable to find answer for AB.
I use these functions in almost all my afls:

Code:
zTickSize=0.05;
//zTickSize=IIf(StrLeft(Name(),StrLen(Name())-8)=="CRUDEOIL",1,zTickSize);
function zRoundUp(zValue) {return ceil(zValue/zTickSize)*zTickSize;}
function zRoundDown(zValue) {return floor(zValue/zTickSize)*zTickSize;}
 

TracerBullet

Well-Known Member
I use these functions in almost all my afls:

Code:
zTickSize=0.05;
//zTickSize=IIf(StrLeft(Name(),StrLen(Name())-8)=="CRUDEOIL",1,zTickSize);
function zRoundUp(zValue) {return ceil(zValue/zTickSize)*zTickSize;}
function zRoundDown(zValue) {return floor(zValue/zTickSize)*zTickSize;}
So now you know it can fail ..
Code:
zTickSize=0.05;
function zRoundUp(zValue) {return ceil(zValue/zTickSize)*zTickSize;}
function zRoundDown(zValue) {return floor(zValue/zTickSize)*zTickSize;}

pricex =  9744.351;
t2 = zRoundDown(pricex) ; 

_N( Title = ( "" + t2 ) ) ;
A forum member has given another answer in pm. I dont have knowledge or inclination to understand why it might work inspite of the last div by 100 ( similar to HL's answer) - there could be some low level reason based on how FP stuff works. But anyway - anyone can check if needed

Code:
paise = 0.05;
a1    = 9744.351;
tRoundUp   = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise + paise) * 100 ) / 100;
tRoundDown = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise ) * 100 ) / 100;
 
Last edited:
Interesting discussion and a great contribution from everyone.


Code:
GfxTextOut(NumToStr(floor(20*Close)/20,13.8),1000,150);
tried this, print the close with 8 decimals and was surprised to see the above actually does not work :)


.
 
So now you know it can fail ..
Code:
zTickSize=0.05;
function zRoundUp(zValue) {return ceil(zValue/zTickSize)*zTickSize;}
function zRoundDown(zValue) {return floor(zValue/zTickSize)*zTickSize;}

pricex =  9744.351;
t2 = zRoundDown(pricex) ;

_N( Title = ( "" + t2 ) ) ;
A forum member has given another answer in pm. I dont have knowledge or inclination to understand why it might work inspite of the last div by 100 ( similar to HL's answer) - there could be some low level reason based on how FP stuff works. But anyway - anyone can check if needed

Code:
paise = 0.05;
a1    = 9744.351;
tRoundUp   = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise + paise) * 100 ) / 100;
tRoundDown = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise ) * 100 ) / 100;
I tried with Int, but it was same as using floor

.
 
Last edited:

TracerBullet

Well-Known Member
A forum member has given another answer in pm. I dont have knowledge or inclination to understand why it might work inspite of the last div by 100 ( similar to HL's answer) - there could be some low level reason based on how FP stuff works. But anyway - anyone can check if needed

Code:
paise = 0.05;
a1    = 9744.351;
tRoundUp   = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise + paise) * 100 ) / 100;
tRoundDown = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise ) * 100 ) / 100;
Fails :)

Nice way from Happy to check. RoundDown fails
Code:
paise = 0.05;
a1    = 9883.41;  // or 9883.4
tRoundUp   = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise + paise) * 100 ) / 100;
tRoundDown = ceil((Floor(a1) + int( (a1 % 1) / paise ) * paise ) * 100 ) / 100;

GfxTextOut( "" + tRoundUp,      1000,150);
GfxTextOut( "" + tRoundDown,    1000,170);
 
Last edited:
I even tried using string manipulation still its adding some floating point digits . . .

Now maybe @trash can give some solution

but that can happen only if we all show our original Amibroker licences :DD


.
 
Last edited:

HappyLife

Well-Known Member
@TracerBullet
Code:
Price = 1.3499;
A1 = frac(Price) * 100;
A2 = (Round(A1 / 5) * 5) / 100 + int(Price);
@TracerBullet , is not working
Code:
Price = 9883.44;
Set_tick = 0.05 * 100;

Get_frac = (Round((frac(Price) * 100) / Set_tick) * Set_tick)/100;

round_Up   = IIf(Get_frac >= frac(Price), Get_frac, Get_frac + (Set_tick/100)) + int(Price);
round_Down = IIf(Get_frac >= frac(Price), Get_frac - (Set_tick/100), Get_frac) + int(Price);

printf( "Price: %g ", Get_frac );
printf( "\n round_Up: %g ", round_Up );
printf( "\n round_Down: %g ", round_Down );
 
Last edited:

Similar threads