Help with the IF function

 

Hi

I am programming an expert to open buy order when the line of the indicator turns blue and close the sell orders and vice versa

so i identified B as:

double B=iCustom(NULL,0,"Triggerlines",2,0);

and then used it as:

if (B==Blue) {OrderSend(Symbol(),OP_BUY,Lots,Ask,SlipPage,StopLoss,TakeProfit,"Open Buy",MagicNumber,0,Blue)};

And when compiling it shows errors. Can someone help me where did i go wrong, waiting for your reply, and thanks in advance.

 

you don't have a problem with the if, you have a problem with understanding the very basics of this programming language (otherwise you would understand what the error message is trying to tell you) and the usage of the iCustom() function (learning this makes only sense after learning the language).


The answers that you need for solving your problem are too many to explain them in one or two simple postings in a forum thread. You should click on the two links in the upper left of this website that are labeled "Documentation" and "Book" (bookmark these two links in your browser, you will need them very often during the next few months) and study them thoroughly. After you have read (and understood) the book you will still need the documentation of all the functions on a daily basis.


After you have read it all, you will be able to understand why your above code can not work. The variable B will not contain the color of the line, it will contain the price level of one of the lines of the indicator. An indicator can plot up to 8 differently colored lines (buffers) and you requested the price of buffer 2 at bar 0 and obviously you cannot compare a price with a color. Your code should instead check whether the buffer for the blue line contains a value or is empty at the current bar.

 

B is a double value, not a color.


read more about icustom()

Reason: