Lipi Reference
Lipi

Functions

strategy()

Declares the script as a strategy: a script that places simulated orders and reports their performance. It is used in place of `indicator`, as the first statement of the script. Besides the display settings it shares with `indicator`, it sets how orders are sized and filled: `initial_capital`, `default_qty_type` and `default_qty_value` for position size, `commission_type` and `commission_value` for costs, `pyramiding` for how many entries in the same direction are allowed, and `process_orders_on_close`, `calc_on_order_fills` and `calc_on_every_tick` for when orders are evaluated.

Syntax

                strategy(const string title, const string shorttitle, const bool overlay, const string format, const int precision, const int pyramiding, const bool calc_on_order_fills, const bool calc_on_every_tick, const string default_qty_type, const float default_qty_value, const float initial_capital, const string commission_type, const float commission_value, const bool process_orders_on_close, const int max_lines_count, const int max_boxes_count, const int max_labels_count, const int max_polylines_count, const bool behind_chart) → void
              

Arguments

title required const string
shorttitle const string
overlay const bool
format const string
precision const int
pyramiding const int
calc_on_order_fills const bool
calc_on_every_tick const bool
default_qty_type const string
default_qty_value const float
initial_capital const float
commission_type const string
commission_value const float
process_orders_on_close const bool
max_lines_count const int
max_boxes_count const int
max_labels_count const int
max_polylines_count const int
behind_chart const bool

Return Type

void

Example


          //@lipi=2
strategy("MA Cross Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.fixed, default_qty_value=1, commission_type=strategy.commission_percent, commission_value=0.1)
fast = talib.sma(close, 10)
slow = talib.sma(close, 30)
if talib.crossover(fast, slow) {
    strategy.entry("Long", strategy.long)
}
if talib.crossunder(fast, slow) {
    strategy.close("Long")
}
plot(fast, title="Fast MA", color=color.green)
plot(slow, title="Slow MA", color=color.red)