Afl Error help

lemondew

Well-Known Member
#1
Can someone help out in this one
Getting the following error :

Error 31. Syntax error, unexpected $end, expecting WHILE Formulas\Custom\buy42_3.afl 7 1



Heres the code

Code:
do = TimeFrameGetPrice("O", inDaily, 0 );
do20 = do +20;
dp = ValueWhen (Cross(H,do20),C);
Buy = Cross(L,dp-10);
c315 = ValueWhen(TimeNum()== 152000,C);
Sell = Cross(BuyPrice-20,L) or c315;
 

doss186

Well-Known Member
#2
do is a system reserved command, the following code works

_SECTION_BEGIN("Price");
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() );

doo = TimeFrameGetPrice("O", inDaily ,0);
do20 = doo +20;
dp = ValueWhen (Cross(H,do20),C);
Buy = Cross(L,dp-10);
c315 = ValueWhen(TimeNum()== 152000,C);
Sell = Cross(BuyPrice-20,L) OR c315;

PlotShapes( shapeUpArrow * Buy, colorGreen, 0, Low );

PlotShapes( shapeDownArrow * Sell, colorRed, 0, High );

_SECTION_END();
 

lemondew

Well-Known Member
#3
Thanks I think I didnt get the code right though.

This is what I am trying to do for back test. On a day if we go 20 points above open(o +20). Then buy is activated but we buy if get entry 10 points below (i. e O+10).

We have a SL of 20. And hold till 3:20. Not for next day. Only 1 trade a day.

If I have to write a code in an other language it would be something like this


sig = 0;
buysignal = 0;
sellsignal= 0;


//if I can loop through each bars and get OHLC for each bar

for( i = 0; i < Totalbars in chart ; i++ )
{
if ((i%372)==0) {

//new day assuming 9:17 open and 3:29 close 372 1 min bars
ptr = Open + 20; //20 points more than open
sig = 0;
buysignal = 0;
sellsignal= 0;
}



if ( (buysignal==0) AND (sig ==1) AND (Low<= ptr-10) )
{
buy = Low;
buysignal =1;
}

if ( High >= ptr )
sig = 1;

if ( (buysignal ==1) AND (Low <= ptr-30) ){
sell = Low;
sellsignal =1;
}
if ((buysignal ==1) AND (sellsignal ==0) AND (i%372)==371)
sell = close;

//closing bar since 372 1 min bars
}








do is a system reserved command, the following code works

_SECTION_BEGIN("Price");
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() );

doo = TimeFrameGetPrice("O", inDaily ,0);
do20 = doo +20;
dp = ValueWhen (Cross(H,do20),C);
Buy = Cross(L,dp-10);
c315 = ValueWhen(TimeNum()== 152000,C);
Sell = Cross(BuyPrice-20,L) OR c315;

PlotShapes( shapeUpArrow * Buy, colorGreen, 0, Low );

PlotShapes( shapeDownArrow * Sell, colorRed, 0, High );

_SECTION_END();
 
Last edited:

lemondew

Well-Known Member
#4
Can I be able to loop through each 1 min bar in amibroker or any better way to achieve this. Thanks in advance
 

copypasteaee

Humbled by Markets
#5
Get bars printed in day
Get open price of day
Condition 1 =(hhv, no of bars today) >=open +20
Buy = condition1 and L<= open+10
 

lemondew

Well-Known Member
#6
fixed it guys. The language has many functions which are designed to work only for a given way. Thanks anyways.

Removed valuewhen function and sell on cross functions. Used ApplyStop and a different code for limiting the number of trades.
 

Similar threads