Printing true or false

 

I have a program which includes a 'Use Trade Time' option and want to display the answer 'true' or 'false' on a chart.

All I can get it to print is '0' zero. Please can anybody help me?

Thanks

Ken

 
Kenneth Bachelor: I have a program which includes a 'Use Trade Time' option and want to display the answer 'true' or 'false' on a chart. All I can get it to print is '0' zero. Please can anybody help me?
Probably yes, but how? You have not shown your code attempt, so how do you expect us to see what you are doing wrong and offer you advice?
 
Kenneth Bachelor:

I have a program which includes a 'Use Trade Time' option and want to display the answer 'true' or 'false' on a chart.

All I can get it to print is '0' zero. Please can anybody help me?

Thanks

Ken

try (string)(bool-variable)
 
Fernando Carreiro:
Probably yes, but how? You have not shown your code attempt, so how do you expect us to see what you are doing wrong and offer you advice?

I have the following in my code and it all works except the one in red which displays '0'

I have extern bool
   UseTradeTime            = true;

and
        Comment(
        "Magic No: "                      + IntegerToString(MagicNumber)                + "         " +
        "Initial T/P: "                   + IntegerToString(InitialTakeProfit)          + "            " +  
        "Group Mulitplier: "              + DoubleToString (GroupMultiplier, 2)         + "       " +
        "Max Trades in Series:  "          + IntegerToString(MaxTradeInSeries)           + "    " +
        "Initial Lots Percent Risk: "     + DoubleToString (InitialLotsPercentRisk, 3)  + "%   " +
        "Open next series after bars: "   + IntegerToString(OpenNextSeriesAfterBars)    + "    " +"\n"+  
        "Stop-Loss: "                     + IntegerToString (StopLoss)                  + "        " +
        "Add T/P Pips:  "                  + IntegerToString(AddTPPips)                 + "       " +
        "Trade Size Increase: "           + DoubleToString (TradeSizeIncrease, 2)       + "           " +
        "Use Trade Time: "                + (UseTradeTime)                              + "           " + 
        "Trade Time Start: "              + TradeTime_Start                             + "           " +
        "Trade Time End: "                + TradeTime_End                               + "    " +
                 "\n"   )

 
Carl Schreiber:
try (string)(bool-variable)
That was my first thought Carl, but it just prints '0'
 
Kenneth Bachelor:

I have the following in my code and it all works except the one in red which displays '0'

I have extern bool
   UseTradeTime            = true;

and
        Comment(
        "Magic No: "                      + IntegerToString(MagicNumber)                + "         " +
        "Initial T/P: "                   + IntegerToString(InitialTakeProfit)          + "            " +  
        "Group Mulitplier: "              + DoubleToString (GroupMultiplier, 2)         + "       " +
        "Max Trades in Series:  "          + IntegerToString(MaxTradeInSeries)           + "    " +
        "Initial Lots Percent Risk: "     + DoubleToString (InitialLotsPercentRisk, 3)  + "%   " +
        "Open next series after bars: "   + IntegerToString(OpenNextSeriesAfterBars)    + "    " +"\n"+  
        "Stop-Loss: "                     + IntegerToString (StopLoss)                  + "        " +
        "Add T/P Pips:  "                  + IntegerToString(AddTPPips)                 + "       " +
        "Trade Size Increase: "           + DoubleToString (TradeSizeIncrease, 2)       + "           " +
        "Use Trade Time: "                + (UseTradeTime)                              + "           " + 
        "Trade Time Start: "              + TradeTime_Start                             + "           " +
        "Trade Time End: "                + TradeTime_End                               + "    " +
                 "\n"   )

  1. use the "#property strict" in the begining of your code.
  2. use the StringConcatenate() function instead of stringing everything together. ( Comment() function already does concatenation )
// This code was not compiled/tested and only serves as an example

#property strict

// ...

extern bool
   UseTradeTime = true; 

// ...

   Comment(
      "Magic No: ",                    MagicNumber,                                 "         ",
      "Initial T/P: ",                 InitialTakeProfit,                           "            ",  
      "Group Mulitplier: ",            DoubleToString( GroupMultiplier, 2 ),        "       ",
      "Max Trades in Series:  ",       MaxTradeInSeries,                            "    ",
      "Initial Lots Percent Risk: ",   DoubleToString( InitialLotsPercentRisk, 3 ), "%   ",
      "Open next series after bars: ", OpenNextSeriesAfterBars,                     "    \n",  
      "Stop-Loss: ",                   StopLoss,                                    "        ",
      "Add T/P Pips:  ",               AddTPPips,                                   "       ",
      "Trade Size Increase: ",         DoubleToString( TradeSizeIncrease, 2 ),      "           ",
      "Use Trade Time: ",              UseTradeTime,                                "           ", 
      "Trade Time Start: ",            TradeTime_Start,                             "           ",
      "Trade Time End: ",              TradeTime_End,                               "    \n"
      );
 
Fernando Carreiro:
  1. use the "#property strict" in the begining of your code.
  2. use the StringConcatenate() function instead of stringing everything together.
Thanks Fernando. I think I'm just going to have to leave the line out of what's displayed, because it's totally beyond me.
 
Kenneth Bachelor: Thanks Fernando. I think I'm just going to have to leave the line out of what's displayed, because it's totally beyond me.
Review the post as I have edited it! It is not that difficult! Its just minor changes!
 

Or you could use a turnary operator

"..."+(bool_var?"true":"false")+"...";
 
Kenneth Bachelor:
That was my first thought Carl, but it just prints '0'

Really?

I am currently using

bool isTrue = true;
Print(..,"  isTrue: ",(string)isTrue,...);

and it prints everytime:

... isTrue: true ...

Reason: