algorithmic-trading

Tradingview Pine script `strategy.exit` and `strategy.close` don't respect `from_entry` value

怎甘沉沦 提交于 2021-02-11 15:17:58
问题 I have several different entries in my strategy, and I want to assign separate stop losses to them: // @version=4 strategy("Test strategy") strategy.entry("E0", strategy.long, limit=10000, when=close[1] > 10000) strategy.entry("E1", strategy.long, limit=10000, when=close[1] > 10000) strategy.exit("SL-E0", "E0", stop=9000) strategy.exit("SL-E1", "E1", stop=9500) As far as I understand the documentation (https://www.tradingview.com/pine-script-reference/#fun_strategy{dot}exit) the 2nd parameter

Converting series integer to integer in pinescript

China☆狼群 提交于 2021-02-10 14:16:26
问题 I am using pinescript, and I have been trying to figure out why the following code does not work. The console keeps showing that series[integer] cannot output integer. I understand that series is not compatible with non-series values. If this is the case, is there a way to change series[integer] to integer? The following code does not work: x = barssince(crossover(cci,100)) y = barssince(crossover(100,cci)) xy = x-y //in this case the xy value is 9 z = highest(cci, abs(xy)) plot(z) The

Efficiently calculating point of control with pandas

馋奶兔 提交于 2021-02-08 10:35:13
问题 My algorithm stepped up from 35 seconds to 15 minutes runtime when implementing this feature over a daily timeframe. The algo retrieves daily history in bulk and iterates over a subset of the dataframe (from t0 to tX where tX is the current row of iteration). It does this to emulate what would happen during the real time operations of the algo. I know there are ways of improving it by utilizing memory between frame calculations but I was wondering if there was a more pandas-ish implementation

What is the correct way to define MQL4 “#import of static class methods”?

 ̄綄美尐妖づ 提交于 2021-02-08 02:16:31
问题 What I'm trying to achieve is define classes (using MQL4 ) in separate files and use the methods from those classes in the main code. Essentially importing static class member functions. class example{ // ____ in example.mq4 public: static void myfunction(void) export { .. do something .. } } class example{ // ____ in example.mqh public: static void myfunction(void); } #include <example.mqh> // ____ in main.mq4: #import "example.ex4" void example::myfunction(void); #import Results in a

What is the correct way to define MQL4 “#import of static class methods”?

蹲街弑〆低调 提交于 2021-02-08 02:15:59
问题 What I'm trying to achieve is define classes (using MQL4 ) in separate files and use the methods from those classes in the main code. Essentially importing static class member functions. class example{ // ____ in example.mq4 public: static void myfunction(void) export { .. do something .. } } class example{ // ____ in example.mqh public: static void myfunction(void); } #include <example.mqh> // ____ in main.mq4: #import "example.ex4" void example::myfunction(void); #import Results in a

What is the correct way to define MQL4 “#import of static class methods”?

↘锁芯ラ 提交于 2021-02-08 02:15:29
问题 What I'm trying to achieve is define classes (using MQL4 ) in separate files and use the methods from those classes in the main code. Essentially importing static class member functions. class example{ // ____ in example.mq4 public: static void myfunction(void) export { .. do something .. } } class example{ // ____ in example.mqh public: static void myfunction(void); } #include <example.mqh> // ____ in main.mq4: #import "example.ex4" void example::myfunction(void); #import Results in a

What is the correct way to define MQL4 “#import of static class methods”?

佐手、 提交于 2021-02-08 02:14:43
问题 What I'm trying to achieve is define classes (using MQL4 ) in separate files and use the methods from those classes in the main code. Essentially importing static class member functions. class example{ // ____ in example.mq4 public: static void myfunction(void) export { .. do something .. } } class example{ // ____ in example.mqh public: static void myfunction(void); } #include <example.mqh> // ____ in main.mq4: #import "example.ex4" void example::myfunction(void); #import Results in a

“alertcondition” fails when the condition comes from a security function

萝らか妹 提交于 2021-02-05 11:12:31
问题 I'm trying to create alerts based on conditions that derive from security functions. Below, the relevant piece of the code, and here is the entire code. s01 = input('BINANCE:BTCUSDT', type=input.symbol) screenerFunc() => triggerA and triggerB c01 = security(s01, res, screenerFunc()) alertcondition(condition=c01, title="Alert", message="Alert!") But I'm getting the following error for the last line: Cannot use a mutable variable as an argument of the security function. Appreciate the help! 回答1

How to detect if in ANY candle in the past 'n' candles meet a certain requirement?

人盡茶涼 提交于 2021-01-29 20:01:36
问题 I'd like to check if ANY candle in the past 'n' candles meet a certain condition. E.g. let's check if any close in the latest 20 candles was higher than 'x': x = 2 n = 20 condition = [ANY of n] > x 回答1: See barssince() and an example showing how to use it here. You can also count the number of occurrences of a condition in the last n bars using: sum(cond ? 1 : 0, len) Disclosure : the link in this answer points to a PineCoders FAQ entry. I am a member of the PineCoders community and I most

n/a value when line.new with if statement in Pine Script TradingView

ぐ巨炮叔叔 提交于 2021-01-24 11:44:37
问题 I wanted to create an indicator that shows when a close crossed over a trend line. Here's the code, here "trendLineCrossover" should show 1.00 on crossover bar and 0.00 on other bars. But actually this shows me 0.00 only on the last bar (and the consecutive area) and on other bars it shows n/a . lineObj = if (syminfo.tickerid == "BINANCE:SRMUSDT") if (barstate.islast) line.new(x1=3380-89, y1=0.9609, x2=3380 , y2=1.0216) line.set_extend(id=lineObj, extend=extend.right) trendLine = line.get