Many this will get you going. MaCond = C > MA(C,20); RocValue = Roc(C,1) == 0;// or whatever level you want FlatCond = Sum(RocValue, 5) >= 1; HistRocValue = Ref(Roc(C,1),-5);// or did you mean 6 DownCond = HistRocValue - Ref(HistRocValue, -6) < 0;
Buy = MaCond And FlatCond And DownCond: Sell = ? --- In [email protected], "Siva" <sivsr...@...> wrote: > > I want to test a trade set up if stock price breaks a 20 days simple moving > average. But for Buy signal, I want the MA curve to fullfill some conditions. > > 1. 20DMA curve must be up for at least 2 days. > var1[ 0 ] = MA( Close, 20 ); > for( i = 1; i < BarCount; i++ ) > { > while( i <= i + 3 ) > { > if(var1[ i ] > var1[ i + 1 ]) > { > break; > } > > 2. Before the first condition, the curve should be flat for 1 day to a > maximum of 5 days. > for( a = 1; a < 6; a++ ) > > 3. Before the second condition, the curve should be down for at least five > days. > Thanks. >
