How to use if() function to check value returned from cross() function - AmiBroker | futures io social day trading
futures io futures trading


How to use if() function to check value returned from cross() function
Updated: Views / Replies:1,333 / 4
Created: by vampirelord Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

How to use if() function to check value returned from cross() function

  #1 (permalink)
Trading Apprentice
Hong Kong
 
Futures Experience: Beginner
Platform: Amibroker
Favorite Futures: Stocks
 
Posts: 1 since Feb 2014
Thanks: 0 given, 0 received

How to use if() function to check value returned from cross() function

Dear all, I am a beginner to Amibroker & AFL.
Actually, I want to implement the following logic:
I want to generate the buy signal when both EMA and MACD shows crossover but they need not to happen on the same day (e.g. EMA shows crossover today, and 3 days later, MACD shows crossover, I still buy the stock)
The following gives more details:
When 10 days EMA crossovers 20 days EMA, remember this as part of the buying signal by assigning TRUE to a variable.
Then, look at MACD, if the MACD line crossovers signal line, remember this buying signal by assigning TRUE to another variable.
After that, check both buying signal. If both are TRUE, buy the stock.

I would like to use if() function to check value returned from cross() function. However, an error occurs. I know cross() function returns an array with the value of true/flase or 1/0 and may be that's why causing the error.
Can anyone tell me how to extra the "true" or "false" value from cross() function and can be checked by if() function?
Thank you very much!

Reply With Quote
 
  #2 (permalink)
Trading Apprentice
Rome/Italy
 
Futures Experience: Intermediate
Platform: Amibroker, prorealtime, webank
Favorite Futures: Stocks
 
Posts: 2 since Feb 2014
Thanks: 0 given, 0 received

I think you have to use "IIF" instruction instead of "if"
"IIf" function deals array, "if" deals variables.
See the manual for IIF function or post your TS.

Reply With Quote
 
  #3 (permalink)
Banned: Rude behavior towards others
London UK
 
Futures Experience: Advanced
Platform: -
Favorite Futures: any
 
Posts: 18 since Mar 2014
Thanks: 3 given, 9 received


you don't need if or IIf for this.

 
Code
dd = Day();
ema1 = EMA(C, 10);
ema2 = EMA(C, 20);
cross1 = Cross( ema1, ema2);
cross2 = Cross( MACD(), Signal() );
Buy = ema1 > ema2 AND cross2 AND ValueWhen( cross1, dd ) != ValueWhen( cross2, dd );

Reply With Quote
 
  #4 (permalink)
Trading Apprentice
paris France
 
Futures Experience: Advanced
Platform: Amibroker Motive Wave
Favorite Futures: Stocks
 
Posts: 5 since Mar 2014
Thanks: 1 given, 1 received

with the function BarSince

You can use the function BarsSince for choose the max delai for Cross2 :

delai = Param("max delai since cross2",3,1,14,1);
ema1 = EMA(C, 10);
ema2 = EMA(C, 20);
cross1 = Cross( ema1, ema2);
cross2 = Cross( MACD(), Signal() );
Buy = ema1 > ema2 AND BarsSince(cross1) <= delai AND BarsSince(cross1) >= 1 AND Cross2 ;

// like says occasionallurker, you don't need if or iif

Reply With Quote
 
  #5 (permalink)
Banned: Rude behavior towards others
London UK
 
Futures Experience: Advanced
Platform: -
Favorite Futures: any
 
Posts: 18 since Mar 2014
Thanks: 3 given, 9 received


bob303 View Post
You can use the function BarsSince for choose the max delai for Cross2 :

delai = Param("max delai since cross2",3,1,14,1);
ema1 = EMA(C, 10);
ema2 = EMA(C, 20);
cross1 = Cross( ema1, ema2);
cross2 = Cross( MACD(), Signal() );
Buy = ema1 > ema2 AND BarsSince(cross1) <= delai AND BarsSince(cross1) >= 1 AND Cross2 ;

// like says occasionallurker, you don't need if or iif


Your code is using barindex. So it will work in EOD time frame only. If he wants to use intraday with day delay then this code should work. Not tested.

 
Code
dd = DaysSince1900();

ema1 = EMA( C, 10 );
ema2 = EMA( C, 20 );

cross1 = Cross( ema1, ema2 );
cross2 = Cross( MACD(), Signal() );

// delay of x days
delay = ValueWhen( cross2, dd ) - ValueWhen( cross1, dd ) >= 3;

Buy = ema1 > ema2 AND cross2 AND delay;

Reply With Quote

Reply



futures io > > > > How to use if() function to check value returned from cross() function

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help about TOS function alchemist74 ThinkOrSwim 2 December 31st, 2013 10:26 AM
DateTime2ELTime Function westsider EasyLanguage Programming 2 October 28th, 2012 05:36 PM
Tables function aquarian1 Feedback and Announcements 3 December 23rd, 2011 10:42 PM
NT7 - toggle-function while global cross hair usage ? max-td NinjaTrader 2 October 22nd, 2010 12:49 PM


All times are GMT -4. The time now is 05:54 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, 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
Page generated 2017-12-17 in 0.09 seconds with 19 queries on phoenix via your IP 54.163.210.170