Australian (ASX) Stock Market Forum

Help with simple Amibroker formula

Joined
28 January 2009
Posts
46
Reactions
0
I am just learning the basics of writing AB formulas and I am stuck already.

I have a very simple formula written which ends in -

Buy = BuySignal AND above;
Short = SellSignal AND below;

IIf( (Buy),PlotShapes(shapeUpTriangle*Buy,colorGreen),0);
IIf( (Short),PlotShapes(shapeDownTriangle*Short,colorRed),0);

1. I want to put 2 OCO stops on each trade at +40 and -40 points. How do I write this into the formula?

2. I want which ever stop is activated to display on the chart like it did with the buy and sell signals. How do I do this?

3. What is the difference between "cover" and stops? Isn't a position cover already a stop?

I'm confused, any help appreciated.
 
I'm hoping Captain Black can help with this question. I thought I had it first time but there is a glitch.

I want to use the GP_ATRStop.afl in a strategy and tried this approach...

PHP:
 #include <GP_ATRStop.afl>;
  	
 Buy = whatever;
 Sell = Sells; // from the GP_ATRStop.afl 
 Buy = ExRem(Buy,Sell); 
 Sell = ExRem(Sell,Buy);
by placing the GP_ATRStop.afl in the include folder and using the #include function in the strategy.

It works as it should except that the first trade date is referenced by every following trade. For example ....

the first trade when back testing between 2007 - 2010 is opened the 5-Jan-2007 and closed the 24-Jan-2007 when the close price is below the set ATR trailing stop on the 23-Jan-2007.
That works exactly how it should.

However all following trades on the list reference the first trade open date, the 5-Jan-2007. That is they close using the 5-Jan-2007 as the start for the trailing stop.

Is there a simple fix for this so each individual trade when back tested references its own opening day to start the trailing stop?

The added benefit to get this working is being able to set the ATR in Parameters window of A.A. for quick change when back testing strategies.

Thank you.
 
Hi Wysiwyg,
looking through my library I think I've found the GP stops code you are using. I don't use it so can't really provide much support, if GP is still active here may be able to PM him?

From a quick glance I noticed this at the beginning of the code:

Code:
/*     [B][I] This function checks if the buy date is in the dates array and if not,
        changes it to the closest date before it.[/I][/B]
*/

function CheckDate(buyDate, dates)
{
    retDate = buyDate;

    i = 0;
    gotDate = 0;
    while (i < BarCount && !gotDate) {
        if (buyDate == dates[i])
            gotDate = 1;
        else {
            if (dates[i] > buyDate) {
                gotDate = 1;
                if (i)
                    retDate = dates[i-1];
                else
                    retDate = dates[0];
                }
            }
        i++;
        }

    return retDate;
}
My best guess is that this is where the problem is.
 
Hi Wysiwyg,
looking through my library I think I've found the GP stops code you are using. I don't use it so can't really provide much support, if GP is still active here may be able to PM him?
Okay Captain, no worries. Many of the coders have drifted away from forums it seems and most likely because there is nothing in it for them doing codes for free. Mike & NW Trader on Yahoo & yourself are a few I have been helped by and thanks. There are also many formulas submitted from the advanced crew in the library which have been good for learning practical functions.

I think the message is learn how to do it ourselves though I have almost thrown the mouse across the room a few times. The epitome of frustration sometimes is trying to work out a piece of AFL. No doubt all will be a lot clearer in the future some time.
 
I think the message is learn how to do it ourselves though I have almost thrown the mouse across the room a few times. The epitome of frustration sometimes is trying to work out a piece of AFL. No doubt all will be a lot clearer in the future some time.

Sorry I can't be of more help but without more detail it's difficult to pinpoint the exact problem. Everyone has different AA settings and nuances in their code that can affect the resulting output. The section quoted below sticks out to me as perhaps being a/the cause of the issue.

This function checks if the buy date is in the dates array and if not,
changes it to the closest date before it.
 
Top