Missing buy sell variable assignment

#1
Hi,

I tried back testing an Afl it says Buy sell assignment missing
so how do one adds thats . i gave a rough try but that ddin;t work

i tried
buy = buffer_line_up ;
sell =buffer_line_down; but that didn;t work

things needed:-
Buy sell assignment so result be displayed in backtest.

Buy signal is when bar crosses and buffer line turns Blue
sell signal is when buffer line is red

Sound alert needed when it gives buy signal
PlaySound("C:\\Program Files\\AmiBroker\\sound\\buy.wav");

Thx for read and help in advance .:)


Code:
procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice)
{
global buffer_line_down;
global buffer_line_up;
buffer_line_down = Null;
buffer_line_up = Null;
 
PHASE_NONE = 0;
PHASE_BUY = 1;
PHASE_SELL = -1;
 
phase=PHASE_NONE;
band_upper = 0;band_lower = 0;
   
for(i = ATR_Period + 1; i < BarCount; i++)
{
    band_upper = CalcPrice[i] + ATR_Multiplier * tr[i];
    band_lower = CalcPrice[i] - ATR_Multiplier * tr[i];
     
    if(phase==PHASE_NONE)
    {
        buffer_line_up[i] = CalcPrice[i];
        buffer_line_down[i] = CalcPrice[i];
    }
    if(phase!=PHASE_BUY && Close[i]>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1])) 
    {
        phase = PHASE_BUY;
        buffer_line_up[i] = band_lower;
        buffer_line_up[i-1] = buffer_line_down[i-1];
    }
    if(phase!=PHASE_SELL && Close[i]<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))
    {
        phase = PHASE_SELL;
        buffer_line_down[i] = band_upper;
        buffer_line_down[i-1] = buffer_line_up[i-1];
    }   
    if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )
    {
        if(band_lower>buffer_line_up[i-1]) 
        {
            buffer_line_up[i] = band_lower;
        }
        else
        {
            buffer_line_up[i] = buffer_line_up[i-1];
        }
    }
    if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )
    {
        if(band_upper<buffer_line_down[i-1])
        {
            buffer_line_down[i] = band_upper;
        }
        else
        {
            buffer_line_down[i] = buffer_line_down[i-1];
        }
    }
}
}
 
SetBarsRequired(sbrAll,sbrAll);
 
TrendMode = ParamToggle("TrendMode","Off|On",0);
ATR_Multiplier = Param("ATR_Multiplier",2,0.1,10,0.1);
ATR_Period = Param( "ATR_Period",5,1,20,1);
tr = ATR(ATR_Period);
 
CalcPrice = (H+L)/2;
calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice);
 
SetChartOptions(0,chartShowDates);
Plot(C,"C",colorWhite,64);
Plot(buffer_line_up,"\ntu",ColorRGB(28,134,238),styleThick);
Plot(buffer_line_down,"\ntd",ColorRGB(205,51,51),styleThick);
 
Plot( 2,"",IIf(buffer_line_up,colorGreen,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
Plot( 4,"",IIf(buffer_line_down,colorRed,colorBlack),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
 
#2
Please include the following in your afl


Buy = Cross(C,buffer_line_up);
Sell = Cross(buffer_line_down,C);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

PlotShapes(SELL* shapeDownarrow, colorRed,0,H,-20);
AlertIf( Buy , "SOUND C:\\Windows\\Media\\buy.wav", "Audio alert", 1 );
PlotShapes(BUY * shapeUparrow, colorLime,0,L,-20);
AlertIf( Sell , "SOUND C:\\Windows\\Media\\sell.wav", "Audio alert", 1 );
 

Similar threads