Amibroker, Afl, simple trading system

Discussion in 'Trading Software' started by stighy, Aug 29, 2010.

  1. stighy

    stighy

    Hi, hope someone could help me.. i'm trying to learn how amibroker work.
    I would like to make a simple trading system, that Buy (or Alert) when price is near some moving avarage.

    So i write something like:

    MaxDistance=0.5;
    myavarage = 200;
    dist = (( Close / EMA(Close,myavarage ) )*100)-100;
    Buy = iif(dist<MaxDist, 1,Buy);

    // Another avarage
    myavarage = 100;
    dist = (( Close / EMA(Close,myavarage ) )*100)-100;
    Buy = iif(dist<MaxDist, 1,Buy);

    But it seems not work...
    Someone expert with Amibroker can help me ?

    Thank you and regards!
     
  2. You have a long road ahead.
    However we all need to start somewhere....

    First off get the spelling right, 'average', not 'avarage' although not critical at this stage.

    Second, in one same formula don't mix the same code.
    ie,
    myavarage = 200; & myavarage = 100; Use either one or the other, not both

    thirdly, you have not completed this line of code
    Buy = iif(dist

    Should be something like this..

    MaxDistance=0.5;
    myaverage = 200;
    dist = (( Close / EMA(Close,myaverage ) )*100)-100;
    Buy = iif(dist < MaxDistance, 1, 0);

    Filter = Buy > 0;

    Just play around with the first bit of code till you get it right, then add the " // Another average " into the equation.
    Always keep a sharp eye out for typos, they will stop a code working.

    Just spotted another error...but it wont change much, should be
    = Close / EMA(Close,myaverage )*100;
    Don't need double brackets, (( )) one will do it.
     
  3. Here's the full code....I think this should do you...


    MaxDistance= 0.05; // max percentage difference required
    myaverage = 200; // unit of moving average

    MyEMA = EMA(C,myaverage);
    dist1 = MyEMA - C; // $ difference
    dist2 = (EMA(C,myaverage)- C)*100 / MyEMA; // percentage difference
    Buy = IIf(dist2 < MaxDistance*100, 1, 0);

    Cond1 = C < MyEMA;
    Cond2 = dist2 <= MaxDistance*100;

    Filter = Cond1 AND Cond2;

    AddColumn(C, "close",1.3); // closing price
    AddColumn(MyEMA, "MyEMA",1.3); // Chosen EMA amount
    AddColumn(dist1, "$ difference",1.3); // $ difference
    AddColumn(dist2, "dist2",1.3); // percentage difference
    AddColumn(Buy, "Buy=1",1);
     
  4. stighy

    stighy

     
  5. Sheesh, I did you a reply then my ADSL connection dropped out, so i lost my reply, trying again.

    how to "modify" that code, if you want to check another one moving average ?
    change this line...
    myaverage = 200; // unit of moving average
    to whatever period you want, eg...
    myaverage = 50; // 50 period average

    you want the alert if price "touch" ma 200 and ma 50 (for example)...
    change this line...

    MaxDistance= 0.05; // in this instance 0.05 = 5%
    to touch line, then you want zero percent, therefore...
    MaxDistance= 0.00;

    I would have thought my code was quite self explanatory.
     
  6. Quote..
    "I want the alert if price "touch" ma 200 and ma 50 (for example)..."
    if you want it to touch both 200 and 50 EMA's, ie they come together.

    myaverage = 200 AND 50; // unit of moving averages

    But this will greatly limit your results
     
  7. I'm off to bed shortly, I live 'downunder'