Australian (ASX) Stock Market Forum

Amibroker Coding - Please help :(

Joined
Jan 24, 2020
Posts
5
Reaction score
2
Please help. I'm trying to simply make a buy strategy if the current bar closes below 75% of the previous bar. My code below does not work and would appreciate your guidance please.

priorday = Ref(c, -1);
calculate = (-.25 * priorday);
buy = calculate
 
Joined
Jun 29, 2007
Posts
113
Reaction score
37
Please help. I'm trying to simply make a buy strategy if the current bar closes below 75% of the previous bar. My code below does not work and would appreciate your guidance please.

priorday = Ref(c, -1);
calculate = (-.25 * priorday);
buy = calculate
buy = c < ref(c,-1)*.75 ;

haven't tested it .... but it looks right

or the longer way

priorday = Ref(c, -1);
calculate = (priorday * .75);
buy = c < calculate;
 
Joined
Jan 24, 2020
Posts
5
Reaction score
2
Hi Dave :)

Sorry I mean the current bar has to close at least 75% below the previous bar. I wrote a new code but it still won't work. Any thoughts? Thanks again :)

Priorcandle = ((C - O)/O)*100;
priorCandle2 = Ref (Priorcandle, -1);
lessthan75 = LARGECANDEL1 * 0.75;

Buy = C < lessthan75;
 

rnr

Joined
Jul 1, 2007
Posts
544
Reaction score
298
Please help. I'm trying to simply make a buy strategy if the current bar closes below 75% of the previous bar. My code below does not work and would appreciate your guidance please.

priorday = Ref(c, -1);
calculate = (-.25 * priorday);
buy = calculate

Buy = C < Ref(C,-1)*0.75;

When used for backtesting the above code is looking into the future and even if you had an order in the market prior to the closing auction there is no guarantee your order would be filled.

Cheers,
Rob
 
Joined
Sep 26, 2014
Posts
156
Reaction score
36
Hi Dave :)

Sorry I mean the current bar has to close at least 75% below the previous bar. I wrote a new code but it still won't work. Any thoughts? Thanks again :)

Priorcandle = ((C - O)/O)*100;
priorCandle2 = Ref (Priorcandle, -1);
lessthan75 = LARGECANDEL1 * 0.75;

Buy = C < lessthan75;

Buy = C < Ref(C, -1) - Ref(abs(C - O), -1) * 0.75;
Buyprice = C; // or buy at next day's Open

use at your own risk
 
Joined
Jun 8, 2008
Posts
5,573
Reaction score
4,703
Thanks, not working in my end but appreciate the help and communication
he current bar has to close at least 75% below the previous bar.
Still confused at what you want to code
Current bar close..ok
75% below previous bar..??.are we talking below the previous bar close, or its low?
And 75% below?
Maybe a small hand sketch of what you want to do?
Not playing the smartarse but if Dave's answer does not fit, it means we are misunderstanding the problem
 
Joined
Jan 24, 2020
Posts
5
Reaction score
2
Hi guys, Thank-you. Please view the attached sketch. Apologies, it is me that is not understanding. For my simplicity i have changed it to 50%.

So, if the current red bar falls below the prior green bar by 50% than buy. However the code does not seem to work and is proving tricky. Appreciate your help.

 

Attachments

Joined
Nov 30, 2005
Posts
1,078
Reaction score
770
You need to be very specific as to what you want.

You wish to compare today's close to which value from previous bar, high, low, open or close ?
 
Joined
Sep 26, 2014
Posts
156
Reaction score
36
Hi guys, Thank-you. Please view the attached sketch. Apologies, it is me that is not understanding. For my simplicity i have changed it to 50%.

So, if the current red bar falls below the prior green bar by 50% than buy. However the code does not seem to work and is proving tricky. Appreciate your help.


OK, here is the complete code for testing:


Buy = C < Ref(C, -1) - Ref(abs(C - O), -1) * 0.5;
Buyprice = C;
Sell = 1;
SellPrice = C;


You run this on a single ticker for now to verify the entry points.
The position size doesn't matter at this point but it can't be zero!
This is as easy as it gets. Nothing tricky about it.
If today's close is lower than yesterday's close minus half the difference between Open and Close, you buy.
Exit on next day's Close.
Note: make sure that the holding period is 2 bars. That means unticking "Allow same-bar exit" in the settings.
You might consider using High and Low of the prior bar rather than Open and Close to avoid a possible difference of zero. Like this:

Buy = C < Ref(C, -1) - Ref(H - L), -1) * 0.5;
 
Joined
Jun 8, 2008
Posts
5,573
Reaction score
4,703
OK, here is the complete code for testing:


Buy = C < Ref(C, -1) - Ref(abs(C - O), -1) * 0.5;
Buyprice = C;
Sell = 1;
SellPrice = C;


You run this on a single ticker for now to verify the entry points.
The position size doesn't matter at this point but it can't be zero!
This is as easy as it gets. Nothing tricky about it.
If today's close is lower than yesterday's close minus half the difference between Open and Close, you buy.
Exit on next day's Close.
Note: make sure that the holding period is 2 bars. That means unticking "Allow same-bar exit" in the settings.
You might consider using High and Low of the prior bar rather than Open and Close to avoid a possible difference of zero. Like this:

Buy = C < Ref(C, -1) - Ref(H - L), -1) * 0.5;
From what i i understand from graph, the latter is what is required?
And as an advise, never use half/50 percent in example..as 50pc of high is 50pc of low etc etc etc
Use an easy to draw but explicit 25pc or 30pc in example.
Hope it helps
I think that later answer from @Habbakuk is what you want
 
Joined
Jun 29, 2007
Posts
113
Reaction score
37
OK, here is the complete code for testing:


Buy = C < Ref(C, -1) - Ref(abs(C - O), -1) * 0.5;

Buy = C < Ref(C, -1) - Ref(H - L), -1) * 0.5;
depending on requirements as the open may be higher than the close .

Buy = C < Ref(MAX(O,C), -1) - Ref(abs(C - O), -1) * 0.5;

Also As i think rbr alluded to, buying and selling on the close takes considerable more work than the open and requires ........... stuff ( patience, automation, more slippage ) .

Out of curiosity, who are you getting your data through ... and broker ???
 
Joined
Jan 24, 2020
Posts
5
Reaction score
2
Thank-you all so much for the help and guidance. It really works just the way i wanted it :).. Appreciate the help. Hope I can do the same for others when I'm experienced :) :)
 
Joined
Jun 8, 2008
Posts
5,573
Reaction score
4,703
Question for the more experienced AB users here;
I hit a problem using Premium Data.
I compute an index indicator using:
SetForeign( "XAO" );
vsum = Sum( Volume, 12 );
xxx

RestorePriceArrays( );

All good

Now interested to look at a US index;
The following fails!!!
SetForeign( "$DJ" );
vsum = Sum( Volume, 12 );
xxx

RestorePriceArrays( );

yet if I select $DJ in charting I can see the index properly
What could be the cause?
Any help welcome
 
Joined
Jun 29, 2007
Posts
113
Reaction score
37
Do you have US data ??? ....... Premium data or Norgate data ???

I think once you have US data the AU names get mangled and have a .au suffix. SO you would have "$XAO.AU". In some functions $XAO worked ( It's been a while since i tested ) and some they don't ... it's odd, so i just default to $XAO.AU .

Bottom line is, i think if you have US data you should use "$XAO.AU".

Richard might be able to provide more information if he's watching.
 
Joined
Jun 29, 2007
Posts
113
Reaction score
37
Do you have US data ??? ....... Premium data or Norgate data ???

I think once you have US data the AU names get mangled and have a .au suffix. SO you would have "$XAO.AU". In some functions $XAO worked ( It's been a while since i tested ) and some they don't ... it's odd, so i just default to $XAO.AU .

Bottom line is, i think if you have US data you should use "$XAO.AU".

Richard might be able to provide more information if he's watching.
Sorry ... that didn't answer the question you asked, just trying to understand your problem
 
Joined
Jun 8, 2008
Posts
5,573
Reaction score
4,703
Sorry ... that didn't answer the question you asked, just trying to understand your problem
Premium data only
But i can see $DJ in charts, yet not working from code..
I am aware of the northgate vs premium data difference and extension..but does not help me here ;-)
 
Top