You are here: home » pinescript » demonstrations » print_logs
Translations of this page:
  • en

Print Logs

log.error()

Converts the formatting string and value(s) into a formatted string, and sends the result to the “Pine logs” menu tagged with the “error” debug level.

The formatting string can contain literal text and one placeholder in curly braces {} for each value to be formatted. Each placeholder consists of the index of the required argument (beginning at 0) that will replace it, and an optional format specifier. The index represents the position of that argument in the function's argument list.

Arguments

message (series string) Log message.

Example

  1. //@version=6
  2. strategy("My strategy", overlay = true, process_orders_on_close = true)
  3. bracketTickSizeInput = input.int(1000, "Stoploss/Take-Profit distance (in ticks)")
  4.  
  5. longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
  6. if (longCondition)
  7. limitLevel = close * 1.01
  8. log.info("Long limit order has been placed at {0}", limitLevel)
  9. strategy.order("My Long Entry Id", strategy.long, limit = limitLevel)
  10.  
  11. log.info("Exit orders have been placed: Take-profit at {0}, Stop-loss at {1}", close, limitLevel)
  12. strategy.exit("Exit", "My Long Entry Id", profit = bracketTickSizeInput, loss = bracketTickSizeInput)
  13.  
  14. if strategy.opentrades > 10
  15. log.warning("{0} positions opened in the same direction in a row. Try adjusting `bracketTickSizeInput`", strategy.opentrades)
  16.  
  17. last10Perc = strategy.initial_capital / 10 > strategy.equity
  18. if (last10Perc and not last10Perc[1])
  19. log.error("The strategy has lost 90% of the initial capital!")

log.info()

Converts the formatting string and value(s) into a formatted string, and sends the result to the “Pine logs” menu tagged with the “info” debug level.

The formatting string can contain literal text and one placeholder in curly braces {} for each value to be formatted. Each placeholder consists of the index of the required argument (beginning at 0) that will replace it, and an optional format specifier. The index represents the position of that argument in the function's argument list.

Arguments

message (series string) Log message.

Example

  1. //@version=6
  2. strategy("My strategy", overlay = true, process_orders_on_close = true)
  3. bracketTickSizeInput = input.int(1000, "Stoploss/Take-Profit distance (in ticks)")
  4.  
  5. longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
  6. if (longCondition)
  7. limitLevel = close * 1.01
  8. log.info("Long limit order has been placed at {0}", limitLevel)
  9. strategy.order("My Long Entry Id", strategy.long, limit = limitLevel)
  10.  
  11. log.info("Exit orders have been placed: Take-profit at {0}, Stop-loss at {1}", close, limitLevel)
  12. strategy.exit("Exit", "My Long Entry Id", profit = bracketTickSizeInput, loss = bracketTickSizeInput)
  13.  
  14. if strategy.opentrades > 10
  15. log.warning("{0} positions opened in the same direction in a row. Try adjusting `bracketTickSizeInput`", strategy.opentrades)
  16.  
  17. last10Perc = strategy.initial_capital / 10 > strategy.equity
  18. if (last10Perc and not last10Perc[1])
  19. log.error("The strategy has lost 90% of the initial capital!")

log.warning()

Converts the formatting string and value(s) into a formatted string, and sends the result to the “Pine logs” menu tagged with the “warning” debug level.

The formatting string can contain literal text and one placeholder in curly braces {} for each value to be formatted. Each placeholder consists of the index of the required argument (beginning at 0) that will replace it, and an optional format specifier. The index represents the position of that argument in the function's argument list.

Arguments

message (series string) Log message.

Example

  1. //@version=6
  2. strategy("My strategy", overlay = true, process_orders_on_close = true)
  3. bracketTickSizeInput = input.int(1000, "Stoploss/Take-Profit distance (in ticks)")
  4.  
  5. longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
  6. if (longCondition)
  7. limitLevel = close * 1.01
  8. log.info("Long limit order has been placed at {0}", limitLevel)
  9. strategy.order("My Long Entry Id", strategy.long, limit = limitLevel)
  10.  
  11. log.info("Exit orders have been placed: Take-profit at {0}, Stop-loss at {1}", close, limitLevel)
  12. strategy.exit("Exit", "My Long Entry Id", profit = bracketTickSizeInput, loss = bracketTickSizeInput)
  13.  
  14. if strategy.opentrades > 10
  15. log.warning("{0} positions opened in the same direction in a row. Try adjusting `bracketTickSizeInput`", strategy.opentrades)
  16.  
  17. last10Perc = strategy.initial_capital / 10 > strategy.equity
  18. if (last10Perc and not last10Perc[1])
  19. log.error("The strategy has lost 90% of the initial capital!")
Edit this page
Back to top