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

Re: [amibroker] Help on Debugging this If-Else Loop



PureBytes Links

Trading Reference Links

from quick look the variables in your loop should be arrays
myMA1[i] < MyMA2[i]

-- 
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com


2008/7/10 ozzyapeman <zoopfree@xxxxxxxxxxx>:
> Hoping someone can help me debugging this bit of code. It's a pretty
> easy FOREX test system that I want to code, on my way to building a more
> complex system. In this example, I define two simple moving averages and
> I want to:
>
> Go Long when MA1 rises above MA2
> Sell when the price is at least 10 pips higher than the buy entry price,
> and MA1 falls below MA2
>
> Go Short when MA1 falls below MA2
> Cover when the price is at least 10 pips lower than the short entry
> price, and MA1 rises above MA2
>
> I'm getting errors inside the longer If statements. And I have a feeling
> there is also an easier way to do all this:
>
>
> myMA1 = MA(C,4);
> myMA2 = MA(C,10);
>
>
> Buy =   myMA1 > MyMA2;
> Short = myMA1 < MyMA2;
>
> PriceAtBuy = 0;
> PriceAtShort = 0;
>
>
> for( i = 0; i < BarCount; i++ )
> {
>      if( PriceAtBuy == 0 AND Buy[ i ] )
>      PriceAtBuy = Buy[ i ];
>
>      if( PriceAtShort == 0 AND Short[ i ] )
>      PriceAtShort = ShortPrice[ i ];
>
>      if(
>          (myMA1 < MyMA2) AND (PriceAtBuy > 0) AND (SellPrice[ i ] >
> (PriceAtBuy + 0.0010 ))
>        )
>      {
>        Sell[ i ] = 1;
>        PriceAtBuy = 0;
>
>      }
>      else
>        Sell[ i ] = 0;
>
>
>      if(
>          (myMA1 > MyMA2) AND (PriceAtShort > 0) AND (CoverPrice[ i ] <
> (PriceAtShort - 0.0010 ))
>        )
>     {
>        Cover[ i ] = 1;
>        PriceAtShort = 0;
>      }
>      else
>        Cover[ i ] = 0;
>
>
> }
>
>   Buy =   ExRem(Buy, Sell);
>   Sell =  ExRem(Sell, Buy);
>   Short = ExRem(Short, Cover);
>   Cover = ExRem(Cover, Short);
>

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

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/