Markus,

You might want to have someone check what you ended up with. The code that you 
posted below did not make much sense.

1. If you're looking for first trade *ever* (i.e. single first trade from 
entire portfolio of trades), then there is no reason to call FindOpenPos at 
all, and no need to loop through all open positions. Just call GetFirstOpenPos 
and check if it's not null.

2. If you're looking for first trade *per symbol*, again there is no need to to 
loop through all open positions, just use FindOpenPos. Also, in this scenario, 
you would need to use a unique name for your static variable since there would 
be one per symbol. And, while you're there, change it to a simple dynamic 
variable instead of a static variable, unless you need the values in a chart 
after the backtest.

Mike

--- In [email protected], "Markus Witzler" <funny...@...> wrote:
>
> Don´t worry guys, I GOT IT!
> 
> Markus
>   ----- Original Message ----- 
>   From: Markus Witzler 
>   To: [email protected] 
>   Sent: Sunday, February 21, 2010 7:45 PM
>   Subject: Re: [amibroker] Re: Bar number of first trade in CBT
> 
> 
>     
> 
>   Hello Mike,
> 
>   ProcessTradeSignals doensn´t work since this is a mid-level method - I´m on 
> low level.
> 
>   Instead, I did the code below and keep my head scratching why it doens´t 
> work.
> 
>   As soon as I add these lines to my code and press Backtest, AB briefly 
> jumps to Backtest mask and then all of a sudden back to Quote Editor window 
> without any error message!
> 
>   I initialized "instance = 0 "at the beginning of CBT routine. So, that 
> can´t cause the problems either.
> 
>   I must add that I inserted the loop right after the i-incremented signal 
> loop, so that it is being checked for every time an instance of i has 
> occured. Since I want to get the bar, the first trade of the whole system has 
> been initiated, I only need to get i for the instance = 1.
> 
>   for (trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos())
> 
>   { 
> 
>   trade = bo.findopenposition(sig.symbol);
> 
> 
>   if (trade)
> 
> 
>   {
> 
>   instance = instance + 1;
> 
>   }
> 
>   if (instance == 1)
> 
>   {
> 
> 
>   StaticVarSet("Bar_numer_of_first_trade_initiation", i);
> 
>   }
> 
>   }
> 
>   If you nee the whole code´, please let me know!
> 
>   Thanks
> 
>   Markus
> 
> 
>     ----- Original Message ----- 
>     From: Mike 
>     To: [email protected] 
>     Sent: Saturday, February 20, 2010 10:56 PM
>     Subject: [amibroker] Re: Bar number of first trade in CBT
> 
> 
>       
>     Hi,
> 
>     If you're doing low level backtest, then either:
> 
>     - you're the one entering the trade, in which case just take note of what 
> bar you're on when you do.
> 
>     - or you're calling ProcessTradeSignals(i) at the end of each bar, in 
> which case just call GetFirstOpenPos(); when it returns non null that'll be 
> the first trade bar.
> 
>     Mike
> 
>     --- In [email protected], "Markus Witzler" <funnybiz@> wrote:
>     >
>     > Hello,
>     > 
>     > I need to retrieve the bar number of first trade in CBT (low level)., 
> i.e. when first trade was opened.
>     > 
>     > Any clue how to accomplish this?
>     > 
>     > The only thing I know is I must do this in closed trade list.
>     > 
>     > Thanks
>     > 
>     > Markus
>     >
> 
> 
> 
> 
> 
>     __________ Information from ESET Smart Security, version of virus 
> signature database 4668 (20091207) __________
> 
>     The message was checked by ESET Smart Security.
> 
>     http://www.eset.com
> 
> 
> 
>   __________ Information from ESET Smart Security, version of virus signature 
> database 4668 (20091207) __________
> 
>   The message was checked by ESET Smart Security.
> 
>   http://www.eset.com
> 
> 
>   
> 
>   __________ Information from ESET Smart Security, version of virus signature 
> database 4668 (20091207) __________
> 
>   The message was checked by ESET Smart Security.
> 
>   http://www.eset.com
> 
> 
> 
> 
> __________ Information from ESET Smart Security, version of virus signature 
> database 4668 (20091207) __________
> 
> The message was checked by ESET Smart Security.
> 
> http://www.eset.com
>


Reply via email to