NexusFi: Find Your Edge


Home Menu

 





"Three days before MA(18) and MA(48) cross each other"


Discussion in Platforms and Indicators

Updated
    1. trending_up 1,614 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

"Three days before MA(18) and MA(48) cross each other"

  #1 (permalink)
alexb1995
Ludwigshafen am Rhein
 
Posts: 4 since Jan 2017
Thanks Given: 0
Thanks Received: 0

Hi,

I'm pretty new to AFL and have the following issue, where two conditions need to be true to return a buy signal:
I'd like to express that if a 48 days average and an 18 days average cross each other, plus the 18 days average is at the day of the crossing higher than 3 days before, it should give me a buy signal.

I tried the following:
 
Code
period1 = MA(Close, 48);
period2 = MA(Close, 18);

crossing = Cross(period2, period1);
rising = Ref(period2, crossing) > Ref(period2, Ref(crossing, -3)); //Close at Day of crossing > 3 days before

buy = crossing and rising;
Unfortunately this doesn't work, i guess it is because Cross() simply gives out 0 or 1 (false/true) for each day, and not a date, so it's not possible to use Ref() on its result.


I hope my concern is understandable and it would help me a lot if anybody has a tipp.

Thank you!

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
56 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #2 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3


alexb1995 View Post
Hi,

I'm pretty new to AFL and have the following issue, where two conditions need to be true to return a buy signal:
I'd like to express that if a 48 days average and an 18 days average cross each other, plus the 18 days average is at the day of the crossing higher than 3 days before, it should give me a buy signal.

I tried the following:
 
Code
period1 = MA(Close, 48);
period2 = MA(Close, 18);

crossing = Cross(period2, period1);
rising = Ref(period2, crossing) > Ref(period2, Ref(crossing, -3)); //Close at Day of crossing > 3 days before

buy = crossing and rising;
Unfortunately this doesn't work, i guess it is because Cross() simply gives out 0 or 1 (false/true) for each day, and not a date, so it's not possible to use Ref() on its result.


I hope my concern is understandable and it would help me a lot if anybody has a tipp.

Thank you!

your concern is a bit ambiguous. but as far as i got it, you can try this:

MA1 = MA(C, 48);
MA2 = MA(C, 18);

Buy = Cross(MA2, MA1) AND Close > Ref(Close, -3);

and please read the amibroker guide and understand the basics of afl coding. amibroker doesn't backtests the program without buy, short, sell and cover conditions. all 4 are required.

Reply With Quote
  #3 (permalink)
alexb1995
Ludwigshafen am Rhein
 
Posts: 4 since Jan 2017
Thanks Given: 0
Thanks Received: 0


Thank you for your answer!

Since English is not my first language, I am giving my best to express myself clearly, so sorry for any misunderstanding.


 
Code
Buy	=	Cross(MA2, MA1) AND Close > Ref(Close, -3);
Doesn't Ref(Close, -3) refer to the closing price three days ago? (as I red on the amibroker online guide)

What I want is to compare the closing price of the day where MA and MA2 cross, with the closing price three days before the crossing.
Won't your code compare the closing price of the crossing with the closing price three days starting from today?


Thank you!

Reply With Quote
  #4 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3


alexb1995 View Post

Won't your code compare the closing price of the crossing with the closing price three days starting from today?


Thank you!

as i said, i didn't exactly get what you wanted, that's why the error. English is not my first language too.

MA1 = MA(C, 48);
MA2 = MA(C, 18);

Crossing = ValueWhen(Cross(MA2, MA1), Close, 1);
Rising = IIf(ValueWhen(Crossing,Close,1) > Ref(Close, -3), 1, 0);

Buy = Cross(MA2, MA1) AND Rising;

now, i am not an expert at coding, so i am not sure about the reference to close of 3 candles previous to Crossing, but i think the above code should do it.

if it doesn't, check this link https://www.amibroker.com/guide/afl/valuewhen.html

from what i know, what you want can be accomplished by the ValueWhen function.

Reply With Quote
  #5 (permalink)
alexb1995
Ludwigshafen am Rhein
 
Posts: 4 since Jan 2017
Thanks Given: 0
Thanks Received: 0

Okay good, I guess you got it now

Your code looks good I didn't knew the ValueWhen() Function. I'm gonna try it.

Thank you very much!

Reply With Quote
  #6 (permalink)
milkysahai001
Agra+India
 
Posts: 42 since Sep 2016
Thanks Given: 17
Thanks Received: 3

ignore the earlier one. it should be :

MA1 = MA(C, 48);
MA2 = MA(C, 18);

Crossing = ValueWhen(Cross(MA2, MA1), Close, 1);
Rising = IIf(ValueWhen(Crossing,Close,1) > Ref(Close, -3), 1, 0);

Buy = Cross(MA2, MA1) AND Rising == 1;

hope it works. good luck!

Reply With Quote





Last Updated on January 25, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts