18bool trading_window_active(std::int64_t current_ms, std::int64_t start_ms,
19 int script_tf_seconds)
noexcept {
20 if (start_ms == std::numeric_limits<std::int64_t>::min())
return true;
21 const std::int64_t buffer_ms = script_tf_seconds > 0
22 ?
static_cast<std::int64_t
>(script_tf_seconds) * 1000 : 0;
23 return current_ms >= start_ms - buffer_ms;
29 double limit_price,
double stop_price,
double qty,
30 const std::string& comment,
31 const std::string& oca_name,
int oca_type,
37 return detail::IntentEntry{id, is_long, limit_price, stop_price, qty, comment,
38 oca_name, oca_type, qty_type};
42 if (!trading_window_active(current_bar_.timestamp, trade_start_time_, script_tf_seconds_))
44 adapter_.set_configuration(config_);
47 adapter_.entry(
id, is_long, limit_price, stop_price, qty, comment, oca_name,
52 double qty,
double qty_percent,
bool immediately) {
54 return detail::IntentClose{id, comment, qty, qty_percent, immediately};
58 adapter_.set_configuration(config_);
60 adapter_.close(
id, comment, qty, qty_percent, immediately);
64 double qty,
double qty_percent,
bool immediately,
65 std::uint64_t callsite_token) {
67 return detail::IntentCloseToken{id, comment, qty, qty_percent, immediately,
72 if (!trading_window_active(current_bar_.timestamp, trade_start_time_, script_tf_seconds_))
74 adapter_.set_configuration(config_);
76 adapter_.close(
id, comment, qty, qty_percent, immediately, callsite_token);
81 return detail::IntentCloseAll{};
85 if (!trading_window_active(current_bar_.timestamp, trade_start_time_, script_tf_seconds_))
87 adapter_.set_configuration(config_);
93 double limit_price,
double stop_price,
94 double trail_points,
double trail_offset,
95 double trail_price,
double qty_percent,
96 const std::string& comment,
double qty,
97 const std::string& oca_name,
98 double profit_ticks,
double loss_ticks) {
100 return detail::IntentExit{id, from_entry, limit_price, stop_price, trail_points,
101 trail_offset, trail_price, qty_percent, comment, qty,
102 oca_name, profit_ticks, loss_ticks};
106 if (!trading_window_active(current_bar_.timestamp, trade_start_time_, script_tf_seconds_))
108 adapter_.set_configuration(config_);
110 trail_price, qty_percent, comment, qty, oca_name, profit_ticks,
112 adapter_.exit(
id, from_entry, limit_price, stop_price, trail_points, trail_offset,
113 trail_price, qty_percent, comment, qty, oca_name, profit_ticks,
118 const std::string& from_entry,
119 const std::string& comment) {
121 return detail::IntentExitCancelBracket{exit_id, from_entry, comment};
125 if (!trading_window_active(current_bar_.timestamp, trade_start_time_, script_tf_seconds_))
127 adapter_.set_configuration(config_);
129 adapter_.exit_cancel_bracket(exit_id, from_entry, comment);
134 return detail::IntentCancel{id};
138 adapter_.set_configuration(config_);
145 return detail::IntentCancelAll{};
149 adapter_.set_configuration(config_);
151 adapter_.cancel_all();
155 double limit_price,
double stop_price,
156 const std::string& oca_name,
int oca_type) {
158 return detail::IntentOrder{id, is_long, qty, limit_price, stop_price, oca_name,
163 if (!trading_window_active(current_bar_.timestamp, trade_start_time_, script_tf_seconds_))
165 adapter_.set_configuration(config_);
167 adapter_.order(
id, is_long, qty, limit_price, stop_price, oca_name, oca_type);
void strategy_cancel_all()
void strategy_entry(const std::string &id, bool is_long, double limit_price=std::numeric_limits< double >::quiet_NaN(), double stop_price=std::numeric_limits< double >::quiet_NaN(), double qty=std::numeric_limits< double >::quiet_NaN(), const std::string &comment={}, const std::string &oca_name={}, int oca_type=0, int qty_type=-1)
void strategy_order(const std::string &id, bool is_long, double qty, double limit_price=std::numeric_limits< double >::quiet_NaN(), double stop_price=std::numeric_limits< double >::quiet_NaN(), const std::string &oca_name={}, int oca_type=0)
void strategy_exit_cancel_bracket(const std::string &exit_id, const std::string &from_entry, const std::string &comment={})
void strategy_close_all()
void strategy_cancel(const std::string &id)
PineStrategyConfig config_
void strategy_exit(const std::string &id, const std::string &from_entry, double limit_price, double stop_price, double trail_points=std::numeric_limits< double >::quiet_NaN(), double trail_offset=std::numeric_limits< double >::quiet_NaN(), double trail_price=std::numeric_limits< double >::quiet_NaN(), double qty_percent=100.0, const std::string &comment={}, double qty=std::numeric_limits< double >::quiet_NaN(), const std::string &oca_name={}, double profit_ticks=std::numeric_limits< double >::quiet_NaN(), double loss_ticks=std::numeric_limits< double >::quiet_NaN())
void strategy_close(const std::string &id, const std::string &comment={}, double qty=std::numeric_limits< double >::quiet_NaN(), double qty_percent=std::numeric_limits< double >::quiet_NaN(), bool immediately=false)
bool capture_pre_roll_command(const NativeStrategyHost &host, std::int64_t label_ms, const PineStrategyConfig &config, MakePayload &&make_payload)
void admit_strategy_exit(const std::string &id, const std::string &from_entry, double limit_price, double, double, double trail_offset, double trail_price, double, const std::string &comment, double, const std::string &oca_name, double profit_ticks, double loss_ticks)
void admit_strategy_close_token(const std::string &id, const std::string &comment, double qty, double qty_percent, bool immediately, std::uint64_t)
void admit_strategy_cancel(const std::string &id)
void admit_strategy_close_all() noexcept
void admit_strategy_entry(const std::string &id, bool, double limit_price, double stop_price, double, const std::string &comment, const std::string &oca_name, int, int)
void admit_strategy_exit_cancel_bracket(const std::string &exit_id, const std::string &from_entry, const std::string &comment)
void admit_strategy_close(const std::string &id, const std::string &comment, double, double, bool)
void admit_strategy_cancel_all() noexcept
void admit_strategy_order(const std::string &id, bool, double, double limit_price, double stop_price, const std::string &oca_name, int)