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



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


Discussion in Platforms and Indicators

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

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

(login for full post details)
  #1 (permalink)
alexb1995
Ludwigshafen am Rhein
 
 
Posts: 4 since Jan 2017
Thanks: 0 given, 0 received

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

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(609 thanks from 61 posts)
looks_twoSalao's Journalby Salao
(155 thanks from 28 posts)
looks_3Learning to Profit - A journey in algorithms and optionsby Syntax
(114 thanks from 27 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(94 thanks from 30 posts)
looks_5Maybe a little bit different journalby Malykubo
(51 thanks from 32 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
I finally blew up an account
524 thanks
The Crude Dude Oil Trading System
76 thanks
Spoo-nalysis ES e-mini futures S&P 500
63 thanks
The tiyfTradePlanFactory indicator
25 thanks
Building a Crypto Mining Rig
18 thanks
 
(login for full post details)
  #2 (permalink)
milkysahai001
Agra+India
 
 
Posts: 42 since Sep 2016
Thanks: 17 given, 3 received


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
 
(login for full post details)
  #3 (permalink)
alexb1995
Ludwigshafen am Rhein
 
 
Posts: 4 since Jan 2017
Thanks: 0 given, 0 received


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
 
(login for full post details)
  #4 (permalink)
milkysahai001
Agra+India
 
 
Posts: 42 since Sep 2016
Thanks: 17 given, 3 received


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
 
(login for full post details)
  #5 (permalink)
alexb1995
Ludwigshafen am Rhein
 
 
Posts: 4 since Jan 2017
Thanks: 0 given, 0 received

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
 
(login for full post details)
  #6 (permalink)
milkysahai001
Agra+India
 
 
Posts: 42 since Sep 2016
Thanks: 17 given, 3 received

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


futures io Trading Community Platforms and Indicators > "Three days before MA(18) and MA(48) cross each other"


Last Updated on January 25, 2017


Upcoming Webinars and Events

NinjaTrader Indicator Challenge!

Ongoing

Journal Challenge w/$1,800 in prizes!

May 7

The Cold Hard Truth: Maybe I Am Not Good Enough w/Chris Gray @ Earn2Trade

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts