Forex Factory
  • Home
  • Forums
  • News
  • Market
  • Login
  • User/Email: Password:
  • 5:45am
  • Search
Menu
  • Forums
  • News
  • Market
  • Login
  • 5:45am
Search

Options

Search

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

You are viewing
the Crypto Craft
beta version.

Your participation
is appreciated!

Similar Threads

How can I fix single digit value errors in my indicator? 3 replies

Price value compare to two EMAH/L 0 replies

Trading multiple pairs in a single EA 3 replies

Multiple pairs in a single backtest 9 replies

Do you trade multiple EAs from a single account? 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 1
Attachments: How to compare a single value to multiple options?
Exit Attachments

How to compare a single value to multiple options?

  • Post #1
  • Quote
  • First Post: Sep 5, 2018 8:20pm Sep 5, 2018 8:20pm
  •  mtbb
  • | Joined Apr 2015 | Status: Member | 59 Posts
How can this work?... if(Minute()==(11 || 15 || 18) test=true;

Is there a way to have a single value compare multiple options like above? or does it have to be if(Minute()==11 || Minute()==15 || Minute()==18);
  • Post #2
  • Quote
  • Sep 5, 2018 8:28pm Sep 5, 2018 8:28pm
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting mtbb
Disliked
How can this work?... if(Minute()==(11 || 15 || 18) test=true; Is there a way to have a single value compare multiple options like above? or does it have to be if(Minute()==11 || Minute()==15 || Minute()==18);
Ignored
There isn't an easy way to check membership like in python. You will need to create a func...

Inserted Code
void OnStart()
{
   int minutes[] = {1,5,15,23,35,45,53};
   Print(is_in(35, minutes)); //true
}
template<typename T>
bool is_in(T check_value, T &array[])
{
   for(int i=ArraySize(array)-1; i>=0; i--)
      if(check_value == array[i])
         return true;
   return false;
}
  • Post #3
  • Quote
  • Sep 5, 2018 8:39pm Sep 5, 2018 8:39pm
  •  mtbb
  • | Joined Apr 2015 | Status: Member | 59 Posts
Thanks for the quick reply Nicholishen.. I was really trying to stay away from having to make functions and or dealing with arrays for such a simple thing..

So i guess the easy (dumb) answer is .. if(Minute()==11 || Minute()==15 || Minute()==18)test=true;
  • Post #4
  • Quote
  • Sep 5, 2018 8:45pm Sep 5, 2018 8:45pm
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting mtbb
Disliked
Thanks for the quick reply Nicholishen.. I was really trying to stay away from having to make functions and or dealing with arrays for such a simple thing.. So i guess the easy (dumb) answer is .. if(Minute()==11 || Minute()==15 || Minute()==18)test=true;
Ignored
That's not optimal since you're calling the Minute function multiple times. First call the minute function then assign it to a variable then compare the variable multiple times.
  • Post #5
  • Quote
  • Sep 5, 2018 9:06pm Sep 5, 2018 9:06pm
  •  mtbb
  • | Joined Apr 2015 | Status: Member | 59 Posts
Ok... Will only call the minute function once.. I am surprised you cant compare if(x==(y || z ||w))do something;
  • Post #6
  • Quote
  • Sep 5, 2018 11:53pm Sep 5, 2018 11:53pm
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting mtbb
Disliked
Ok... Will only call the minute function once.. I am surprised you cant compare if(x==(y || z ||w))do something;
Ignored
Most programming languages don't allow for expressions like this. In python you can do cool stuff like
Inserted Code
if x in [y, z, w]:
  • Post #7
  • Quote
  • Edited at 4:10am Sep 6, 2018 3:03am | Edited at 4:10am
  •  masterx584
  • | Joined Apr 2016 | Status: By By FF :) | 141 Posts
Quoting Nicholishen
Disliked
{quote} There isn't an easy way to check membership like in python. You will need to create a func... void OnStart() { int minutes[] = {1,5,15,23,35,45,53}; Print(is_in(35, minutes)); //true } template<typename T> bool is_in(T check_value, T &array[]) { for(int i=ArraySize(array)-1; i>=0; i--) if(check_value == array[i]) return true; return false; }
Ignored
You are wrong ...you didn't even created a loop ... u use a template just to look better but u don't know what is a template...what's the point to search an array if not returning the index??...test your code before publishing next time ,is full of compiling errors...a bit sarcastic but i read some of your comments where u were "teaching" about complex classes when u have problems with such simple things.... your code
Inserted Code
void OnStart()
{
    int minutes[] = {1,5,15,23,35,45,53};
    Print(is_in(35, minutes)); //true
}
template<typename T>
bool is_in(T check_value, T &array[])
{
   for(int i=ArraySize(array)-1; i>=0; i--)
   if(check_value == array[i]) return true;
  return false;
}
the correct way...tested
Inserted Code
template<typename Tval,typename Tarr>
int TArraySearch(Tval val,Tarr &arr[])
  {
   for(int i=0; i<ArraySize(arr);++i)
     {
      if(val==arr[i])return i;//return index if val found
     }
   return -1;// val not found
  }
 
void OnTick()
  {
    int minutes[]={1,5,15,23,35,45,53};
    if(TArraySearch(Minute(),minutes)!=-1)test=true; //just like checking if(OrderOpen(Symbol(),etc...)!=-1)...
  }
@mtbb if the function returns a value diverse from -1 you found your number and your test can be true and your value is positioned at
Inserted Code
int index=TArraySearch(Minute(),minutes);
//minutes[index] gives u now full access inside and u can modify it if the array is defined outside OnTick() function
minutes[index] =16;
...when you return true or false from an array you really don't have any ideea what is the value found and is a bit useless...could be 5 or 15 or whatever number inside your array.Always check for index.Returning the index gives you access inside the array..u might use this function with arrays with thousands of elements inside searching for dynamic values to be accessed by your code.
It's show time
  • Post #8
  • Quote
  • Sep 6, 2018 4:12am Sep 6, 2018 4:12am
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting masterx584
Disliked
{quote}i read some of your comments where u were "teaching" about complex classes when u have problems with such simple things.... your code void.
Ignored
Yes, master, I could give lessons on the correct way to use MQL classes -- just like I'm about to give you a lesson on your poorly thought out and aggressive rebuttal...

So let's begin.

Quote
Disliked
...you didn't even created a loop
Not only is this incorrect, but the loop in my code is more efficient than the loop in yours. When you compare our functions you are counting up and calling the ArraySize function on each iteration (O(n)) while my loop counts backwards and only calls ArraySize once (O(1)). I clearly win this one.

Quote
Disliked
u use a template just to look better but u don't know what is a template...
I know very well how to create a template and my code is correct. Yours, on the other hand, has a major bug. You see, you need to check (at compile time) that the <type> of the value being checked against the array matches the <type> of the array being referenced. You've managed to define two different template types when you should have only defined one. This make it possible for your program to allow the following code to compile (which is a major bug)
Inserted Code
string num = "one";
int nums[] = {1,2,3};
if(is_in(num, nums))
   ...
FAIL

Quote
Disliked
what's the point to search an array if not returning the index??
The is_in function is a boolean function for membership testing. The point was to be able to use directly inside of the expression. You don't need or care about the index because you only care to test if the value A is a member of list B. So for my code to work the expression would be
Inserted Code
if(is_in(value, list))
and yours would be
Inserted Code
if(is_in(value, list) >= 0)
Do I even need to ask which one of those is cleaner?

Quote
Disliked
Returning the index gives you access inside the array
This is completely redundant. You just checked whether or not your value exists in the array. If it doesn't then nothing further needs to happen. If it does then you already know the value and there's no need to store the index of its position in your arbitrary list.
  • Post #9
  • Quote
  • Edited at 7:42pm Sep 6, 2018 4:16am | Edited at 7:42pm
  •  masterx584
  • | Joined Apr 2016 | Status: By By FF :) | 141 Posts
Quoting Nicholishen
Disliked
{quote} Yes, master, I could give lessons on the correct way to use MQL classes -- just like I'm about to give you a lesson on your poorly thought out and aggressive rebuttal... So let's begin. {quote} Not only is this incorrect, but the loop in my code is more efficient than the loop in yours. When you compare our functions you are counting up and calling the ArraySize function on each iteration (O(n)) while my loop counts backwards and only calls ArraySize once (O(1)). I clearly win this one. {quote} I know very well how to create a template and...
Ignored
I'm a C++,Java developer and ...there is nothing you can teach me.MQL is a super high level language and has absolutely nothing to do with C++ where u need to build everything from scratch...under MQL u have and can play only with a bunch of high level functions defined by metatrader company...C like ... but not exactly.This doesn't give u the right to call yourself a "programmer"..This language was designed for non programmers... for traders more exactly.Now i hope you get the ideea..if u really want to be a programmer go on some C++ forums and try to publish your code to see some reactions.

Never try to compare MQL with C or C++....looks like but not exactly.
C++ is about DirectX,OpenGl,Multithreading,inline assembly ,disassembler,detouring,hooking,injecting,sniffing,decrypting,tuneling,inputs,drivers,cross platform,polymorphism etc...The entire MQL functions could represent something like 0.01% from C++.
U have no ideea how hard is to play with DirectX from the scratch so ...stay calm and take a deep breath.

And now let's correct your code.
your loop is
Inserted Code
for(int i=ArraySize(array)-1; i>=0; i--)
if(check_value == array[i]) return true;
return false;
Are u serious???
U missed even the brackets .You return false always.U don't check inside the arrayGo compile your code and then come back here to teach.
A loop looks like
Inserted Code
for(int i=0;i<bullshit;i++)
 {
   this is a loop
  }
and the template ... can't use twice the same T as u tried to.Don't drink and code at the same time..
this is not possible.
Inserted Code
template<typename T>
bool is_in(T check_value, T &array[])
this is possible
Inserted Code
template<typename Tval,typename Tarr>
int TArraySearch(Tval val,Tarr &arr[])
U just making fool of yourself..atleast don't teach.Go read some books before.
welcome to my ignore list.
It's show time
  • Post #10
  • Quote
  • Edited at 4:49am Sep 6, 2018 4:31am | Edited at 4:49am
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting masterx584
Disliked
{quote} Are u serious??? a loop look like if(int i=0;i<bullshit;i++) { this is a loop } U missed the brackets bro.You return false always.U don't check inside the arrayGo compile your bullshit and then come back here to teach ...lol... and the template ... can't use twice the same T as u tried to.I bet u write your code into your sleep.. bool is_in(T check_value, T &array[]) this is not possible. welcome to my ignore list.
Ignored
I did compile my original code and I tested it before I posted it.... so let's continue our lesson.

In MQL, just like in C and C++, you don't need braces. If you omit the braces following a loop or expression the control flow is passed to the next loop, expression, or statement in succession. You only need braces to identify a code-block with more than one successive expression. Therefore, these two code blocks are identical.
Inserted Code
template<typename T>
bool is_in(T check_value, T &array[])
{
   for(int i=ArraySize(array)-1; i>=0; i--)
      if(check_value == array[i])
         return true;
   return false;
}

Inserted Code
template<typename T>
bool is_in(T check_value, T &array[])
{
   for(int i=ArraySize(array)-1; i>=0; i--)
   {
      if(check_value == array[i])
      {
         return true;
      }
   }
   return false;
}

Quote
Disliked
bool is_in(T check_value, T &array[]) this is not possible.
I'd highly suggest you study some basic programming concepts before you continue to make yourself look like a complete fool.

Here's a script that compiles. Why don't you try it out for yourself?
Attached File
File Type: mq4 master_whaaaat.mq4   < 1 KB | 167 downloads
1
  • Post #11
  • Quote
  • Sep 6, 2018 5:38am Sep 6, 2018 5:38am
  •  braintheboss
  • Joined Nov 2012 | Status: Coder | 6,431 Posts
Quoting Nicholishen
Disliked
{quote} I did compile my original code and I tested it before I posted it.... so let's continue our lesson. In MQL, just like in C and C++, you don't need braces. If you omit the braces following a loop or expression the control flow is passed to the next loop, expression, or statement in succession. You only need braces to identify a code-block with more than one successive expression. Therefore, these two code blocks are identical. template<typename T> bool is_in(T check_value, T &array[]) { for(int i=ArraySize(array)-1; i>=0; i--) if(check_value...
Ignored
You dont forget he is master ( 584 times ) in C++... If he say you need use braces, accept it
Try don't lose pants never...
Develop Return This Week: 0.1%
1
  • Post #12
  • Quote
  • Sep 6, 2018 5:55am Sep 6, 2018 5:55am
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting braintheboss
Disliked
{quote} You dont forget he is master ( 584 times ) in C++... If he say you need use braces, accept it
Ignored
Hahaha, touche. I graciously accept my defeat. Logic prevails. /s
1
  • Post #13
  • Quote
  • Edited Sep 7, 2018 12:53pm Sep 6, 2018 4:28pm | Edited Sep 7, 2018 12:53pm
  •  VEEFX
  • Joined Jun 2006 | Status: Member | 2,683 Posts
Quoting Nicholishen
Disliked
{quote} Hahaha, touche. I graciously accept my defeat. Logic prevails. /s
Ignored
Glad the "master" has put you also on his ignore. He is just an arrogant jerk as evident by his actions on this thread. First, he was the one to reach out to me via PM and then after a few PM exchanges with the "master" about his idiotic, advanced, super-secured NSA non-hackable algo, he accuses me of stealing ideas his ideas and then puts me on ignore.

master584 - Give your paranoia a break! No one is hacking into your garage to steal your top-secret algo. You got a problem with any of my posts, bring it out in the open and let's have a debate. I can chew up blowhards like you in my sleep on any topic. You simply got scared I would put you i.e. my subscriber/follower on my ignore list. You simply got scared of one of my posts that I have the ability to reverse-engineer any algo given enough time and effort. I have openly acknowledged using almost 80+% of open source code freely available on forums in my own EA. I have also made shout outs to those individuals on their profile and thanked them for their immense contribution. How does that make me a thief? Get the cookoo head checked quickly by a neurologist. You will soon need help if you keep worrying about who is coming after your algo which is generating 100+% of profits every week for past seven years... I am shocked at the kind of morons this factory attracts. First you were in Spain, then USA and now Honk Kong. Keep on thinking someone is coming to get you..... you will end up in a loony bin :-)

If you still think I tried to steal info from you, you have my permission to post all my PMs to you, here, out in the open and let others be the judge. Just like other morons, you will also have a warm welcome to my ever-growing ignore list of dysfunctional degenerates, scumbags and morally bankrupt individuals. Good luck selling your algo to Glodman Sachs like you admitted in your PM. Continue advertising your advanced coding skills but know this. You are no better than any java developer I know who works for me at work. Look in the mirror and ask yourself what you are doing here and find a spot in commercial section. Your pattern of "Subscribe, unsubscribe, PM, unsubscribe, ignore. " hunting and baiting for noobs is just way too common to work around here.
Staying in my lane...
  • Post #14
  • Quote
  • Sep 6, 2018 5:07pm Sep 6, 2018 5:07pm
  •  sakisf
  • Joined Sep 2013 | Status: boreddddd | 3,110 Posts
static int blabla = 0;
static datetime m1time = 0;
if(m1time < iTime(NULL, 1, 0)) {
m1time = iTime(NULL, 1, 0);
blabla = Minute();
switch (blabla){
case 11: test = true; break;
case 15: test = true; break;
case 18: test = true; break;
}
}
1
  • Post #15
  • Quote
  • Sep 6, 2018 5:57pm Sep 6, 2018 5:57pm
  •  Nicholishen
  • Joined Jul 2005 | Status: Member | 1,219 Posts
Quoting sakisf
Disliked
static int blabla = 0; static datetime m1time = 0; if(m1time < iTime(NULL, 1, 0)) { m1time = iTime(NULL, 1, 0); blabla = Minute(); switch (blabla){ case 11: test = true; break; case 15: test = true; break; case 18: test = true; break; } }
Ignored
You could take advantage of switch statement fall-through to save yourself some keystrokes. Unfortunately this will only work with ints and enums.

Inserted Code
   bool test = false;
   switch (Minute()){
      case 11:
      case 15:
      case 18:
         test = true;
   }
1
  • Post #16
  • Quote
  • Last Post: Edited at 8:22pm Sep 6, 2018 7:16pm | Edited at 8:22pm
  •  masterx584
  • | Joined Apr 2016 | Status: By By FF :) | 141 Posts
VEEFX stay calm ,i saw alot of your posts.U are very good attacking traders here on forum without any reason.Your already infamous EA with 10k comments alias "code" lines , can't produce a dime on your demo,even if you steal all the indicators found on the planet and copy paste them into your file .Your CPU is running at 70% because there is no logic into your code.If you cut all the comments your code is reduced to the title only.
About emails ... you came to me trying to steal some info from me too...All your emails are ASKING ASKING and ASKING info about my system.I never came to you and never asked about your EA since i'm profitable.Only desperate loosers act as you did.Maybe u lost alot in the markets and u are trying now to recover but your methods are very questionable.Who can't make a dime on demo can't make a dime on live.
I saw posts where u desperately asking a guy to give you his code because u think that the code is similar to yours etc...
Be smart enough and follow my TE..u might learn something.Don't bother to respond ,you are on my list too.I'll send u a postcard at Christmas .Have a great trading day as always.
PS. I detect the initial market wave where your EA will see it a few hours later...when is turning back.
Don't talk bu***hit about my anti NSA pentested system.Didn't you asked me how to hide your MAC Adress?
It's show time
1
Thread Tools Search this Thread
Show Printable Version Show Printable Version
Email This Thread Email This Thread
Search this Thread:

Advanced Search

  • Platform Tech
  • /
  • How to compare a single value to multiple options?
  • Reply to Thread
0 traders viewing now
Top of Page

You are viewing
the Crypto Craft
beta version.

Your participation
is appreciated!

You are viewing
the Crypto Craft
beta version.

Your participation
is appreciated!

  • Facebook
  • Twitter
CC Website
  • Homepage
  • Search
  • Members
  • User Guide
  • Report a Bug
CC Products
  • Forums
  • News
  • Market
About CC
  • Mission
  • Products
  • Blog
  • Contact
Follow CC
  • Facebook
  • Twitter

Other Markets:

  • Forex Factory
  • Energy EXCH
  • Metals Mine

Crypto Craft™ is a brand of Fair Economy, Inc.

Terms of Service / ©2019