Need help with Amibroker formula

#1
Hello All,

How to get in Amibroker (15 minutes bars) HHV or LLV at needed time i.g. 10.00. Then how to use that value to open LONG or SHORT position. Next - the position closes at required TARGET PROFIT or at END of the DAY.

Many thanks
Marcin
 

singhboy

Active Member
#2
First change ur username, we dont want traderji members to indulge in erotic activities;)
 

asnavale

Well-Known Member
#4
Hello All,

How to get in Amibroker (15 minutes bars) HHV or LLV at needed time i.g. 10.00. Then how to use that value to open LONG or SHORT position. Next - the position closes at required TARGET PROFIT or at END of the DAY.

Many thanks
Marcin
Hi Marcin,

Try the following AFL. Set your chart to 15min timeframe if you want to see the results on 15-minute chart. This AFL works on any timeframe smaller than 1 hour.

-Anant

The AFL is below:

//*********************************

_SECTION_BEGIN("FirstHour Breakout");

SetChartOptions(0, chartShowDates | chartWrapTitle);


// ********************* INITIALSE PARAMETERS *********************************

F = Param("Factor", 0.5, 0.1, 10, 0.1); //Fraction of opening hourly bar range
FH = FL = 0;
Buy = Sell = Short = Cover = 0; //Required for modification of AFL later
BuyBar = SellBar = 0; //Required for modification of AFL later

CurrTime = TimeNum();
CurrDate = DateNum();

// ********************** FIND DAY's HIGH AND LOW ***************************

TimeFrameSet(inDaily);
DH_ = H;
DL_ = L;
DC_ = C;
TimeFrameRestore();

// ************************ FIND FIRST HOUR HIGH AND LOW **************************

TimeFrameSet(inHourly);
T = TimeNum();
//CutoffTime = IIf(DateNum() < 1100104, 110000, 100000);

FH = ValueWhen(T <= 100000, H, 1); //First Hour High, For dates prior to 04 Jan 2010 use T<= 110000
FL = ValueWhen(T <= 100000, L, 1); //First Hour Low, For dates prior to 04 Jan 2010 use T<= 110000
//FH = ValueWhen(T <= CutOffTime, H, 1); //First Hour High, For dates prior to 04 Jan 2010 use T<= 110000
//FL = ValueWhen(T <= CutOffTime, L, 1); //First Hour Low, For dates prior to 04 Jan 2010 use T<= 110000
// ************************* CALCULATE TARGETS AND STOP LOSS *********************

FR = FH - FL; //Range of First Hour Bar
LTgt = FH + F * FR; //Target for Long position
STgt = FL - F * FR; //Target for Short position
TimeFrameRestore();

// **************************** Convert all above Values to current time frame ***********************

DH = TimeFrameExpand(DH_, inDaily, expandFirst);
DL = TimeFrameExpand(DL_, inDaily, expandFirst);
DC = TimeFrameExpand(DC_, inDaily, expandFirst);

FHH = TimeFrameExpand(FH, inHourly, expandFirst); //First Hour High
FHL = TimeFrameExpand(FL, inHourly, expandFirst); //First Hour Low
FHR = TimeFrameExpand(FR, inHourly, expandFirst); //First Hour Range
LongTarget = TimeFrameExpand(LTgt, inHourly, expandFirst);
ShortTarget = TimeFrameExpand(STgt, inHourly, expandFirst);
LongSL = FHL; //Stop Loss for Long position
ShortSL = FHH; //StopLoss for Short position

// ****************************************** LINES AT ENTRY, EXIT, STOPLOSS, DAY HI/LOW ********************************

Bars = BarsSince(TimeNum() > 85400 AND TimeNum() < 95959);
x0 = BarCount - LastValue(Bars);
x1 = BarCount -1;
LongEntryLine = LineArray(x0, LastValue(FHH), x1, LastValue(FHH));
ShortEntryLine = LineArray(x0, LastValue(FHL), x1, LastValue(FHL));
LongTargetLine = LineArray(x0, LastValue(LongTarget), x1, LastValue(LongTarget));
ShortTargetLine = LineArray(x0, LastValue(ShortTarget), x1, LastValue(ShortTarget));

// ****************************************** PLOT CHART WITH ALL TRADING INFORMATION ********************************

_N(Title = StrFormat("1st Hr Hi/Lo Strategy for {{NAME}} ({{INTERVAL}}) {{DATE}} {{OHLCX}}\nDay High=%1.2f, Day Low=%1.2f, Day Close=%1.2f\n", DH, DL, DC)
+ EncodeColor(colorBrightGreen) + "Go Long Above " + WriteVal(FHH, 1.2) + ", Exit Long At " + WriteVal(LongTarget, 1.2) + "(Stop Loss = " + WriteVal(LongSL, 1.2) + ")\n"
+ EncodeColor(colorRed) + "Go Short Below " + WriteVal(FHL, 1.2) + ", Exit Short At " + WriteVal(ShortTarget, 1.2) + "(Stop Loss = " + WriteVal(ShortSL, 1.2) + ")\n"
+ EncodeColor(colorYellow) + "Factor = " + WriteVal(F, 1.2));

if(Status("action") == actionIndicator)
{
Plot(C,"",colorGrey50,styleCandle);
Plot(LongEntryLine, "Go Long Here", colorGreen, styleLine | styleDots);
Plot(ShortEntryLine, "Go Short Here", colorRed, styleLine | styleDots);
Plot(LongTargetLine, "Target for Long", colorYellow, styleLine);
Plot(ShortTargetLine, "Target for Short", colorYellow, styleLine);
PlotText("Go Long / Exit Short Here", x0, 1.0005 * LastValue(FHH), colorWhite);
PlotText("Go Short / Exit Long Here", x0, 0.999 * LastValue(FHL), colorWhite);
PlotText("Short Target / Cover Short Here", x0, 0.999 * LastValue(Shorttarget), colorWhite);
PlotText("Long Target / Sell Here", x0, 1.0005 * LastValue(LongTarget), colorWhite);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-30);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);
}


// ********************************** EPLORATION (Will be further coded Later) ************************

if(Status("action") == actionExplore)
{

Filter = CurrTime == 100000;
SetOption("NoDefaultColumns", True);
AddColumn(DateTime(), "Date and Time", formatDateTime);
AddColumn(FHH, "Long Trigger Price", 1.2);
AddColumn(LongTarget, "Long Target", 1.2);
AddColumn(LongSL, "SL for Long", 1.2);
AddColumn(DH, "Day High", 1.2);

AddColumn(FHL, "Short Trigger Price", 1.2);
AddColumn(ShortTarget, "Short Target", 1.2);
AddColumn(ShortSL, "SL for Short", 1.2);
AddColumn(DL, "Day Low", 1.2);


}

_SECTION_END();

//**************************************

 
#6
Hi Marcin,

Try the following AFL. Set your chart to 15min timeframe if you want to see the results on 15-minute chart. This AFL works on any timeframe smaller than 1 hour.

-Anant

Many thanks again.

One more favour. Why it works in one day only? How to expend it for all days?
The backtest does not work, why?

Thanks in advance.
 
#7
Hi Marcin,

Try the following AFL. Set your chart to 15min timeframe if you want to see the results on 15-minute chart. This AFL works on any timeframe smaller than 1 hour.

-Anant

Many thanks again.

One more favour. Why it works in one day only? How to expend it for all days?
The backtest does not work, why?

Thanks in advance.
Probably because it is a "FirstHour Breakout" .afl
 
#8
Hello Seniors.

A request for an AFL.

Need Afl to get Values of Open,High,Low and Close of the first half hour or Time 9:30
Please help me regarding the AFL to get the values @ 9:30.am

Thanks in Advance
 

asnavale

Well-Known Member
#9
Hi Marcin,

Try the following AFL. Set your chart to 15min timeframe if you want to see the results on 15-minute chart. This AFL works on any timeframe smaller than 1 hour.

-Anant

Many thanks again.

One more favour. Why it works in one day only? How to expend it for all days?
The backtest does not work, why?

Thanks in advance.
This is an incomplete work. I had made this AFL for a friend of mine who is also a member here. As he had tested the system manually he just wanted an AFL which shows the required values on trading day (the current day). So, I did not make it to show the levels for all days. As it is showing the values and lines only on the last day it is not possible to back test it. Of course, you can use 'Bar Replay' and see it appearing each day. But that is a time consuming excercise.

-Anant
 

asnavale

Well-Known Member
#10
Hello Seniors.

A request for an AFL.

Need Afl to get Values of Open,High,Low and Close of the first half hour or Time 9:30
Please help me regarding the AFL to get the values @ 9:30.am

Thanks in Advance
You can change the values in the AFL I gave above. The changes required are:

FH = ValueWhen(T <= 093000, H, 1);
FL = ValueWhen(T <= 093000, L, 1);

Another way is to set the timeframe to 30 minutes and the values of first bar are the values you need. For this you do not require any AFL.

-Anant
 

Similar threads