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

[amibroker] Re: question



PureBytes Links

Trading Reference Links

What would be the best way detecting 2 crossovers within the last X 
days?

I tried this code and it didn't work, anyone willing to help?


// AFL Code for detecting multiple crosses within the past X Days
function IsMACross(MA_Above, MA_Below, DaysLookBack)
{
	returnValue = False;
	IsKeepLooping = True;
	if (BarCount > DaysLookBack)
	{
		for (i = (BarCount - DaysLookBack) ; i <= BarCount 
AND IsKeepLooping; i++)
		{
			if (Cross(MA_Above[i], MA_Below[i]))
			{
				returnValue = True;
				IsKeepLooping = False;
			}
		}
	}
	return returnValue;
}


MA50 = MA(C, 50);
MA100 = MA(C, 100);
MA150 = MA(C, 150);

Filter = IsMACross(MA50, MA100, 10) AND IsMACross(MA100, MA150, 10);

Buy = Filter;
Sell = 0;

AddColumn(C, "Close", 1.2);




Thanks,
Gary


--- In amibroker@xxxxxxxxxxxxxxx, "keithmccombs" <kmccombs@xxxx> 
wrote:
> Imran --
> You may not get the results you are expecting with Dieter's code.  
> You asked to sell "when x crossed 'y and z' to the negative
> (downside)".  Dieter gave you cross(y,x) which doesn't address 
> the 'z' in your request.
> 
> You might try:
> Sell = cross(y,x) AND cross(z,x);
> But you will most probably find that this is not what you intended 
> either, because a 'cross' only happens on a single bar and it is 
> highly unlikely that cross(y,x) and cross(z,x) will occur on the 
same 
> bar.  Instead, you might use (depending on your intent):
> Sell = x<y AND x<z;
>     or
> Sell = x<y OR x<z;
> 
> Then use the ExRem() function to get rid of the exta down arrows on 
> your price chart.
> 
> You may also discover that rather than using:
> Buy = cross(x,y);
> you may really want:
> Buy = x>y AND x>z;
> -- Keith 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Imran Pishori" <ipishori1@xxxx> 
> wrote:
> > Thanks!
> > 
> >  
> > 
> >   _____  
> > 
> > From: amibroker@xxxxxxxxxxxxxxx 
[mailto:amibroker@xxxxxxxxxxxxxxx] 
> On Behalf
> > Of dieterdotbraun
> > Sent: Monday, October 03, 2005 4:09 PM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: [amibroker] Re: question
> > 
> >  
> > 
> > Hi Imran,
> > 
> > copy and paste the Code from the first /* to the Last */ in the 
> editor
> > and choose Apply Indicator.
> > finish.
> > 
> > 
> > Code Start--------------------------------------------------------
--
> -
> > /*______________________________ Plot Title______________ */
> > _SECTION_BEGIN("Price");
> > SetChartOptions(0,chartShowArrows);
> > Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %
g, 
> Lo
> > %g, Close %g (%.1f%%)
> > {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) )
> > )+encodecolor(colorred)+
> > "\n\n\n\Welcome to amibroker";
> > 
> > 
> > /*______________________________ Plot Chart______________ */
> > 
> > Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
> > ParamStyle("Style", styleCandle, maskPrice ) ); 
> > _SECTION_END();
> > /*_______________________________Variabelen________________*/
> > x = EMA(C,5);      
> > y = EMA(C,30)      ;
> > z = EMA(C,34)      ;
> > /*______________________________Plot lines on Chart________*/
> > 
> > Plot(x, "EMA(34)", colorBlue, styleLine);
> > Plot(y, "EMA(34)", colorGreen, styleLine);
> > Plot(z, "EMA(34)", colorRed, styleLine);
> > /*______________________________Trading Rules_/Conditions___*/
> > Buy=Cross(x,y);
> > Sell=Cross(y,x);
> > /*______________________________Plot Arrows on Chart_______*/
> > PlotShapes(shapeUpArrow * Buy, colorGreen,0,L,-20);
> > PlotShapes(shapeDownArrow * Sell, colorRed, 0,H,-20);
> > 
> > /*_____________________________Have FUN___________________*/
> > 
> > Code Ende---------------------------------------------------------
--
> > 
> > by,Dieter
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Imran Pishori" 
<ipishori1@xxxx> 
> wrote:
> > > Hello,
> > > 
> > >  
> > > 
> > > I just got Amitrader and was using the program and I realized I 
> have
> > a LOT
> > > to learn but am enjoying the learning process thus far.
> > > 
> > >  
> > > 
> > > I had a question since my coding skills are very limited.
> > > 
> > >  
> > > 
> > > Let say I had 3 plots for example.
> > > 
> > >  
> > > 
> > > x = plot ema (close (5)); 
> > > 
> > > y = plot ema (close (30));
> > > 
> > > z = plot ema (close (34));
> > > 
> > >  
> > > 
> > > now I wanted to buy when 'x' crosses 'y and z' to the positive 
> (upside):
> > > 
> > >  
> > > 
> > > eg:
> > > 
> > >  Buy = cross (x, ????) // this is the part I don't know what to 
> do with
> > > 
> > >  
> > > 
> > > And I would like to sell when x crossed 'y and z' to the 
negative
> > > (downside):
> > > 
> > >  
> > > 
> > > Eg:
> > > 
> > > Sell = cross (x, ???) // I have no idea what I am doing
> > > 
> > >  
> > > 
> > > Could anyone please point me in the right direction on how I 
would
> > > accomplish this.  The help menu points toward the plots crossing
> > just one
> > > point and that is the close price of a particular stock.
> > > 
> > >  
> > > 
> > > Also, are there any books on coding etc. that one would 
recommend 
> I
> > read to
> > > get a better idea on how to code using Amitrader.  
> > > 
> > >  
> > > 
> > > THANKS!
> > > 
> > >  
> > > 
> > > Imran
> > 
> > 
> > 
> > 
> > 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 other support material please check also:
> > http://www.amibroker.com/support.html
> > 
> > 
> > 
> > 
> > 
> > 
> >   _____  
> > 
> > YAHOO! GROUPS LINKS 
> > 
> >  
> > 
> > *	 Visit your group "amibroker
> > <http://groups.yahoo.com/group/amibroker> " on the web.
> >   
> > *	 To unsubscribe from this group, send an email to:
> >  amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?
subject=Unsubscribe> 
> >   
> > *	 Your use of Yahoo! Groups is subject to the Yahoo!
> > <http://docs.yahoo.com/info/terms/>  Terms of Service. 
> > 
> >  
> > 
> >   _____




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Help tsunami villages rebuild at GlobalGiving. The real work starts now.
http://us.click.yahoo.com/njNroD/KbOLAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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 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/

<*> 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/