IF statement inside FileWrite

 

Hello,

The code I have, produces nicely the OHLC values as expected, but I also would like to add a new column giving me the Color of Candle (either "White", "Black", or "Doji").

I am trying to add it via an "IF" statement inside FileWrite function as follows:

FileWrite(fileh,
        Symbol(),
        Period(),
       Open[barind],
       High[barind],
       Low[barind],
       Close[barind],
       if (Close[barInd]>Open[barInd]) Print("White")        // this is the "Color of Candle" example for a white (raising) candle...
 );


Above giving syntax error (looks like the semicolons, etc, or even the whole structuring of "IF" statement is wrong and I simply can't figure out what route to take from here :(

Can someone please point me to the right direction here?

-ModestOne 

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Create a variable
    string candleColor;
    if(Close[barInd]>Open[barInd]) candleColor = "White";
    else                           candleColor = "Black";
    FileWrite(fileh,
            Symbol(),
            Period(),
           Open[barind],
           High[barind],
           Low[barind],
           Close[barind],
           candleColor
    );
    Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
    FileWrite(fileh,
            Symbol(),
            Period(),
           Open[barind],
           High[barind],
           Low[barind],
           Close[barind],
           Close[barInd]>Open[barInd] ? "White" : "Black"
    );

 
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it

  2. Create a variable
    string candleColor;
    if(Close[barInd]>Open[barInd]) candleColor = "White";
    else                           candleColor = "Black";
    FileWrite(fileh,
            Symbol(),
            Period(),
           Open[barind],
           High[barind],
           Low[barind],
           Close[barind],
           candleColor
    );
    Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
    FileWrite(fileh,
            Symbol(),
            Period(),
           Open[barind],
           High[barind],
           Low[barind],
           Close[barind],
           Close[barInd]>Open[barInd] ? "White" : "Black"
    );

Perfect! This works! Thanks a ton, whroeder1 !!
Reason: