Mike,
Thank you for the info. I think I got it to work with the code below. Now I
am curious how to backtest this composite to see how this would have worked
during bull/bear periods. Any tips on how to go about this?
Thank you in advance.
FastMALength = 100;
//Set Fast Moving Average
SlowMALength = 300;
//Set Slow Moving Average
FastMA = DEMA(Close, FastMALength);
//Fast Moving Average
SlowMA = DEMA(Close, SlowMALength);
//Slow Moving Average
bi = BarIndex();
Buy=Cross(FastMA, SlowMA);
Sell=Cross(SlowMA, FastMA) OR bi == LastValue(bi) + 1;
in_trade=Flip(Buy, Sell);
AddToComposite(in_trade, "~OpenPosCount", "V");
AddToComposite(1, "~OpenPosCount", "I");
Bull=Foreign("~OpenPosCount", "V")/ Foreign("~OpenPosCount", "I");
dynamic_color = IIf( Bull > 0.60, colorGreen, IIf( Bull < 0.40, colorRed,
colorBlack) );
/*Plot(Bull, "Bull", dynamic_color, styleOwnScale |styleLine);
Plot(.60, "Bull", colorGreen);
Plot(.40, "Bear", colorRed);*/
PlotForeign("$DJI", "Dow", dynamic_color, styleLine);
--- In [email protected], "Mike" <sfclimb...@...> wrote:
>
> Hi,
>
> A couple of things to look at:
>
> 1. Foreign takes one of "O" (open), "H" (high), "L" (low), "C" (close), "V"
> (volume), "I" (open Interest), and for v5.29 and above: "1" (aux1), "2"
> (aux2). It does NOT take "X".
>
> 2. By default, you must run a Scan to use AddToComposite. However, I notice
> that you are using Filter which applies to Exploration. If you want to use
> AddToComposite in an Exploration, you must add the flag
> atcFlagEnableInExplore.
>
> 3. When running the Scan/Exploration, make sure the current symbol is one
> that has a very long history (e.g. an index).
>
> --- In [email protected], "James" <readshark@> wrote:
> >
> > I wrote the script below to count the number of stocks whose 100 day MA is
> > above their 300 day MA. It seems to mostly work except for about 100 days
> > where it shows the number of stocks is equal to 0. The same days show the
> > number of stocks for the inverse is 0. Furthermore I can see there are
> > stocks whose 100 day MA are above or below their 300 day MA on these days.
> > What am I doing wrong? Thank you in advance.
> >
> > FastMALength = 100;
> > //Set Fast Moving Average
> > SlowMALength = 300;
> > //Set Slow Moving Average
> >
> > FastMA = DEMA(Close, FastMALength);
> > //Fast Moving Average
> > SlowMA = DEMA(Close, SlowMALength);
> > //Slow Moving Average
> >
> > AddToComposite(IIf(FASTMA > SlowMA, 1, 0), "~DEMA_Bull", "X");
> >
> >
> >
> > Buy=Sell=Short=Cover=0;
> > Filter=1;
> >
> > Bull = Foreign("~DEMA_Bull", "X");
> > Plot(Bull, "Bull", 1,1);
> >
> > Filter=1;
> >
>