[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Buyprice and sellprice...



PureBytes Links

Trading Reference Links

Can't you just use buyprice=C*1.01;
--- In amibroker@xxxxxxxxxxxxxxx, "Howard B" <howardbandy@xxx> wrote:
>
> Greetings all --
> 
> I received a private email asking for more clarification about the code
> segment I posted.  Since the technique may be of general interest, I've
> posted it to the forum.
> 
> Here is a complete trading system that adjusts the BuyPrice and
SellPrice,
> under the control of a Param.
> 
> Replace the simple moving average crossover for the Buy with a more
> intelligent one of your own.  And the Sell as well.
> 
> Run this with AdjustBuyPrice set to 0, and again with it set to 1.
> 
> For each run, open the Report, then look at Trades and compare the
price of
> entry and exit.
> 
> /////////////////////////////////////////////////////
> 
> //    adjustBuyPrice.afl
> 
> //    In response to a question on the Yahoo AmiBroker Forum,
> //    this code shows one way to adjust the Buyprice and Sell Price,
> //    perhaps to model slippage.
> 
> //    Howard Bandy
> //    July 2, 2008
> 
> 
> SetTradeDelays(0,0,0,0);
> BuyPrice = C;
> SellPrice = C;
> 
> //    When AdjustBuyPrice is 0, no changes are made
> //    When AdjustBuyPrice is 1, BuyPrice and Sell Price are adjusted
> 
> AdjustBuyPrice = Param("adjBuyPrice",0,0,1,1);
> 
> MA1 = 10;
> MA2 = 5;
> Buy = Cross(MA(C,MA1),MA(C,MA2));
> 
> if (AdjustBuyPrice)
> {
>     for (i=0; i<BarCount; i++)
>     {
>           // test to see if there was a Buy on this bar
>           // and if there was, adjust BuyPrice
>           if (Buy[i] == 1)
>           {
>             BuyPrice[i] = 1.01*BuyPrice[i];
>           }
>     }
> }
> 
> Sell = BarsSince(Buy)>=3;
> 
> 
> if (AdjustBuyPrice)
> {
>     for (i=0; i<BarCount; i++)
>     {
>           // test to see if there was a Sell on this bar
>           // and if there was, adjust SellPrice
>           if (Sell[i] == 1)
>           {
>             SellPrice[i] = 0.99*BuyPrice[i];
>           }
>     }
> }
> 
> 
> 
> 
> 
> //////////////////////////////////////////////////////
> 
> Thanks,
> Howard
> www.quantitativetradingsystems.com
> 
> On Wed, Jul 2, 2008 at 9:08 AM, Dennis Brown <see3d@xxx> wrote:
> 
> >   Barry,
> >
> > About the only comment I can make is that I have produced systems the
> > generate in real life what they backtest to. If you understand all
> > the issues, you can make it match. Another point is that when I trade
> > against my system --deciding the best second to send the order after
> > it says to send it, I generally get a better result. This is trading
> > one minute bars. It all just depends on the details of the system and
> > the trader --and the delays from the data feed.
> >
> > Other than that, I generally agree with your assessment.
> >
> > BR,
> > Dennis
> >
> >
> > On Jul 2, 2008, at 11:40 AM, Barry Scarborough wrote:
> >
> > > I guess I will start a debate that I don't intend to participate in
> > > but state it for consideration. It seems many are trying to tweak
> > > their back tester to find the absolute best performance but include
> > > intangibles like slippage. Back testing, in my opinion, should only
> > > be used to compare systems to find which out performs another. That
> > > is all you need to do because the market will change and the system
> > > will not work as you expect. So it is a waste of time to try to eek
> > > our more gain or try to factor in slippage or all such nonsense.
> > >
> > > Why do I say this? I have a system that consistently will back test
> > > 200% to 1000% A DAY using 1 Russell emini contract ER2 and a 1
minute
> > > chart. In longer periods the gain is less and I use various time
> > > periods and data samples. In the real world it does not make a
profit
> > > on a 1 minute chart. But that system works much better than one that
> > > back tests with less gain and the system does not even start to make
> > > a consistent gain with a period under 15 minutes. Using hour charts
> > > it is much better but no where near 200% a day the back tester
shows.
> > >
> > > The problem is when you enter the real world, especially with auto
> > > trading, whipsaw during sideways periods and during trend changes
> > > will eat your lunch. Auto trading will come close to getting the
> > > value of the close at the time the signal was generated by your
> > > system. But there is slippage and that can be significant depending
> > > on the buy/ask spread and the volatility of the market. You can't
> > > predict what it will be. Don't even try! Even if you use a simple
> > > button pushing auto trading system, where you hit the buy or sell
> > > button when you see your signal, you can't hit the button fast
enough
> > > to simulate the price you get on the static chart. So your results
> > > will not come close to your back test results. I REPEAT NOT EVEN
> > > CLOSE!!! So it is a waste of time to do more than use back
testing to
> > > compare systems. Trying to predict what it will do in the real world
> > > is deceitful, sheer folly, don't do it.
> > >
> > > Well that's my two cents worth. I am going back to sleep now.
> > >
> > > Cheers,
> > > Barry
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx <amibroker%40yahoogroups.com>,
"Howard
> > B" <howardbandy@> wrote:
> > >>
> > >> Hi Louis --
> > >>
> > >> Perhaps write a simple loop?
> > >>
> > >> for (i=0; i<BarCount; i++)
> > >> {
> > >> // test to see if there was a Buy on this bar
> > >> // and if there was, adjust BuyPrice
> > >> if (Buy[i] == 1)
> > >> {
> > >> BuyPrice[i] = 1.01*BuyPrice[i];
> > >> }
> > >> }
> > >>
> > >> Or am I missing something?
> > >>
> > >> Thanks,
> > >> Howard
> > >>
> > >>
> > >>
> > >>
> > >> On Tue, Jul 1, 2008 at 9:27 PM, tayamaan <tayamaan@> wrote:
> > >>
> > >>> Louis, you now assume your slippage to be 1%, which is a guess
> > >>> anyways. It differs per situation what your system considers to be
> > >>> the Buy/Sell Price and what you actually pay or get at the market.
> > >>> These are still two different things. I wouln't know how to
> > > calculate
> > >>> the real slippage, all you can do is comparing the difference
> > > over a
> > >>> period of time and take some kind of average.
> > >>>
> > >>> Adrian
> > >>>
> > >>> --- In amibroker@xxxxxxxxxxxxxxx
<amibroker%40yahoogroups.com><amibroker%
> > 40yahoogroups.com>,
> > > Graham
> > >>> <kavemanperth@> wrote:
> > >>>>
> > >>>> turn off the option of PriceBoundChecking in the Analyser
> > > settings
> > >>> of in the AFL
> > >>>>
> > >>>> SetOption( "PriceBoundChecking", 0 );
> > >>>>
> > >>>> --
> > >>>> Cheers
> > >>>> Graham Kav
> > >>>> AFL Writing Service
> > >>>> http://www.aflwriting.com
> > >>>>
> > >>>>
> > >>>> 2008/7/2 Louis Préfontaine <rockprog80@>:
> > >>>>> Hi,
> > >>>>>
> > >>>>> But is it possible to set the backtester to consider that the
> > >>> buyprice was
> > >>>>> let's say 1% higher than the Close on the bar the trade was
> > > made?
> > >>>>>
> > >>>>> That's what I tried to do. If it's complicated, I can live
> > > with
> > >>> this (well,
> > >>>>> I can at least try, since I believe I am still a beginner in
> > >>> understanding
> > >>>>> AFL), but I'd need to know if it is possible, and if yes, what
> > >>> can be a good
> > >>>>> start...
> > >>>>>
> > >>>>> Was I on the right track with
> > >>>>>
> > >>>>> SetTradeDelays( 1, 1, 1, 1 );
> > >>>>> BuyPrice = c*1.01;
> > >>>>> SellPrice = c*0.99;
> > >>>>>
> > >>>>> Cause it does not work at all...
> > >>>>>
> > >>>>> Thanks again,
> > >>>>>
> > >>>>> Louis
> > >>>>>
> > >>>>> 2008/7/1 Graham <kavemanperth@>:
> > >>>>>>
> > >>>>>> Then you need to set out exactly what you need to do and
> > > write
> > >>> the afl to
> > >>>>>> match
> > >>>>>> It is all logical steps
> > >>>>>> I do it by writing down all the restrictions and
> > > possibilities
> > >>> and
> > >>>>>> what I need at the end and how I think is best way to achieve
> > >>> this
> > >>>>>> ......... in detail. There are no short cuts and can be very
> > >>> tedious.
> > >>>>>> I also more often than not write out a flow chart to map all
> > >>>>>> decisions, inputs, outputs, calculations etc.
> > >>>>>>
> > >>>>>> --
> > >>>>>>
> > >>>>>> Cheers
> > >>>>>> Graham Kav
> > >>>>>> AFL Writing Service
> > >>>>>> http://www.aflwriting.com
> > >>>>>>
> > >>>>>> 2008/7/2 Louis Préfontaine <rockprog80@>:
> > >>>>>>> Hi Adrian,
> > >>>>>>>
> > >>>>>>> Thanks for your suggestion. But still... How can I do
> > > this? I
> > >>> mean: I
> > >>>>>>> want to be precise. With the kind of markets I am in and
> > > what
> > >>> I am
> > >>>>>>> trying
> > >>>>>>> to do, precision is very important... I need to be able to
> > > set
> > >>> a
> > >>>>>>> particular % adjustment for particular situations...
> > >>>>>>>
> > >>>>>>> Louis
> > >>>>>>>
> > >>>>>>> 2008/7/1 tayamaan <tayamaan@>:
> > >>>
> > >>>>>>>>
> > >>>>>>>> Hi, if you would really like to try to compensate for
> > >>> slippage,
> > >>>>>>>> adding this to your commissions as part of your
> > > transaction
> > >>> costs is
> > >>>>>>>> perhaps an idea.
> > >>>>>>>>
> > >>>>>>>> Adrian
> > >>>>>>>>
> > >>>>>>>>> Hi Graham,
> > >>>>>>>>>
> > >>>>>>>>> How can I put more information so that my buy price is
> > > 1%
> > >>> higher
> > >>>>>>>> than C and
> > >>>>>>>>> sell price 1% lower than C?
> > >>>>>>>>>
> > >>>>>>>>> Thanks,
> > >>>>>>>>>
> > >>>>>>>>> Louis
> > >>>>>>>>>
> > >>>>>>>>> 2008/7/1 Graham <kavemanperth@>:
> > >>>>>>>>>
> > >>>>>>>>>> Without more information on what you are trying to
> > > achieve
> > >>>>>>>>>> The price will be for the bar of actual entry C*1.01
> > > or
> > >>> C*0.99
> > >>>>>>>>>>
> > >>>>>>>>>> Also the prices may be outside than the bar range in
> > >>> which case
> > >>>>>>>> the
> > >>>>>>>>>> closer of high or low is used if you have the
> > >>> PriceBoundChecking
> > >>>>>>>> on
> > >>>>>>>>>>
> > >>>>>>>>>> --
> > >>>>>>>>>> Cheers
> > >>>>>>>>>> Graham Kav
> > >>>>>>>>>> AFL Writing Service
> > >>>>>>>>>> http://www.aflwriting.com
> > >>>>>>>>>>
> > >>>>>>>>>> 2008/7/1 Louis Préfontaine <rockprog80@ <rockprog80%
> > >>>>>>>> 40gmail.com>
> > >>>>>>>>>>> :
> > >>>>>>>>>>
> > >>>>>>>>>>> Hi,
> > >>>>>>>>>>>
> > >>>>>>>>>>> I have been trying to set a formula for slippage:
> > >>>>>>>>>>>
> > >>>>>>>>>>> SetTradeDelays( 1, 1, 1, 1 );
> > >>>>>>>>>>>
> > >>>>>>>>>>> BuyPrice = C*1.01;
> > >>>>>>>>>>> SellPrice = C*0.99;
> > >>>>>>>>>>>
> > >>>>>>>>>>> It doesn't work at all. I tried to write C*50 just
> > > for
> > >>> fun, but
> > >>>>>>>> it didn't
> > >>>>>>>>>>> change the buyprice at all. What can possibly be
> > > wrong?
> > >>>>>>>>>>>
> > >>>>>>>>>>> Thanks,
> > >>>>>>>>>>>
> > >>>>>>>>>>> Louis
> > >>>>
> > >>>
> > >>>
> > >>>
> > >>
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > Please note that this group is for discussion between users only.
> > >
> > > To get support from AmiBroker please send an e-mail directly to
> > > SUPPORT {at} amibroker.com
> > >
> > > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > > http://www.amibroker.com/devlog/
> > >
> > > For other support material please check also:
> > > http://www.amibroker.com/support.html
> > > Yahoo! Groups Links
> > >
> > >
> > >
> >
> >  
> >
>



------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/