Australian (ASX) Stock Market Forum

#### wajo777as

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

#### DaveDaGr8

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

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);

#### wajo777as

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;

#### rnr

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

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

#### Habakkuk

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 < Ref(C, -1) - Ref(abs(C - O), -1) * 0.75;

#### wajo777as

Thanks, not working in my end but appreciate the help and communication

#### Habakkuk

Thanks, not working in my end but appreciate the help and communication

What do you mean, "not working"?
It doesn't do what you want?

It does what you described in your question.

#### qldfrog

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

#### wajo777as

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

• Amibroker.png
115.3 KB · Views: 41

#### macca

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 ?

#### Habakkuk

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;
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;

#### qldfrog

OK, here is the complete code for testing:

Buy = C < Ref(C, -1) - Ref(abs(C - O), -1) * 0.5;
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

#### DaveDaGr8

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 ???

#### qldfrog

Broker BellDirect and using Premium Data

#### wajo777as

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

#### qldfrog

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

#### jjbinks

On norgate data, dow jones index is \$DJI

#### DaveDaGr8

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".

#### DaveDaGr8

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".

#### qldfrog

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 ;-)

Replies
8
Views
3K
Replies
0
Views
905
Replies
8
Views
960
Replies
2
Views
1K
Replies
0
Views
572