Australian (ASX) Stock Market Forum

Amibroker FAQ

I'm trying to get HHV of first 5 bars of the day on EUR/USD (timeframe 1 H). I know how to get the first bar of the day and value for first high:

Code:
FirstBar = DateNum() !=  Ref(DateNum(),-1);
FirstHigh = ValueWhen(FirstBar ,H);

but don't know how to get HHV of first 5 bars. Thanks for prompt.
 
I'm trying to get HHV of first 5 bars of the day on EUR/USD (timeframe 1 H). I know how to get the first bar of the day and value for first high:

Code:
FirstBar = DateNum() !=  Ref(DateNum(),-1);
FirstHigh = ValueWhen(FirstBar ,H);

but don't know how to get HHV of first 5 bars. Thanks for prompt.


Code:
bars = 5;

dn = DateNum();
newday = dn != Ref(dn,-1); 
FirstHigh = ValueWhen( Barssince( newday ) == bars-1, HHV( H, bars ) );

Plot( C, "Price", colorDefault, styleCandle, Null, Null, 0, 1 ); 
Plot( FirstHigh, "HHV" + bars, colorGreen, styleStaircase | styleDashed, Null, Null, 0, 1 );
 
Code:
bars = 5;

dn = DateNum();
newday = dn != Ref(dn,-1); 
FirstHigh = ValueWhen( Barssince( newday ) == bars-1, HHV( H, bars ) );

Plot( C, "Price", colorDefault, styleCandle, Null, Null, 0, 1 ); 
Plot( FirstHigh, "HHV" + bars, colorGreen, styleStaircase | styleDashed, Null, Null, 0, 1 );

Thanks a lot. It works :)
 
trash (or anyone else),

Would you be interested in a small job? Will pay (small) fee. Uses AHK (AutoHotKey macro software).
I've done half of it but got stuck. Involves getting orders into TWS from a csv file.
 
I implemented simple breakout from range (from first 10 bars during a day) as below and try to add break even (after reaching 20% of target) to the code but I don't know if it is possible without using loops. Thanks for prompt :)

Code:
SetTradeDelays(0,0,0,0);

bars= 10;

firstBar = DateNum() !=  Ref(DateNum(),-1);

max_from_bars = ValueWhen(BarsSince(firstBar)==bars-1, HHV(H,bars));
min_from_bars = ValueWhen(BarsSince(firstBar)==bars-1, LLV(L,bars));

range = max_from_bars - min_from_bars;

Buy = H > max_from_bars AND BarsSince(firstBar)>=bars ;
Sell =  L < min_from_bars OR H >= max_from_bars+range;
Short = L < min_from_bars AND BarsSince(firstBar)>=bars;
Cover =  H > max_from_bars OR L <= min_from_bars-range;

BuyPrice = Max(O,max_from_bars);
SellPrice = 0;
ShortPrice = Min(O,min_from_bars);
CoverPrice = 0;

ApplyStop(stopTypeProfit,stopModePoint,range);
ApplyStop(stopTypeLoss,stopModePoint,range);
 
I implemented simple breakout from range (from first 10 bars during a day) as below and try to add break even (after reaching 20% of target) to the code but I don't know if it is possible without using loops. Thanks for prompt :)
Do you know ValueWhen references the future and is therefore misleading in backtesting?
 
Not necessarily. Valuewhen can reference historical data.

Yes in this case it defaults to n = 1.

Firstbar = any day other than yesterday (random day)
ValueWhen BarsSince Firstbar is equivalent to 9 (any bar 9 days from random day), returns the HHV(H, 10), most recently (1)

Is not ---- Ref(HHV(H, 10), -1); the same?
 
Do you know ValueWhen references the future and is therefore misleading in backtesting?

I'm sorry to say but that's nonsense.

Yes in this case it defaults to n = 1.

No. All positive n values equal or higher than 1 in ValueWhen(EXPRESSION, ARRAY, n = 1) reference past occurrences! If you set n to 5 then it would look for the 5-th past occurrence. n = 1 is just default if you don't define any other n value yourself. Nothing more nothing less.

https://www.amibroker.com/guide/afl/valuewhen.html

Firstbar = any day other than yesterday (random day)
ValueWhen BarsSince Firstbar is equivalent to 9 (any bar 9 days from random day), returns the HHV(H, 10), most recently (1)

Is not ---- Ref(HHV(H, 10), -1); the same?



The code

Code:
bars = 5;

dn = DateNum();
newday = dn != Ref(dn,-1); 
FirstHigh = ValueWhen( Barssince( newday ) == bars-1, HHV( H, bars ) );

is for intra-day data but not for EOD! It makes no sense using it on EOD data.
The code pinpoints that single bar that has past the same number of bars being set in 'bars' variable since new day. It is an equality check. Then from that point backwards it looks for the highest defined array of that day only. If there is a new day then it starts again. ValueWhen keeps "currently" found value available until there is a new one being true. http://i.imgur.com/x0EENHA.png

There is no "looking into future" and random involved in upper code.
 
If you wanna do something similar on EOD bars then you would have to change to something like the following code

Code:
bars = 5;

mth = Month();
newmonth = mth != Ref(mth,-1); 
FirstHigh = ValueWhen( Barssince( newmonth ) == bars-1, HHV( H, bars ) );

Plot( C, "Price", colorDefault, styleCandle, Null, Null, 0, 1 ); 
Plot( FirstHigh, "HHV" + bars, colorGreen, styleStaircase | styleDashed, Null, Null, 0, 1 );
 
I know that :). Do do you have idea if it's possible to add break even after reaching 20% of target without loops to my intraday code?
Code:
SetTradeDelays(0,0,0,0);

bars= 10;

firstBar = DateNum() !=  Ref(DateNum(),-1);

max_from_bars = ValueWhen(BarsSince(firstBar)==bars-1, HHV(H,bars));
min_from_bars = ValueWhen(BarsSince(firstBar)==bars-1, LLV(L,bars));

range = max_from_bars - min_from_bars;

Buy = H > max_from_bars AND BarsSince(firstBar)>=bars ;
Sell =  L < min_from_bars OR H >= max_from_bars+range;
Short = L < min_from_bars AND BarsSince(firstBar)>=bars;
Cover =  H > max_from_bars OR L <= min_from_bars-range;

BuyPrice = Max(O,max_from_bars);
SellPrice = 0;
ShortPrice = Min(O,min_from_bars);
CoverPrice = 0;

ApplyStop(stopTypeProfit,stopModePoint,range);
ApplyStop(stopTypeLoss,stopModePoint,range);
 
Some help please.

I'm testing on a weekly time frame.

I want to ensure my Buyprice <=H and >=L on a daily time frame.

I've tried priceboundcheck and TimeFrameSet(InDaily), but no luck.
 
Some help please.

I'm testing on a weekly time frame.

I want to ensure my Buyprice <=H and >=L on a daily time frame.

I've tried priceboundcheck and TimeFrameSet(InDaily), but no luck.
As far as I know you should use daily time frame to test and use:
TimeFrameSet(inWeekly);
//your calculations
TimeFrameRestore();
 
Top