Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

pine script - Why this strategy does not work on other pairs?

This code cannot be compiled or used in other pairs, it only works in BTC!!!

What should I do if I want to use it in other pairs?

( when I use this strategy on other pairs, I see a alarm notification in front of the indicator. If you hover your mouse pointer over this warning sign, you will notice a footnote that warns you that this indicator is not working properly and the information is not processed properly. (please look at to the second picture) ibb.co/zmCCDrm )

And how do I write a warning for that?

//@version=2
//                     simple cross of daily candle close
//
strategy("DailyCandleCross", shorttitle="DCC", overlay=true, calc_on_order_fills= true, calc_on_every_tick=true, default_qty_type=strategy.percent_of_equity, default_qty_value=75, pyramiding=0)
A=security(tickerid, 'D', close)
B=security(tickerid, 'D', close[1])
C=A>B
if(C)
    strategy.entry("Long", strategy.long)
if(not C)
    strategy.entry("Short", strategy.short)

Kind regards.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Updated the code to fix the cross calculation:
This code will print a "Long" label whenever the new daily candle close, cross over the previous daily candle close (That means it will generate a lot of labels!):

//@version=4
//                     simple cross of daily candle close
//
study("DailyCandleCross", shorttitle="DCC", overlay=true)
A=security(syminfo.tickerid, 'D', close)
longCondition = crossover(A , A[1])
shortCondition = crossunder(A , A[1])
if(longCondition)
    label.new(bar_index, low , "Long" ,style = label.style_label_up , color= color.green , textcolor= color.white)
if(shortCondition)
    label.new(bar_index, high , "Short" , color = color.red , textcolor= color.white)

Use the "crossover" function to check if a series crossed the other series.
To be honest I don't know if I understood your goal clearly or not and I don't know what are you trying to achieve with this either.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...