Australian (ASX) Stock Market Forum

Amibroker FAQ

I want it to buy/sell at the cross of Value4 and Trigger, when below/above the buylevel/selllevel.

This line of code works just fine out of another system

" BuyLevel = Optimize( "BuyLevel", 28, 5, 30, 1 );

Buy = RSI < BuyLevel;
Sell = RSI > 50;"

So whats the difference between that and what I had in-
"Buy = Cross (Value4, Trigger) < BuyLevel;
Sell = Cross (Trigger, Value4) > SellLevel;"
 
I want it to buy/sell at the cross of Value4 and Trigger, when below/above the buylevel/selllevel.

This line of code works just fine out of another system

" BuyLevel = Optimize( "BuyLevel", 28, 5, 30, 1 );

Buy = RSI < BuyLevel;
Sell = RSI > 50;"

So whats the difference between that and what I had in-
"Buy = Cross (Value4, Trigger) < BuyLevel;
Sell = Cross (Trigger, Value4) > SellLevel;"

As was said earlier:

cross(a,b) is a boolean, it can be either true or false, 0 or 1, that's it.

So to say cross(a,b) < 40, makes no sense.

To say RS1 < 40 is fine, as RSI values can range from 0 to 100.
 
As was said earlier:

cross(a,b) is a boolean, it can be either true or false, 0 or 1, that's it.

So to say cross(a,b) < 40, makes no sense.

To say RS1 < 40 is fine, as RSI values can range from 0 to 100.

OK! Im down with that, but how then, do I write those buy/sell signals to buy/sell at the chosen level when they cross plz?
 
Hi guys,

Fantastic thread.

I'm having a problem with a Sell within a FOR loop. I use the FOR loop as a kind of trailing stop. I have the statement 'Sell = 1' within the loop but the trade never closes. Through some debugging, I know that it gets to that part of the code but I'm not sure what I'm doing wrong.

It looks a bit complicated but I think the problem lies near the end (the last if.else section)

Code:
Buy = xxxx;
Sell = yyyy;

stoppc = 20; // percent
stoplevel = (100-stoppc)/100;
trailstop = 0;
trailARRAY = Null;
OpenPos = 0;

for (i=0; i<BarCount;i++)
{
	if(trailstop==0 AND Buy[i])		// if buy today (trailstop will be 0 at this point. SellFilter must therefore be off)
	{
		OpenPos = 1;
	}
	else				// if not initial buy, remove excess buy signals
	{
		Buy[i] = 0;	
	}
	if(OpenPos == 1)
	{
		if(Sellfilter[i]=0)	// if in trade and sellfilter is off
		{
			trailstop = 0;			// reset trailstop	
		}
		else			// sellfilter must be on
		{
			if(trailstop == 0)	// in trade, sell filter on but SL initially 0
			{
				trailstop	== Low[i] * stoplevel; 	// set SL to % below low
				trailARRAY[i] = trailstop;
			}
			else		// in trade, sellfilter on, trailstop previously set
			{	
				if(Close[i] < trailstop)	// if close lower than stop - exit trade
				{
                                        // !!! gets here but trade never closes !!!

					Sell[i] = 1;		//exit trade - 
					OpenPos = 0;		//not in trade anymore
					trailstop = 0;		//reset SL
				}
				else	// in trade, sellfilter on, trailstop previously set, still in trade
				{
					trailstop = max(trailstop, Low[i] * trailstop; // SL is higher of the two - never lower
					trailARRAY[i] = trailstop;
				}
			}
		}
	}
}

I'm pretty new to amibroker so I'm not sure whether its a simple coding error or my understanding is way off.
 
Hi guys,

Fantastic thread.

I'm having a problem with a Sell within a FOR loop. I use the FOR loop as a kind of trailing stop. I have the statement 'Sell = 1' within the loop but the trade never closes. Through some debugging, I know that it gets to that part of the code but I'm not sure what I'm doing wrong.

It looks a bit complicated but I think the problem lies near the end (the last if.else section)

Code:
Buy = xxxx;
Sell = yyyy;

stoppc = 20; // percent
stoplevel = (100-stoppc)/100;
trailstop = 0;
trailARRAY = Null;
OpenPos = 0;

for (i=0; i<BarCount;i++)
{
	if(trailstop==0 AND Buy[i])		// if buy today (trailstop will be 0 at this point. SellFilter must therefore be off)
	{
		OpenPos = 1;
	}
	else				// if not initial buy, remove excess buy signals
	{
		Buy[i] = 0;	
	}
	if(OpenPos == 1)
	{
		if(Sellfilter[i]=0)	// if in trade and sellfilter is off
		{
			trailstop = 0;			// reset trailstop	
		}
		else			// sellfilter must be on
		{
			if(trailstop == 0)	// in trade, sell filter on but SL initially 0
			{
				trailstop	== Low[i] * stoplevel; 	// set SL to % below low
				trailARRAY[i] = trailstop;
			}
			else		// in trade, sellfilter on, trailstop previously set
			{	
				if(Close[i] < trailstop)	// if close lower than stop - exit trade
				{
                                        // !!! gets here but trade never closes !!!

					Sell[i] = 1;		//exit trade - 
					OpenPos = 0;		//not in trade anymore
					trailstop = 0;		//reset SL
				}
				else	// in trade, sellfilter on, trailstop previously set, still in trade
				{
					trailstop = max(trailstop, Low[i] * trailstop; // SL is higher of the two - never lower
					trailARRAY[i] = trailstop;
				}
			}
		}
	}
}

I'm pretty new to amibroker so I'm not sure whether its a simple coding error or my understanding is way off.



Haven't looked closely but possibly because sellprice is missing

Sell = 1; //exit trade -
SellPrice = trailstop;


Otherwise look here at sample code http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/
 
Haven't looked closely but possibly because sellprice is missing

Sell = 1; //exit trade -
SellPrice = trailstop;


Otherwise look here at sample code http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/


Thanks Trash,

I've tried those lines of code and unfortunately it still didn't work. I actually modelled my stop loss loop on the link you provided. The stop loss plot looks correct and there is even a red arrow over the bar where it should have exited. It just doesn't exit the trade. I've really hit a brick wall here.

I'm actually trying to write code for Nick Radge's Yearly High and the for loop is my implementation of the stop loss with the 75 day XAO filter. I could use the standard apply stop function but I want the stop to 'reset' each time the filter turns off.

I can post it all up but I thought just the 'for' loop would be good enough.
 
Thanks Trash,

I've tried those lines of code and unfortunately it still didn't work. I actually modelled my stop loss loop on the link you provided. The stop loss plot looks correct and there is even a red arrow over the bar where it should have exited. It just doesn't exit the trade. I've really hit a brick wall here.

I'm actually trying to write code for Nick Radge's Yearly High and the for loop is my implementation of the stop loss with the 75 day XAO filter. I could use the standard apply stop function but I want the stop to 'reset' each time the filter turns off.

I can post it all up but I thought just the 'for' loop would be good enough.

Then there are bugs elsewhere in your code

for example this line
trailstop == Low * stoplevel;

should be
trailstop = Low * stoplevel;

Then this is wrong
Sellfilter = 0

should be
Sellfilter == 0

and does that make sense?
trailstop = Max( trailstop, Low * trailstop );
should rather be
trailstop = Max( trailstop, Low * stoplevel );

Haven't looked at other stuff, could be more logical errors.
 
Then there are bugs elsewhere in your code

for example this line
trailstop == Low * stoplevel;

should be
trailstop = Low * stoplevel;

Then this is wrong
Sellfilter = 0

should be
Sellfilter == 0

and does that make sense?
trailstop = Max( trailstop, Low * trailstop );
should rather be
trailstop = Max( trailstop, Low * stoplevel );

Haven't looked at other stuff, could be more logical errors.



Thanks for your help Trash.

I'll have a look to see if those extra '=' are still in there. I remember making that mistake at least once so I may have left one in (conversely, I may have already fixed them up and posted early,bug-riddled code).

It seems from what you're saying its more than likely a coding/logic error. That's fine because at least I know I'm on the right track and just need to iron out a few bugs. I think if I was trying to do something in a way that wasn't in line with the way Amibroker works, you probably would've pointed it out already.

I'll have a look at the code again and let you know.
 
Thanks for your help Trash.

I'll have a look to see if those extra '=' are still in there. I remember making that mistake at least once so I may have left one in (conversely, I may have already fixed them up and posted early,bug-riddled code).

It seems from what you're saying its more than likely a coding/logic error. That's fine because at least I know I'm on the right track and just need to iron out a few bugs. I think if I was trying to do something in a way that wasn't in line with the way Amibroker works, you probably would've pointed it out already.

I'll have a look at the code again and let you know.



OK, here's the entire code:

Code:
//'New Yearly Highs' 
//Setup

InitEquity = 100000;
MaxPos = 20;
Tradesize = 5000;
SetOption("InitialEquity", InitEquity);
SetOption("MaxOpenPositions", MaxPos);
SetPositionSize(5, spsPercentOfEquity);
//SetPositionSize(5000, spsValue);
//SetTradeDelays(1,1,1,1);
SetTradeDelays(0,0,0,0);
SetOption("CommissionMode",2);
SetOption("CommissionAmount", 30);
SetOption("UsePrevBarEquityForPosSizing", True);



//Filter
SetForeign("XAO", True);
MAfilter = MA(C, 75);
Buyfilter = Close > MA( C, 75);
Sellfilter = Close < MA(C, 75);
RestorePriceArrays();


//Rules
HiLevel = Param("HiLevel", 100, 10, 500, 5);
LoLevel = Param("LoLevel", 100, 10, 500, 5);
HI = HHV(C,HiLevel);
LW = LLV(C,LoLevel);
DollarTurnover = MA(C*V, 7);
dollarTurnoverOK = dollarTurnover > 500000;
Liquidity = MA(V,7);
LiquidityOK = Liquidity > 500000;
OptMax = 20; //Optimize("MaxPrice", 20, 5, 30, 5);
MaxSP = Close < OptMax;



Buy = C >= HI AND LiquidityOK AND dollarTurnoverOK AND Buyfilter AND MaxSP;
Sell = C <= LW;




//With Filter
//Buy = C >= HI AND LiquidityOK AND dollarTurnoverOK AND Buyfilter;
//Sell = C <= LW OR SellFilter;

// No Filter
//Buy = C >= HI AND LiquidityOK AND dollarTurnoverOK;
//Sell = C <= LW;

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

//If Filter on, tighten SL to xx%
stoppc = Param("Stop %", 2, 2, 50, 2); 
stoplevel = (100-stoppc)/100;
trailstop = 0;
OpenPos = 0;
trailARRAY = Null;

for (i=1; i<BarCount;i++)
{
	if(trailstop==0 AND Buy[i])		// if buy today (trailstop will be 0 at this point. SellFilter must therefore be off)
	{
		OpenPos = 1;
	}
	else				// if not initial buy, remove excess buy signals
	{
		Buy[i] = 0;	
	}
	if(OpenPos == 1)
	{
		if(Sellfilter[i]==0)	// if in trade and sellfilter is off
		{
			trailstop = 0;			// reset trailstop	
		}
		else			// sellfilter must be on
		{
			if(trailstop == 0)	// in trade, sell filter on but SL initially 0
			{
				trailstop	= Low[i] * stoplevel; 	// set SL to % below low
				trailARRAY[i] = trailstop;
			}
			else		// in trade, sellfilter on, trailstop previously set
			{	
				if(Close[i] < trailstop)	// if close lower than stop - exit trade
				{
					Sell[i] = 1;		//exit trade
					SellPrice = trailstop;	//sell on open
					OpenPos = 0;		//not in trade anymore
					trailstop = 0;		//reset SL
				}
				else	// in trade, sellfilter on, trailstop previously set, still in trade
				{
					trailstop = Max(trailstop, Low[i] * stoplevel); // SL is higher of the two - never lower
					trailARRAY[i] = trailstop;
				}
			}
		}
	}
}

Plot(LW, "LowestValue", colorRed, styleLine, 0, 0, 0, 0);
Plot(HI, "HighestValue", colorGreen, styleLine, 0, 0, 0, 0);

//Plot stop loss - stop loss applied using (max price - xx%)
Plot(trailARRAY, "stoploss", colorWhite, styleLine, 0, 0, 0, 0);
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Close);
PlotShapes(Sell*shapeDownArrow, colorRed, 0, Close);

I had fixed those pesky '=' signs. I can't understand why I get the red arrow and yet the backtest seems to ignore it.

I do have a another question about amibroker afl though. When amibroker does a backtest, does it go through the code line by line for each bar? If so, what does it do with the 'for' loop. I understand that the backtest tests the code through history and I understand the 'for' loop above goes through each bar from the start, but I can't seem to put the two together. Does it iterate over the 'for' loop (from the first to the 'current' bar) and then do it all again the next bar?
 
I suppose something similar to this is what you are after.

Code:
//'New Yearly Highs' 
//Setup
// version 1.1, edited by trash

InitEquity = 100000;
MaxPos = 20;
Tradesize = 5000;
tradedelay = 0;

if ( tradedelay > 0 )
{
    array  = Open;
    flag = 1;
}
else
{
    array  = Close;
    flag = 0;
}

SetOption( "InitialEquity", InitEquity );
SetOption( "MaxOpenPositions", MaxPos );
SetPositionSize( 5, spsPercentOfEquity );
//SetPositionSize(5000, spsValue);

SetTradeDelays( tradedelay, tradedelay, tradedelay, tradedelay );
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 30 );
SetOption( "UsePrevBarEquityForPosSizing", True );

//Filter
SetForeign( "XAO", True );
MAfilter = MA( C, 75 );
Buyfilter = Close > MAfilter;
Sellfilter = Close < MAfilter;
RestorePriceArrays();

//Rules
HiLevel = Param( "HiLevel", 100, 10, 500, 5 );
LoLevel = Param( "LoLevel", 100, 10, 500, 5 );
HI = HHV( C, HiLevel );
LW = LLV( C, LoLevel );
DollarTurnover = MA( C * V, 7 );
dollarTurnoverOK = dollarTurnover > 500000;
Liquidity = MA( V, 7 );
LiquidityOK = Liquidity > 500000;
OptMax = 20; //Optimize("MaxPrice", 20, 5, 30, 5);
MaxSP = Close < OptMax;

Buy = C >= Ref( HI, -1 ) AND LiquidityOK AND dollarTurnoverOK AND Buyfilter AND MaxSP;
Sellcond = C <= Ref( LW, -1 ) /*OR Sellfilter*/;

BuyPrice = SellPrice = array;

Short = Cover = Sell = 0;

//If Filter on, tighten SL to xx%
stoppc = Param( "Stop %", 2, 0, 50, 2 );
stoplevel = ( 100 - stoppc ) / 100;
trailstop = 0;
trailARRAY = Null;

for ( i = 1; i < BarCount; i++ )
{
    if ( trailstop == 0 AND Buy[i] )
    {
        trailstop = L[ i ] * stoplevel;
    }
    else
    {
        Buy[i] = 0;    // remove excess buy signals
    }

    if ( Sellcond[ i ] )
    {
        Sell[ i ] = 1;
        trailstop = 0;
    }

    if ( trailstop > 0 AND Low[ i ] < trailstop )
    {
        Sell[ i ] = 1;
        SellPrice[ i ] = trailstop;
        trailstop = 0;
    }

    if ( trailstop > 0 )
    {
        trailstop = Max( L[ i ] * stoplevel, trailstop );
        trailARRAY[ i ] = trailstop;
    }
}

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

// channel plot
Plot(LW, "LowestValue", colorRed, styleLine, 0, 0, 0, 0);
Plot(HI, "HighestValue", colorGreen, styleLine, 0, 0, 0, 0);

//Plot stop loss - stop loss applied using (max price - xx%)
Plot( trailarray, "stoploss", colorWhite, styleLine, 0, 0, 0, 0 );

/// plotting shapes ::::::::::::::::::::::::::::::::::::::::::::::::::::
Buycond = Ref( Buy, -flag );
Sellcond = Ref( Sell, -flag );

Buycolor = colorGreen;
Sellcolor = colorOrange;
Colorborder = colorLightGrey;

PlotShapes( Buy*shapeSmallUpTriangle, Buycolor, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallUpTriangle, Colorborder, 0, L, -15 );
PlotShapes( Buycond*shapeHollowSmallCircle, Buycolor, 0, BuyPrice, 0 );

PlotShapes( Sell*shapeDownArrow, Sellcolor, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, Colorborder, 0, H, -15 );
PlotShapes( Sellcond*shapeHollowSmallCircle, Sellcolor, 0, SellPrice, 0 );
 
I suppose something similar to this is what you are after.

Code:
//'New Yearly Highs' 
//Setup
// version 1.1, edited by trash

InitEquity = 100000;
MaxPos = 20;
Tradesize = 5000;
tradedelay = 0;

if ( tradedelay > 0 )
{
    array  = Open;
    flag = 1;
}
else
{
    array  = Close;
    flag = 0;
}

SetOption( "InitialEquity", InitEquity );
SetOption( "MaxOpenPositions", MaxPos );
SetPositionSize( 5, spsPercentOfEquity );
//SetPositionSize(5000, spsValue);

SetTradeDelays( tradedelay, tradedelay, tradedelay, tradedelay );
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 30 );
SetOption( "UsePrevBarEquityForPosSizing", True );

//Filter
SetForeign( "XAO", True );
MAfilter = MA( C, 75 );
Buyfilter = Close > MAfilter;
Sellfilter = Close < MAfilter;
RestorePriceArrays();

//Rules
HiLevel = Param( "HiLevel", 100, 10, 500, 5 );
LoLevel = Param( "LoLevel", 100, 10, 500, 5 );
HI = HHV( C, HiLevel );
LW = LLV( C, LoLevel );
DollarTurnover = MA( C * V, 7 );
dollarTurnoverOK = dollarTurnover > 500000;
Liquidity = MA( V, 7 );
LiquidityOK = Liquidity > 500000;
OptMax = 20; //Optimize("MaxPrice", 20, 5, 30, 5);
MaxSP = Close < OptMax;

Buy = C >= Ref( HI, -1 ) AND LiquidityOK AND dollarTurnoverOK AND Buyfilter AND MaxSP;
Sellcond = C <= Ref( LW, -1 ) /*OR Sellfilter*/;

BuyPrice = SellPrice = array;

Short = Cover = Sell = 0;

//If Filter on, tighten SL to xx%
stoppc = Param( "Stop %", 2, 0, 50, 2 );
stoplevel = ( 100 - stoppc ) / 100;
trailstop = 0;
trailARRAY = Null;

for ( i = 1; i < BarCount; i++ )
{
    if ( trailstop == 0 AND Buy[i] )
    {
        trailstop = L[ i ] * stoplevel;
    }
    else
    {
        Buy[i] = 0;    // remove excess buy signals
    }

    if ( Sellcond[ i ] )
    {
        Sell[ i ] = 1;
        trailstop = 0;
    }

    if ( trailstop > 0 AND Low[ i ] < trailstop )
    {
        Sell[ i ] = 1;
        SellPrice[ i ] = trailstop;
        trailstop = 0;
    }

    if ( trailstop > 0 )
    {
        trailstop = Max( L[ i ] * stoplevel, trailstop );
        trailARRAY[ i ] = trailstop;
    }
}

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

// channel plot
Plot(LW, "LowestValue", colorRed, styleLine, 0, 0, 0, 0);
Plot(HI, "HighestValue", colorGreen, styleLine, 0, 0, 0, 0);

//Plot stop loss - stop loss applied using (max price - xx%)
Plot( trailarray, "stoploss", colorWhite, styleLine, 0, 0, 0, 0 );

/// plotting shapes ::::::::::::::::::::::::::::::::::::::::::::::::::::
Buycond = Ref( Buy, -flag );
Sellcond = Ref( Sell, -flag );

Buycolor = colorGreen;
Sellcolor = colorOrange;
Colorborder = colorLightGrey;

PlotShapes( Buy*shapeSmallUpTriangle, Buycolor, 0, L, -15 );
PlotShapes( Buy*shapeHollowSmallUpTriangle, Colorborder, 0, L, -15 );
PlotShapes( Buycond*shapeHollowSmallCircle, Buycolor, 0, BuyPrice, 0 );

PlotShapes( Sell*shapeDownArrow, Sellcolor, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, Colorborder, 0, H, -15 );
PlotShapes( Sellcond*shapeHollowSmallCircle, Sellcolor, 0, SellPrice, 0 );


Thanks Trash.

I've backtested your code and I can see trades getting stopped out (which is good). Unfortunately what I want is that the stop loss only applies when 'Sellfilter' is true (XAO closes below its 75 MA). Also, when the filter turns off again, the stop loss value resets/goes to zero/whatever you want to call it, and then when the filter turns back on, the stop loss 'starts again' (ie doesn't keep the same value from where it left off). Annoying aren't I? :D
 
Without testing but then change line

if ( trailstop > 0 AND Low[ i ] < trailstop )

to

if ( trailstop > 0 AND Low[ i ] < trailstop AND Sellfilter )
 
Without testing but then change line

if ( trailstop > 0 AND Low[ i ] < trailstop )

to

if ( trailstop > 0 AND Low[ i ] < trailstop AND Sellfilter )




Still no-go unfortunately. The stop loss I don't think is quite right, but regardless, it doesn't actually exit the trade anyway. There is a red triangle with a grey border but, according to the backtester, the trade still only exits at the yearly/100 day low.

Trouble is, the more I tweak the code to how I think it should go, the more it ends up looking like mine. I hate to be a pest but are you able to backtest my code? Barring any logic error, do you think my code looks ok? I think it looks similar to yours but a little more complex because of what I'm trying to do with the stop loss and I've used else statements where I only want one section of code to apply before making it fall through to the next loop iteration.
 
Hi Guys,

I am 2-weeks new to Amibroker and I find this software is great! Powerful backtesting

Could anyone point me to any good AFL design of Amibroker Automated Trading ? I am trying to code a fully automated afl and could have benefit from any good template.

I have read thru the official document but it only provide simple example of each function.
www.amibroker.com/at/‎


Thanks! :)
 
I does work for me (with my recent edited code)!! Chart results and backtests results are in line here! You should take care of time frame and params in backtester because they are independent! So rather use hard coded params to not get confused.

Here is proof that results are in line with each other (chart and backtest list). I'm using different symbols and time frame but that doesn't matter.

Results with taking additional Sellfilter of foreign symbol into account.
Click each picture to enlarge.
In the picture it does not exit at any trail stop because sell filter is not true together with it yet.
So it exits on the lower red channel sell condition every time here on that day. Sell filter is in line with that exit by accident so it has no influence on that other sell condition.
image.jpg

image.jpg

Here Results without taking any additional Sellfilter of a foreign symbol into account.
image.jpg

image.jpg


Here is a picture where SellFilter and trailstop are true so it exits on trail stop.
image.jpg
And if removing SellFilter then it is two trades.
image.jpg

Sorry, but my help ends here on this issue. Can't waste endless time on this since example is working. Wait for others if you don't get it done yourself.
 

Attachments

  • image.jpg
    image.jpg
    8 KB · Views: 5
  • image.jpg
    image.jpg
    3.8 KB · Views: 4
  • image.jpg
    image.jpg
    3.7 KB · Views: 4
  • image.jpg
    image.jpg
    9.1 KB · Views: 3
  • image.jpg
    image.jpg
    3.9 KB · Views: 2
  • image.jpg
    image.jpg
    3.9 KB · Views: 2
I does work for me (with my recent edited code)!! Chart results and backtests results are in line here! You should take care of time frame and params in backtester because they are independent! So rather use hard coded params to not get confused.

Here is proof that results are in line with each other (chart and backtest list). I'm using different symbols and time frame but that doesn't matter.

Results with taking additional Sellfilter of foreign symbol into account.
Click each picture to enlarge.
In the picture it does not exit at any trail stop because sell filter is not true together with it yet.
So it exits on the lower red channel sell condition every time here on that day. Sell filter is in line with that exit by accident so it has no influence on that other sell condition.
image.jpg

image.jpg

Here Results without taking any additional Sellfilter of a foreign symbol into account.
image.jpg

image.jpg


Here is a picture where SellFilter and trailstop are true so it exits on trail stop.
image.jpg
And if removing SellFilter then it is two trades.
image.jpg

Sorry, but my help ends here on this issue. Can't waste endless time on this since example is working. Wait for others if you don't get it done yourself.

Thanks anyway Trash. I really appreciate the amount of effort you've put in.
 

Attachments

  • image.jpg
    image.jpg
    8 KB · Views: 2
  • image.jpg
    image.jpg
    3.8 KB · Views: 3
  • image.jpg
    image.jpg
    3.7 KB · Views: 1
  • image.jpg
    image.jpg
    9.1 KB · Views: 0
  • image.jpg
    image.jpg
    3.9 KB · Views: 0
  • image.jpg
    image.jpg
    3.9 KB · Views: 3
Thanks anyway Trash. I really appreciate the amount of effort you've put in.

As for sellfiilter I would rather use this
Sellfilter = Ref( C < MAfilter, -1 ) AND O < MAfilter;
instead of
Sellfilter = C < MAfilter;
becasue second one looks ahead since trailstop exits intrabar.

Or you change sellprice of trailstop to array and keep Sellfilter = C < MAfilter;.
Anyway for me it works here. You have not come up with any clear description and/or picture explaining what you actually mean. Useless for reproduction.
 
Hi Guys,

I am 2-weeks new to Amibroker and I find this software is great! Powerful backtesting

Could anyone point me to any good AFL design of Amibroker Automated Trading ? I am trying to code a fully automated afl and could have benefit from any good template.


Thanks! :)
This below will show you that back testing results can be dramatically opposing to real time results. Additionally, simply participating in the market changes the outcome where as in a back test you are the 'invisible' trader trading unreal positions.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    168.8 KB · Views: 14
  • Untitled.jpg
    Untitled.jpg
    103.4 KB · Views: 21
Hi Guys,

I am 2-weeks new to Amibroker and I find this software is great! Powerful backtesting

Could anyone point me to any good AFL design of Amibroker Automated Trading ? I am trying to code a fully automated afl and could have benefit from any good template.

I have read thru the official document but it only provide simple example of each function.
www.amibroker.com/at/‎


Thanks! :)

Check out Howard Bandy's books. One of them you can get free: http://www.introductiontoamibroker.com/book.html
 
Top