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

Re: [amibroker] Re: Is it possible to create such a buy signal ?



PureBytes Links

Trading Reference Links

Hello,

> - A buy occured with the above conditions of course
> - Sell at buy price (open*1.02) + 0.5%
> - or Sell at buy price (open*1.02) -0.5 %
> - If a sell signal couldn't be generated today (because price didn't 
> go up or down 0.5% from the buy price) then sell at close.
> 
> Again, all of this should happen the same day it was bought.

This one is fairly easy, add the following lines to your formula (after buy setup):

sell = buy; // this ensures that sell is performed at the same bar as buy

sell1cond = high > buyprice * 1.005; // +0.5% from buyprice
sell2cond = low < buyprice * 0.9995; // -0.5% from buyprice

// the line below chooses appropriate sellprice depending on conditions met
sellprice = IIF( sell1cond, buyprice * 1.005, IIF( sell2cond, buyprice * 0.9995, close ) );

One caveat is that if both conditions sell1cond and sell2cond are met
the code chooses sell1cond (this simulates that prices first go up and
the sell limit is activated). As we don't know intra-day behaviour this
may be right or wrong.

Best regards,
Tomasz Janeczko
===============
AmiBroker - the comprehensive share manager.
http://www.amibroker.com