stuck on code

#1
hi there! I've been trying to make this code now for a few days and it constantly returns results, but they are not correct.

Can anyone please help me?
This is what I have:

Cond1=Cross( MACD ( 12 , 26 ) , Signal ( 12, 26, 9 ) );
Cond2=Cross( StochK ( 15 , 3 ) , StochD ( 15, 3, 3 ) );
Cond3=Close > HHV( High, 100 );
Cond4=Cross( Signal ( 12, 26, 9 ) , MACD ( 12, 25 ));
Cond5=Cross( StochD ( 15, 3, 3 ) , StochK ( 15 , 3 ) );
Buy=Cond1+Cond2+Cond3;
Sell=Cond3+Cond4;
Filter=Buy;
AddColumn( Close, "Close", 1.2 );
AddColumn( MACD ( 12, 26 ) , "MACD", 1.2 );
AddColumn( Signal ( 12, 26, 9 ) , "Signal", 1.2 );
AddColumn( StochK ( 15 , 3 ) , "K%", 1.3 );
AddColumn( StochD ( 15 , 3 , 3 ) , "D%", 1.3 );

Syntax seems to be ok, as I check it before analysis.

What I would like is to filter only buy signals where:
-the MACD has crossed its signal line
-the StochK is higher than the StochD
-the closing price is at a 3-month high

Thanks a lot!
 

vinodkiyer

Well-Known Member
#2
TimeFrameSet(inDaily);
Cond1=Cross( MACD ( 12 , 26 ) , Signal ( 12, 26, 9 ) );
Cond2=Cross( StochK ( 15 , 3 ) , StochD ( 15, 3, 3 ) );
Cond3=Close > HHV( High, 90 );
Cond4=Cross( Signal ( 12, 26, 9 ) , MACD ( 12, 26 ));
Cond5=Cross( StochD ( 15, 3, 3 ) , StochK ( 15 , 3 ) );
Buy=Cond1+Cond2+Cond3;
Sell=Cond4+Cond5;
Filter=Buy | Sell;

//Explorer
AddColumn( IIf(Buy, 66, IIf(Sell, 83,01 )), "Entry/Exit@", formatChar, colorWhite, bkcolor= IIf(Sell,colorDarkRed,colorDarkGreen) );
AddColumn( Close, "Close", 1.2 );
AddColumn( MACD ( 12, 26 ) , "MACD", 1.2 );
AddColumn( Signal ( 12, 26, 9 ) , "Signal", 1.2 );
AddColumn( StochK ( 15 , 3 ) , "K%", 1.3 );
AddColumn( StochD ( 15 , 3 , 3 ) , "D%", 1.3 );
TimeFrameRestore();
 

vinodkiyer

Well-Known Member
#4
lower than 80:

iif(stochk(15,3)<80,1,0);

cross 80 downwards:


cross(80,stochk(15,3));

cross 80 upwards:
cross(stochk(15,3),80);

likewise for stochd
 
#5
thanks again, hmmm, didn't work, or maybe i put it in the wrong place? By the way, when testing again the whole formula doesn't seem to work. I get results of stocks with a much lower closing than in the last 3 months as a buy signal and i get STS's higher than 80. So there seems to be still something wrong with the formula...????

TimeFrameSet(inDaily);
Cond1=Cross( MACD ( 12 , 26 ) , Signal ( 12, 26, 9 ) );
Cond2=Cross( StochK ( 15 , 3 ) , StochD ( 15, 3, 3 ) );
Cond3=Close > HHV( High, 90 );
Cond4=Cross( Signal ( 12, 26, 9 ) , MACD ( 12, 26 ));
Cond5=Cross( StochD ( 15, 3, 3 ) , StochK ( 15 , 3 ) );
Buy=Cond1+Cond2+Cond3;
Sell=Cond4+Cond5;
Filter=Buy | Sell;

//Explorer
AddColumn( IIf(Buy, 66, IIf(Sell, 83,01 )), "Entry/Exit@", formatChar, colorWhite, bkcolor= IIf(Sell,colorDarkRed,colorDarkGreen) );
IIf(StochK(15,3)<80,1,0);
IIf(StochD(15,3,3)<80,1,0);
AddColumn( Close, "Close", 1.2 );
AddColumn( MACD ( 12, 26 ) , "MACD", 1.2 );
AddColumn( Signal ( 12, 26, 9 ) , "Signal", 1.2 );
AddColumn( StochK ( 15 , 3 ) , "K%", 1.3 );
AddColumn( StochD ( 15 , 3 , 3 ) , "D%", 1.3 );
TimeFrameRestore();
 
Last edited:

vinodkiyer

Well-Known Member
#6
I only tried to correct the code which you posted and had replied to your quiery. the iif condition must have a variable or addcolumn, etc. explain your buy/sell conditions
and i will give u one accordingly
 
#7
hi vinodkiyer

BUY:
1) MACD crosses its Signal line from below (already in formula)
2) StochK crosses StochD from below (already in formula)
3) StochK and StochD are below 80 (not yet in formula)
4) 3month high closing price (already in formula)

I would like a few additional ones, please :)

5) EMA (15) is higher than EMA (45)
6) either ROC or OBV are positive respective previous day (ref -1, right?)
7) EOM (10) (is there a function for that in Amibroker) has just crossed from below or is trading above its EMA (14)
8) TRIX has just crossed 0 from below and is positive (is there a function for TRIX in Amibroker?)

SELL:
1) MACD crosses its Signal line from above (already in formula)
2) StochK crosses StochD from above (already in formula)
3) StochK and StochD are above 80

and a few additional ones;
4) EMA (15) is lower than EMA (45)
6) Either ROC or OBV are negative respective previous day
7) EOM (10) has just crossed its EMA (14) from above or is currently below its EMA (14)
8) TRIX has just crossed 0 from above and is negative

Now is it possible to have these conditions as necessary conditions? Meaning, if only one of the buy conditions is not fulfilled, Amibroker will not give a buy signal. Or otherwise, if only one of the Sell signals is not fulfilled, Amibroker will not give a sell signal. Or does amibroker just choose whether there are more buy than sell signals and gives advice accordingly??

Thanks really really a lot for your help! :clap:
 

Similar threads