trigger to meet two condition

#1
Hi dear members :)

I have this single condition based on cross() function:

Code:
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trigger = Cross(MA2, MA1);
So, trigger is true if MA2 crosses MA1

Now, I would like to add a second condition.

trigger is true if MA2 crosses MA1 && for the next 16 periods MA1 does not cross MA2.

This formula is to be run on past prices (EOD) daily chart.

Any idea how to go about it? :confused:

Thanks!
 

NTrader42

Well-Known Member
#3
Hi dear members :)

I have this single condition based on cross() function:

Code:
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trigger = Cross(MA2, MA1);
So, trigger is true if MA2 crosses MA1

Now, I would like to add a second condition.

trigger is true if MA2 crosses MA1 && for the next 16 periods MA1 does not cross MA2.

This formula is to be run on past prices (EOD) daily chart.

Any idea how to go about it? :confused:

Thanks!
try this
Code:
MA1 = MA(C, 16);
MA2 = MA(C, 32);

trigger = Cross( ref(MA1, -16), ref(MA2,-16) ) // cross is 16 bars back
                 And  ref(MA1, -15) > ref(MA2,-15)     // does not cross back 
                 And  ref(MA1, -14) > ref(MA2,-14)     
                 And    // .............. here add condition for other 13 bars
                 And MA1 > MA2;
 
#4
Pls create this condition afl diff between prev high - prev low and 25% of diff now buy when 25% + prev close is more than cmp sell when 25% - prev close is less than cmp pls creat this afl thanks
 
#5
hi,

If you write the full concept, then there r many who can help. Please give full details so it can be done at once

johnnypareek at yahoo.com
Well, the concept is quite simple. Basically, I want to avoid whipsaws when I do analysis in the past at EOD.

When fast MA crosses slow MA I assume that a bullish cycle has begun (according to the MAs it could be small, medium, lont term cycle). Yet, if a couple of bars later the slow MA crosse back the fast MA then the market is sideways a nono of a bullish cycle has begun.

Let me get this straight: I am not trying to predict futures! This is some analysis I do in the past and I would like AmiBroker to do that for me instead of doing it mysefl by hand.

Thanks

EDIT: this image will give the idea!

 
Last edited:
#6
try this
Code:
MA1 = MA(C, 16);
MA2 = MA(C, 32);

trigger = Cross( ref(MA1, -16), ref(MA2,-16) ) // cross is 16 bars back
                 And  ref(MA1, -15) > ref(MA2,-15)     // does not cross back 
                 And  ref(MA1, -14) > ref(MA2,-14)     
                 And    // .............. here add condition for other 13 bars
                 And MA1 > MA2;
I tried that. As a result, it will only trigger when MA1 crosses down MA2 :confused:

Code:
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trig = Cross( Ref(MA1, -16), Ref(MA2,-16) )
AND Ref(MA1, -15) > Ref(MA2,-15)
AND Ref(MA1, -14) > Ref(MA2,-14)
AND Ref(MA1, -13) > Ref(MA2,-13)
AND Ref(MA1, -12) > Ref(MA2,-12)
AND Ref(MA1, -11) > Ref(MA2,-11)
AND Ref(MA1, -10) > Ref(MA2,-10)
AND Ref(MA1, -9) > Ref(MA2,-9)
AND Ref(MA1, -8) > Ref(MA2,-8)
AND Ref(MA1, -7) > Ref(MA2,-7)
AND Ref(MA1, -6) > Ref(MA2,-6)
AND Ref(MA1, -5) > Ref(MA2,-5)
AND Ref(MA1, -4) > Ref(MA2,-4)
AND Ref(MA1, -3) > Ref(MA2,-3)
AND Ref(MA1, -2) > Ref(MA2,-2)
AND Ref(MA1, -1) > Ref(MA2,-1)
AND Ref(MA1, 0) > Ref(MA2,-0)
AND MA1 > MA2;

vLINE = Ref( trig , 16 );

Plot(vLINE, "vLINE", colorOrange, styleHistogram|styleOwnScale,0,1,0,-1);
 

NTrader42

Well-Known Member
#7
I tried that. As a result, it will only trigger when MA1 crosses down MA2 :confused:

Code:
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trig = Cross( Ref(MA1, -16), Ref(MA2,-16) )
AND Ref(MA1, -15) > Ref(MA2,-15)
AND Ref(MA1, -14) > Ref(MA2,-14)
AND Ref(MA1, -13) > Ref(MA2,-13)
AND Ref(MA1, -12) > Ref(MA2,-12)
AND Ref(MA1, -11) > Ref(MA2,-11)
AND Ref(MA1, -10) > Ref(MA2,-10)
AND Ref(MA1, -9) > Ref(MA2,-9)
AND Ref(MA1, -8) > Ref(MA2,-8)
AND Ref(MA1, -7) > Ref(MA2,-7)
AND Ref(MA1, -6) > Ref(MA2,-6)
AND Ref(MA1, -5) > Ref(MA2,-5)
AND Ref(MA1, -4) > Ref(MA2,-4)
AND Ref(MA1, -3) > Ref(MA2,-3)
AND Ref(MA1, -2) > Ref(MA2,-2)
AND Ref(MA1, -1) > Ref(MA2,-1)
AND Ref(MA1, 0) > Ref(MA2,-0)
AND MA1 > MA2;

vLINE = Ref( trig , 16 );

Plot(vLINE, "vLINE", colorOrange, styleHistogram|styleOwnScale,0,1,0,-1);
yes because u have written the code for only 1 trigger :)

for both sides use 2 different triggers one for buy one for sell

for eg,

sell = Cross( Ref(MA1, -16), Ref(MA2,-16) ); //and the ma1 > ma2 series
buy = Cross( Ref(MA2, -16), Ref(MA1,-16) );//and the ma2 > ma1 series

you may also have to use ExRem for removing extra signals on same side


Thanks
 
#8
By the way, the full concept is the following:

Code:
MA1 = MA(C, 32);
MA2 = MA(C, 16);

trig = Cross(MA2, MA1);

vLINE = Ref ( trig, 16 );

Plot(vLINE, "vLINE", colorOrange, styleHistogram|styleOwnScale,0,1,0,-1);
So, the formula plots a vertical line 16 preceding periods when trig is true.

However, once trig is true I want to make sure the inversal crossover does not take place by the next 16 periods or trig will not be true anymore :thumb:
 
#9
yes because u have written the code for only 1 trigger :)

for both sides use 2 different triggers one for buy one for sell

for eg,

sell = Cross( Ref(MA1, -16), Ref(MA2,-16) ); //and the ma1 > ma2 series
buy = Cross( Ref(MA2, -16), Ref(MA1,-16) );//and the ma2 > ma1 series

you may also have to use ExRem for removing extra signals on same side


Thanks
mmmm I am not sure...this is not about buy and sell :eek: