Amibroker AFL Coding Help

Discussion in 'Trading Software' started by mdjgd4, Mar 7, 2014.

  1. mdjgd4

    mdjgd4

    Would really appreciate any guidance on a new strategy I'm wanting to code in Amibroker. The strategy is very simple and involves the following:

    Buy/Cover = close of current bar higher than closing high n bars ago
    Sell/Short = close of current bar lower than closing low n bars ago

    The idea would be to optimize variable n. The variable n in sense would be a pivot point and if the price of the traded instrument crosses above this pivot point it triggers a trade.

    The concept is somewhat similar to the Turtle Traders strategy (e.g. if closing price exceeds the highest closing in 20 days then buy). In this example n would equal 20 days or 20 bars dependent on the time frame used.

    Any help on this would be greatly appreciated. Thank you in advance!!!
     
  2. try this.
    pivothi= hhv(close,10); //highest close 10 bars past
    buy= close >pivothi

    i'd be very careful of using current close for once you transition into live trading, that close is still not finished and you might be looking into future

    better doing something like
    prevcl=ref(close,-1);
    pivothi = hhv(preCl,10);........
     
  3. Sergio77

    Sergio77

    Then, for n = 10 shouldn't he do

    pivothi = hhv(preCl,9);

    otherwise he will be looking at 11 bars.
     
  4. Sergio, I just threw out that number there as pseudocode. the HHV(9) will give you nine bars regardless of where it starts out in the array. Lastly, some traders pick up the price for pivots differently. ie where to start the offset,etc.
     
  5. oop you are correct boredyet. I forget about ref in my corrected post. That being said, I had an extended discussion on trade delays w AB as well as my AFL "guru". In live autotrading, I sometime want to get in on the current bar w/o setting trade delays. for instance, if I use some backbars to calculate entry price, and that entry price gets breached right now, I am putitng out my buy orders , hence I try to avoid trade delays.
     
  6. mdjgd4

    mdjgd4

    Thank you so much for all of the help on this! Using the info provided I created the formula below and have not been able to get it to work. Any ideas? Thank you in advance!!!

    Length1 = Optimize ("Length1", 10, 1, 20, 1);
    Length2 = Optimize("Length2", 10, 1, 20, 1);

    Pivot1 = HHV(Close,Length1);
    Pivot2 = LLV(Close,Length2);

    Buy = Close > Pivot1;
    Sell = Close < Pivot2;
     
  7. mdjgd4

    mdjgd4

    Okay thank you for the trade delay fix! Modified the code to include this and it works great now:

    Length1 = Optimize ("Length1", 10, 1, 20, 1);
    Length2 = Optimize("Length2", 10, 1, 20, 1);

    Pivot1 = HHV(Close,Length1);
    Pivot2 = LLV(Close,Length2);

    Buy = Close > Ref( Pivot1, -1 );
    Sell = Close < Ref( Pivot2, -1 );

    Thank you again so much for all of the help here guys!!!
     
  8. Hi . Have a question for experienced Amibroker auto traders using IB Controller . I have an AFL scan running every 1 min to look for buy triggers then if true , fires off an "order set" to IB . ex If mvgavg>10 then ibc.placeorder. The set consists of 3 orders --- a limit buy / a stop and a target. I record the orderID's and have an if statement so that only 1 set of 3 is submitted per ticker. It works fine EXCEPT when it does not!

    I would look down my TWS 30 ticker list and see 25 pairs with only a set of 3, but occasionally, 1-2 fx would have many sets of 3! The code is really simple and since it is working on 80-90% of the symbols, I am beginning to wonder whether it is IBController related. If it was bad coding would it be bad on all tickers not just 1-2 ? Any thoughts?
     
  9. Too bad, I don't measure up to what YOU think a super user of Ab should behave. Yes, I do consult with TJ and Marcin so it is not a licensing issue. But their support is limited at best. In addition to writing thousands of code a month, I also pay someone $50 /hr in India to help me. You know why? time=money. You are right in one thing. I AM LAZY. If I can post somewhere and happen to get an advise from a superuser who has encountered the peculiarity before, it would save me 4 hours of debugging. You have no clue how many peeps here at ET help me out -maverick,nitro,bone,lescor,etc.

    As a trader it is all about time triage..... yeh triage..go open a tab and google the definition for I doubt you have the intellectual suppleness to look at the world with softer eyes.

    Seriously? , you cut and paste a missing ref call for a code and you chalk that up to inexperience? Can you simulate the return of option calendar spreads or a straddle using AB backtester objects? as it unfolds thru time and vega implosion? probably not....