Australian (ASX) Stock Market Forum

Amibroker FAQ

Re: Amibroker exits

Thanks very much for the help, GB.

The NBar stop part is not working correctly. I am getting exits marked as 'n-bar' in the correct places, but the actual exit, the exit price, is the previous low, the same as the stop-loss exits. I'm trying to get the second exit to occur at the close of the third day.

You mean you want to sell for L<=Ref(L,-1) only if it happens the day after buying?... otherwise nbar=3?

If so:

Buy = ROC(C,1)>5; // change to your buy rules
Sellprice = Iif(ref(Buy,-1),Ref(L,-1),C); // if you bought yesterday, then sell if L<=Ref(L,-1), otherwise..
Sell = Sellprice>=L and Sellprice<=H;//
Applystop(stoptypenbar,stopmodebars,3);
 
Re: Amibroker exits

Thanks very much for the help, GB.

The NBar stop part is not working correctly. I am getting exits marked as 'n-bar' in the correct places, but the actual exit, the exit price, is the previous low, the same as the stop-loss exits. I'm trying to get the second exit to occur at the close of the third day.

Simple way.

Code:
SetTradeDelays(1,0,1,1);

Buy = Cross(MACD(), Signal()); // Buy cross of MACD & signal line
Sell = L < Ref(L, -1); // Sell if current low is less than last bar low
SellPrice = Close; // Sell price for stop loss and  sell condition is close price same bar as trigger (no  delay in set trade delays)
BuyPrice = Open; // Buy price is open price 1 bar delay

ApplyStop(stopTypeNBar, stopModeBars, 3); // Exit position on bar 3 close (same bar with no delay set in trade delays)
 
Re: Amibroker exits

Simple way.

Code:
SetTradeDelays(1,0,1,1);

Buy = Cross(MACD(), Signal()); // Buy cross of MACD & signal line
Sell = L < Ref(L, -1); // Sell if current low is less than last bar low
SellPrice = Close; // Sell price for stop loss and  sell condition is close price same bar as trigger (no  delay in set trade delays)
BuyPrice = Open; // Buy price is open price 1 bar delay

ApplyStop(stopTypeNBar, stopModeBars, 3); // Exit position on bar 3 close (same bar with no delay set in trade delays)

It might be simple but it neglects virtually every condition he has specified. 1) He doesn't want trade delays, 2) he wants the sellprice=yesterday's low (not the close), and 3) he only wants this last condition to be active the day following the buy.
 
Re: Amibroker exits

I tried to set the SellPrice with conditional logic. I tried the following:

IIf(BarsSince(Buy)==2,IIf(L > Ref(L, -1), SellPrice = Close, SellPrice = Ref(L, -1)), SellPrice = Ref(L, -1));
Sell = Cross( SellPrice, Low);
ApplyStop(stopTypeNBar,stopModeBars,2);

I thought the logic seemed correct but, for the NDay stop, I still get an exit price of yesterday's low, instead of the exit price being the close.
 
Re: Amibroker exits

I thought the logic seemed correct but, for the NDay stop, I still get an exit price of yesterday's low, instead of the exit price being the close.
Applystop exit is determined by the sellprice that you stated.

The first exit is a stop loss. I want to exit immediately if the low of the day crosses the low of the previous day
Exit immediately and then later you state exit yesterdays low price. Is that correct? If so, not possible as the exit bar may range may be below yesterdays bar. Best way is to deal with the quotes available.
 
Re: Amibroker exits

Applystop exit is determined by the sellprice that you stated. I think you will have to "loop" for different SellPrices.

Thanks for the help, Wysiwyg. I can't figure out how to apply a loop in this situation.

Thank for your earlier suggestion too. The NDay exits work fine, exiting at the close, as required. But, once you have set the SellPrice to Close, all the subsequent exits which are triggered by crossing yesterday's low also have the close of the bar as their exit price.
 
Re: Amibroker exits

Thanks for the help, Wysiwyg. I can't figure out how to apply a loop in this situation.

Thank for your earlier suggestion too. The NDay exits work fine, exiting at the close, as required. But, once you have set the SellPrice to Close, all the subsequent exits which are triggered by crossing yesterday's low also have the close of the bar as their exit price.
Thanks. If you look at the sell price criteria the exit price of last bar low is not always possible because the exit bar may range less than previous bar as in piccy. You can't sell at the previous low because any price on exit bar does not meet it.

Untitled.png
 
Re: Amibroker exits

Thanks. If you look at the sell price criteria the exit price of last bar low is not always possible because the exit bar may range less than previous bar as in piccy. You can't sell at the previous low because any price on exit bar does not meet it.

View attachment 66483

Agreed. That's what I'm trying to work with -- on entry bar, bar 1, there is a stop at the previous bar low. It either fills or it doesn't. If still alive on day 2, the stop moves to the low of day 1, now the previous bar. Same on day 3, if still alive, stop to low of day 2. If not stopped out, exit on the close of day 3.

In your picture, you would have exited on the close of day 3, and never got to the bar with the red arrow, which is bar 4.
 
Re: Amibroker exits

You mean you want to sell for L<=Ref(L,-1) only if it happens the day after buying?... otherwise nbar=3?

If so:

Buy = ROC(C,1)>5; // change to your buy rules
Sellprice = Iif(ref(Buy,-1),Ref(L,-1),C); // if you bought yesterday, then sell if L<=Ref(L,-1), otherwise..
Sell = Sellprice>=L and Sellprice<=H;//
Applystop(stoptypenbar,stopmodebars,3);

Sorry, GB, I completely missed your reply here...

No, it's not quite like that -- I want to sell on any of bars 1,2, or 3 if price breaks yesterday's low. If still in the trade, exit on the close of day 3.

As far as I can see, your code above has an exit at the close of every first bar.

Appreciate the help.
 
Hey guys it would be greatly appreciated if you guys can double check the follow explore whether it is correct or not? Also, is there a way to code the % of drop of x stock from y highs? My objective is to find stocks that have fallen 40% or more from the recent high but since i dont know how to code the "recent high" part i used from x amount of period.

Thanks

PHP:
Period = 14;

// Determines trend direction using DMI indicators
MDIFilter = MDI(period) > PDI(period);

// calculate the % change from the prior close in days
PCY = ((C-Ref(C,-10))/Ref(C,-10))*100;
PCY2 = ((C-Ref(C,-20))/Ref(C,-20))*100;
PCY3 = ((C-Ref(C,-40))/Ref(C,-40))*100;
PCY4 = ((C-Ref(C,-60))/Ref(C,-60))*100;
PCY5 = ((C-Ref(C,-80))/Ref(C,-80))*100;
PCY6 = ((C-Ref(C,-100))/Ref(C,-100))*100;
PCY7 = ((C-Ref(C,-120))/Ref(C,-120))*100;
PCY8 = ((C-Ref(C,-140))/Ref(C,-140))*100;
PCY9 = ((C-Ref(C,-160))/Ref(C,-160))*100;
PCY10 = ((C-Ref(C,-180))/Ref(C,-180))*100;

// Columns 
NumColumns = 2;

Column0     = FullName();     
Column0Name = "Ticker name";

Column1     = IIf(MDIFilter AND ((PCY OR PCY2 OR PCY3 OR PCY4 OR PCY5 OR PCY6 OR PCY7 OR PCY8 OR PCY9 OR PCY10) >= -40), 1, 0);
Column1Name = "Reversal Signal";

AddTextColumn( SectorID(1), "Sector" );

AddTextColumn( MarketID(1), "Market" );


// Look for stocks down a minimum of >= 40%
Filter = ADX(period) >= 30 AND Column1;

Buy = ADX(period) >= 30 AND Column1;
 
Also, is there a way to code the % of drop of x stock from y highs? My objective is to find stocks that have fallen 40% or more from the recent high but since i dont know how to code the "recent high" part i used from x amount of period.

Thanks

This gives you the percent drop from 52 week high.

Code:
YearHigh2 = C - HHV(H, 250);
YearHigh1 = YearHigh2 / HHV(H, 250);
YearHighToPresent = YearHigh1 * 100;

Filter = YearHighToPresent;

AddTextColumn(WriteVal(YearHighToPresent), "Percent Fall", 1.2, colorBlue);

and 40% or greater

Code:
YearHigh2 = C - HHV(H, 250);
YearHigh1 = YearHigh2 / HHV(H, 250);
YearHighToPresent = YearHigh1 * 100;
Fallof40 = YearHighToPresent < -39;


Filter = Fallof40;
AddTextColumn(WriteVal(IIf(Fallof40, YearHighToPresent, 0)), "Percent Fall", 1.2, colorBlue);
 
@Wysiwyg, i noticed my original included all the stocks from your code but also included stocks that did not fall >=40%. If you have the time, can you tell me what went wrong in the original code as such it still include stocks that did not fall more than 40%?

Code:
((PCY OR PCY2 OR PCY3 OR PCY4 OR PCY5 OR PCY6 OR PCY7 OR PCY8 OR PCY9 OR PCY10) >= -40)
I imagine it has to do with this line?

I replaced the original with yours, just trying to get a better understanding. Cheers.
 
@Wysiwyg, i noticed my original included all the stocks from your code but also included stocks that did not fall >=40%. If you have the time, can you tell me what went wrong in the original code as such it still include stocks that did not fall more than 40%?

Code:
((PCY OR PCY2 OR PCY3 OR PCY4 OR PCY5 OR PCY6 OR PCY7 OR PCY8 OR PCY9 OR PCY10) >= -40)
I imagine it has to do with this line?

I replaced the original with yours, just trying to get a better understanding. Cheers.

At the end you have to change the >= -40 to <= -40 for a negative number. Also your 10 conditions use a specific Close price back from 10 bars to 180 bars ago. So you are getting the % change for each specific referenced Close. Mine referenced the High.

Hope this helps.
 
Hi all.

I was wondering if anybody can let me know how to reference a previous signal from the past? eg higher than last swing high.

Thanks
 
Hi all.

I was wondering if anybody can let me know how to reference a previous signal from the past? eg higher than last swing high.

Thanks

swinghigh=Your code used to define a swing high;

H>ValueWhen(swinghigh,H,1);
 
swinghigh=Your code used to define a swing high;

H>ValueWhen(swinghigh,H,1);

Hi rnr. Many thanks for your help with this.:)

I was wondering if you could also tell me how to reference the last occurrence of this because at the moment my signal is generating breaks of all swing highs in the past?
 
Hi rnr. Many thanks for your help with this.:)

I was wondering if you could also tell me how to reference the last occurrence of this because at the moment my signal is generating breaks of all swing highs in the past?

The script also misses many breakouts of swing highs in my scan (I show the swing highs by plotshapes).

I've not idea why.:confused:

Any help would be greatly appreciated.

Swinghigh = H>Ref(H,-1) AND H>Ref(H,1);
breakout = (H>ValueWhen(swinghigh,H,1));
PlotShapes(shapeSmallCircle*swinghigh,colorgreen, 0, L, -40);

Buy = breakout;
 
The script also misses many breakouts of swing highs in my scan (I show the swing highs by plotshapes).

I've not idea why.:confused:

Any help would be greatly appreciated.

Swinghigh = H>Ref(H,-1) AND H>Ref(H,1);
breakout = (H>ValueWhen(swinghigh,H,1));
PlotShapes(shapeSmallCircle*swinghigh,colorgreen, 0, L, -40);

Buy = breakout;

swinghi= Peak(H,5,1);
Buy = Cross(C,Ref(swinghi,-1));
Plot(Zig(H,5),"",colorBlack);
 
swinghi= Peak(H,5,1);
Buy = Cross(C,Ref(swinghi,-1));
Plot(Zig(H,5),"",colorBlack);

Thanks Gringotts. I was then looking for price to close back down below the high of the previous pivot.
I don't think that can be done if the swing is calculated using Zig eg:

Buy = H>(Ref(swinghi,-1)) AND C<(Ref(swinghi,-1)) ;



I've been trying this but for some reason AB won't have it and misses many signals :confused:

Logic seems correct to me.:confused:

SwingHi= H>Ref(H,-1) AND H>Ref(H,1);
BO= (L>ValueWhen(swingHi,H,1)) AND (C<ValueWhen(swingHI,H,1));
PlotShapes(shapeSmallCircle*SWINGHi,colorBLUE, 0, H, 20);

Buy = SwingHi;

This is the JHX daily chart for example. Note no green arrow buy signal on yesterday's candlestick? But there was one correctly identified 4 days ago.

5-05-2016 8-45-13 PM.jpg
 
Top