• Australian (ASX) Stock Market Forum

Hello and welcome to Aussie Stock Forums!

To gain full access you must register. Registration is free and takes only a few seconds to complete.

Already a member? Log in here.

Amibroker Coding - Please help :(

Discussion in 'Trading Strategies/Systems' started by wajo777as, Jan 24, 2020.

  1. wajo777as

    wajo777as

    Posts:
    5
    Likes Received:
    2
    Joined:
    Jan 24, 2020
    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
     
  2. DaveDaGr8

    DaveDaGr8

    Posts:
    112
    Likes Received:
    34
    Joined:
    Jun 29, 2007
    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;
     
    wajo777as, MovingAverage and qldfrog like this.
  3. wajo777as

    wajo777as

    Posts:
    5
    Likes Received:
    2
    Joined:
    Jan 24, 2020
    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;
     
  4. rnr

    rnr

    Posts:
    503
    Likes Received:
    249
    Joined:
    Jul 1, 2007

    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
     
    wajo777as likes this.
  5. Habakkuk

    Habakkuk

    Posts:
    153
    Likes Received:
    33
    Joined:
    Sep 26, 2014

    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
     
    wajo777as likes this.
  6. wajo777as

    wajo777as

    Posts:
    5
    Likes Received:
    2
    Joined:
    Jan 24, 2020
    Thanks, not working in my end but appreciate the help and communication
     
  7. Habakkuk

    Habakkuk

    Posts:
    153
    Likes Received:
    33
    Joined:
    Sep 26, 2014
    What do you mean, "not working"?
    It doesn't do what you want?

    It does what you described in your question.
     
    wajo777as likes this.
  8. qldfrog

    qldfrog

    Posts:
    4,682
    Likes Received:
    3,351
    Joined:
    Jun 8, 2008
    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 likes this.
  9. wajo777as

    wajo777as

    Posts:
    5
    Likes Received:
    2
    Joined:
    Jan 24, 2020
    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.

    [​IMG]
     

    Attached Files:

    qldfrog likes this.
  10. macca

    macca

    Posts:
    905
    Likes Received:
    455
    Joined:
    Nov 30, 2005
    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 ?
     
    wajo777as and qldfrog like this.
  11. Habakkuk

    Habakkuk

    Posts:
    153
    Likes Received:
    33
    Joined:
    Sep 26, 2014

    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;
     
    wajo777as and qldfrog like this.
  12. qldfrog

    qldfrog

    Posts:
    4,682
    Likes Received:
    3,351
    Joined:
    Jun 8, 2008
    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
     
    wajo777as likes this.
  13. DaveDaGr8

    DaveDaGr8

    Posts:
    112
    Likes Received:
    34
    Joined:
    Jun 29, 2007
    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 ???
     
    wajo777as likes this.
  14. qldfrog

    qldfrog

    Posts:
    4,682
    Likes Received:
    3,351
    Joined:
    Jun 8, 2008
    Broker BellDirect and using Premium Data
     
    wajo777as likes this.
  15. wajo777as

    wajo777as

    Posts:
    5
    Likes Received:
    2
    Joined:
    Jan 24, 2020
    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 likes this.
  16. qldfrog

    qldfrog

    Posts:
    4,682
    Likes Received:
    3,351
    Joined:
    Jun 8, 2008
    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
     
  17. jjbinks

    jjbinks

    Posts:
    305
    Likes Received:
    265
    Joined:
    May 14, 2013
    On norgate data, dow jones index is $DJI
     
    Trav. and qldfrog like this.
  18. DaveDaGr8

    DaveDaGr8

    Posts:
    112
    Likes Received:
    34
    Joined:
    Jun 29, 2007
    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.
     
  19. DaveDaGr8

    DaveDaGr8

    Posts:
    112
    Likes Received:
    34
    Joined:
    Jun 29, 2007
    Sorry ... that didn't answer the question you asked, just trying to understand your problem
     
  20. qldfrog

    qldfrog

    Posts:
    4,682
    Likes Received:
    3,351
    Joined:
    Jun 8, 2008
    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 ;-)
     
Loading...

Share This Page