simple buy/sell indicator help

#1
Please help on how should I write the AFL:

Criteria to buy
First day: Close Cross Moving Average 20days(MA20)
Second day: Open Above MA20
If second day fulfill, buy at OPEN
If second day not fulfill, do nothing

Code:
MA20=MA(C,20);
Buy = Cross(C,MA20);
SecondDay = Open > MA20
Sell = Cross(MA20,C);
 

johnnypareek

Well-Known Member
#2
Please help on how should I write the AFL:

Criteria to buy
First day: Close Cross Moving Average 20days(MA20)
Second day: Open Above MA20
If second day fulfill, buy at OPEN
If second day not fulfill, do nothing

Code:
MA20=MA(C,20);
Buy = Cross(C,MA20);
SecondDay = Open > MA20
Sell = Cross(MA20,C);
try this

MA20=MA(C,20);
SecondDay = Open > MA20
Buy = ref(Cross(C,MA20),-1) and o>ma20;

Sell = Cross(MA20,C);
 

mastermind007

Well-Known Member
#3
MA20=MA(C,20);
SecondDay = Open > MA20
Buy = ref(Cross(C,MA20),-1) and o>ma20;

Sell = Cross(MA20,C);
Code provided by Johnny is correct except one problem, so I am fixing it. I hope Johnny does not mind this.
fishmarket, Remove the highlighted line. (a) Its not used and (b) it will cause compile error !!!
 

Similar threads