logo
Tags down

shadow

Pinescript Strategy Error when trying to sell


By : Wan Cl
Date : September 15 2020, 06:00 PM
To fix the issue you can do Candidate to problems in your code (assuming v4):
1) According to the reference manual (https://www.tradingview.com/pine-script-reference/v4), you need to inform strategy.close the same ID of the open trade you're trying to close, "buy", in this case, as follows:
code :
strategy.close("buy", when = window() and sell)


Share : facebook icon twitter icon

Mysql - Woocommerce Cross Sell & Up Sell Single Product


By : Sun
Date : March 29 2020, 07:55 AM
hope this fix your issue It looks like the problem is with the way you are getting the cross sell id's, I believe what you have is for an older version of WC, you can change your code as follows:
Replace:
code :
$crosssell_ids = get_post_meta( get_the_ID(), '_crosssell_ids' ); 
$crosssell_ids = $crosssell_ids[0];
global $product;
$crosssell_ids = $product->get_cross_sell_ids();
'post__in' => '$crosssell_ids'
'post__in' => $crosssell_ids

How to transform Momentum strategy scripts to alert in pinescript?


By : user1859386
Date : March 29 2020, 07:55 AM
To fix the issue you can do
Can anyone help me to transform the mom strategy pine-script codes to the alert?
code :
//@version=3
study("Momentum Alert", overlay=true)
length = input(12) 
price = close

momentum(seria, length) =>
    mom = seria - seria[length]
    mom

mom0 = momentum(price, length)
mom1 = momentum(mom0, 1)

// Create alert conditions
alertcondition(condition=mom0 > 0 and mom1 > 0,
     message="Momentum increased")

alertcondition(condition=mom < 0 and mom1 < 0,
     message="Momentum decreased")

// Output something
plot(series=mom0)

Why sma is so different with wma in for loop with pinescript?


By : eilon
Date : March 29 2020, 07:55 AM
may help you . I'm trying to sum MA like below with tradingview's pinescript. , sma has a problem. Use sma written in pine instead:
code :
//@version=3
study("My Script")

pine_sma(src, len) =>
    sum = 0.0
    for i = 0 to len - 1
        sum := sum + src[i] / len
    sum

sum_ma = 0.0
for i = 1 to 30
    sum_ma := sum_ma + i * pine_sma(close[i], 1)
plot(sum_ma, color=blue)

sum_ma := 0
for i = 1 to 30
    sum_ma := sum_ma + i * wma(close[i], 1)
plot(sum_ma, color=red)

Struggling with v2 to v4 pinescript Conversion, "Cannot modify global variable inside function" Error


By : user3535926
Date : March 29 2020, 07:55 AM
To fix the issue you can do Struggling with v2 to v4 pinescript Conversion, "Cannot modify global variable inside function" Error And I'm not really sure how to access the variable and modify inside the function, to complete the loop, and its not showing up on the chart. , I think, in v.4 it should be something like this:
code :
//@version=4
study("Adaptive Least Squares", overlay=true)
length = input(500)
smooth = input(1.5)
//
alpha = pow(tr / highest(tr, length), smooth)
m(a, prevVal) =>
    alpha * a + (1 - alpha) * nz(prevVal, a)
//
x = bar_index
y = close
x_ = 0.0
x_ := m(x, x_[1])

y_ = 0.0
y_ := m(y, y_[1])
//
dx = abs(x - x_)
dy = abs(y - y_)

mx = 0.0
mx := m(dx, mx[1])
my = 0.0
my := m(dy, my[1])
//

xx = 0.0
xx := m(x * x, xx[1])

xy = 0.0
xy := m(x * y, xy[1])

yy = 0.0
yy := m(y * y, yy[1])

a1 = pow(2 / alpha + 1, 2) * xy - (2 / alpha + 1) * x_ * (2 / alpha + 1) * y_
b1 = sqrt((pow(2 / alpha + 1, 2) * xx - pow((2 / alpha + 1) * x_, 2)) * (pow(2 / alpha + 1, 2) * yy - pow((2 / alpha + 1) * y_, 2)))
r = a1 / b1
//
a = r * (my / mx)
b = y_ - a * x_
reg = x * a + b
//
plot(reg, color=color.red, transp=0)

Interview problem : Buy and sell stocks to maximize profit with constraint of not buying once you sell


By : user5971950
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This can be solved in O(n lg n) with O(n) space using a BST.
The datastructure
code :
class BSTNode{
    BSTNode(val){
        this.val = val
        this.sum = sum
        this.left = this.right = null
        this.count = 1
    }

    insert(val){
        if(val < this.val)
            insert val into the left subtree
        else if(val > this.val)
            insert val into the right subtree

        this.sum += val
        this.count++
    }

    count_sum_nodes_upper_bound(val){
        if(val < this.val)
            return this.left.sum_nodes_lower_bound(val)
        else if(val == this.val)
            return this.left.sum, this.left.count
        else{
            right_sum, right_count = this.right.sum_nodes_lower_bound(val)

            return (this.sum - this.right.sum + right_sum),
                   (this.count - this.right.count + right_count)
        }
    }
}
maximize_profit(A){
    node = BSTNode(A[0])
    max = 0
    max_idx = -1

    for(i in 1..(A.length - 1)){
        sum, count = node.count_sum_nodes_upper_bound(A[i])
        gain = A[i] * count - sum 

        if(max < gain){
            max = gain
            max_idx = i
        }

        node.insert(A[i])
    }

    return max_idx
}
shadow
Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk