Join & EARN

FOREX ALGOS { }

Boolean Logic

Logic operations on Boolean values (true/false). Boolean algebra includes operators AND (&&), OR (||), and NOT (!). It underlies all conditional checks in code. Codecademy explains that Boolean logic “is a type of algebra in which results are calculated as either TRUE or FALSE… utilizing three basic logical operators: AND, OR, and NOT”.

  • Definition: Combining conditions with && (AND), || (OR), ! (NOT). For example, (A && B) is true only if both A and B are true.

  • Context: Used in conditions and filters. For instance:

    if ((Close > Open) && (RSI < 30))
    { /* code */ }

    means “price closed up and RSI indicates oversold.”

  • Example:

    // cAlgo: sell if bearish candle AND volatility high
    if (Bars.ClosePrices.Last(0) < Bars.OpenPrices.Last(0) && Indicators.BollingerBands(20,2).Width.LastValue > 0.0010)
    ExecuteMarketOrder(TradeType.Sell, SymbolName, 10000);
    // NinjaScript: only trade on Mon-Fri between 9am-4pm
    if (Time[0].DayOfWeek != DayOfWeek.Saturday && Time[0].Hour >= 9 && Time[0].Hour <= 16)
    EnterLong();