After a search on AFL library and the forum,
I am trying to get the highest high value since open time 93000 each day. I am using OHLC 1 minute bars. The goal is to mark a drop from intraday highesthigh as a trigger.
I am having trouble getting the code to generate any trades in backtesting.
Any help is much appreciated.
tn = TimeNum();
StartTime = 93000;
Endtime = Now(4);
StartBar = tn == StartTime;
EndBar = tn == Endtime;
Highestsinceopen = ValueWhen( EndBar, HighestSince( StartBar, High ) );
Lowestsinceopen = ValueWhen( EndBar, LowestSince( StartBar, Low ) );
Buy = Close < 0.99 * highestsinceopen;
Sell = profittarget ;
You are using equality check for tn
. So it timenum does not exist in the TimeNum() array then it will result in NULL return. Also NOW uses your operating system's date/time.
You may do like this (you can change between ValueWhen
and IIf
mode in line 5)
/// You can change between ValueWhen and IIf mode in line 5
/// @link https://forum.amibroker.com/t/current-intraday-high-value/17840/2
StartTime = 93000;
Endtime = 235959;
ValueWhen_mode = false; // false -> Iif mode, true -> ValueWhen mode
tn = TimeNum();
tn_range = tn >= StartTime AND tn <= EndTime;
new_range = tn_range != Ref(tn_range, -1 );
if ( ValueWhen_mode ) {// ValueWhen mode
Highestsinceopen = ValueWhen(tn_range, HighestSince(new_range, High) );
Lowestsinceopen = ValueWhen(tn_range, LowestSince(new_range, Low) );
} else { // IIf() mode
Highestsinceopen = IIf(tn_range, HighestSince(new_range, High), Null);
Lowestsinceopen = IIf(tn_range, LowestSince(new_range, Low), Null);
}
Buy = Close < 0.99 * highestsinceopen;
Sell = 0;//profittarget ;
// ApplyStop(....
Plot( C, "Price", colorDefault, styleBar );
Plot( Highestsinceopen, "Highestsinceopen", colorGreen, styleStaircase );
Plot( Lowestsinceopen, "Lowestsinceopen", colorRed, styleStaircase );
//PlotShapes( Buy * shapeUpArrow, colorGreen, layer = 0, L );
Also I see in post #1 that you want to exit via set profit target. It is unknown variable but I suspect that you want to exit at fix target level since Buy. For that you should rather use ApplyStop().


4 Likes
Thank you for the help and great explanation
1 Like