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

[amibroker] Short not triggered only cover (Analysis scan)



PureBytes Links

Trading Reference Links

Hi,

I have following problem and hope that someone would explain to me the
behaviour of Amibroker.  I am using buy/sell and Short/Cover methods.
Settings for Analysis is Long and Short.  The Code structure looks like
this. This example is only with the  Exit Code for Shorts. The Exit code
for Longs looks similiar  and it works as intended.
--------------------------------
Buy =  Buyconditions ....
Sell =  (TimeNum() > 272000 );  //will never be activated - ignore. The
actual "Sell" handled by Loop with conditions

Short = ShortConditions ...
Cover = (TimeNum() > 272000 ) ; //will never be activated - ignore. The
actual "Cover" handled by Loop with conditions

---- Short - SL and Trailing ----
priceatbuy=0;
exit = 0;
Lowsincebuy  = 0;
TRTarget  =0;

for( i = 0; i < BarCount; i++ )
{

    if( priceatbuy == 0 AND Short[i] ) //Buy Cond true or falls
      {
        If  x-condition to exit the Short is true
         {
             Cntactivshort  = Cntactivshort  +1;
             priceatbuy  = Close [i];
             exit = 1;
             Cover [i]= 1;
             CoverPrice [i]= priceatbuy;
          }
         else
         {
             Cover [ i ] = 0;
          }
       }

      if( exit >= 1 ) //if Sold  ....
    {
        Short[ i ] = 0;
        Cover[ i ] = exit + 1; // mark appropriate exit code
        exit = 0;
        priceatbuy = 0; // reset price
     }
} //For
------------

Question 1:
My problem is that in my Analysis, Scan results a "short" is never
triggered, only "cover".  The Buy and Short conditions are triggered in
code, I tested this with foolproof conditions to assure that the "if" 
is executed.   What I dont understand at all is that I use the same
method (- instead of  + and < instead of >) to exit my Longs and there
it works perfectly.
Out of desperation I changed the line:
if( priceatbuy == 0 AND Short[i] )  to
if( priceatbuy == 0 AND Buy[i] )  for fun and suddenly Im getting
"short"  and "cover" results in my scan. Can someone please shed light
on the darkness here?
PS: If I comment out my loop and use the Applystop Function I get the
correct results in my backtests.
Long (max Loss) and Short (max Loss) Lines. Since my exits depend on 
various "if" conditions though, I am forced the use the Loop Exit
Variant.

Question 2:
How can I debug loops? I am using the debug application for normal
_Trace calls but Im having difficulty when Im using a loop like the one
above. What would be the best way to save the different "priceatbuy"
values for debug purposes for  example?

Thx in advance!




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/