you could define your sellprice inside the loop:
if( priceatbuy > 0 && Low[ i ] < priceatbuy - 1)
{
Sell[ i ] = 1;
SellPrice[ i ] = priceatbuy[ i ] - 1;
2007/7/12, mac_bosh <[EMAIL PROTECTED]>:
Hi,
Nothing appears to be wrong with your code, But, and I stand to be
corrected, ensure that you have the correct settings in here:
Menu->Analysis->Automatic Analysis->Setting->Trades
Bosh
--- In [email protected] <amibroker%40yahoogroups.com>,
"jl2012_30" <[EMAIL PROTECTED]> wrote:
>
> I'm totally new to Amibroker and am very lost.
>
> I'm trying to write a code that implements a stop loss if the stock
> falls $1 below my buy price.
>
> I tried the following code but it does not work (I don't get stop out
> at all).
>
> -----------------------
> Sell = 0;
>
> priceatbuy = 0;
> for( i = 0; i < BarCount; i++ )
> {
> if( priceatbuy == 0 && Buy[ i ] )
> priceatbuy = BuyPrice[ i ];
>
> if( priceatbuy > 0 && Low[ i ] < priceatbuy - 1)
> {
> Sell[ i ] = 1;
> SellPrice[ i ] = Close[i];
> priceatbuy = 0;
> }
> else
> Sell[ i ] = 0;
> }
>
> -------------------------
>
> However, if I change the statement
>
> if( priceatbuy > 0 && Low[ i ] < priceatbuy - 1) to
> if( priceatbuy > 0 && Close[ i ] < priceatbuy - 1)
>
> the code will stop me out correctly based on the Close array.
>
> What is wrong with my code above? Any help is definitely very much
> appreciated.
>
--
Regards