Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubleshooting - Step size doesn't work correctly #24

Closed
Avyyys opened this issue Dec 18, 2023 · 5 comments · Fixed by #26
Closed

Troubleshooting - Step size doesn't work correctly #24

Avyyys opened this issue Dec 18, 2023 · 5 comments · Fixed by #26

Comments

@Avyyys
Copy link

Avyyys commented Dec 18, 2023

I have had problems with step size. When I have more than one parameter, for some reason I can only get the step size of the first parameter to work, but not the step size of the second parameter. Even in the first parameter it only works if I add number like "2.0", but without ".0" it doesn't work at all. However, this solution no longer applies to the second parameter, I've tried everything, but I can't get it to work in another parameter at all. It always counts every number that is between the "start" and "end". I have also tried with another browser, but it had no effect.

@Avyyys
Copy link
Author

Avyyys commented Dec 19, 2023

image

As an example, even if the step size is 50, it goes through each number separately. I noticed that it works fine for small numbers like "0.1" but for integers like "2", "5" or "10" it doesn't work anymore.

@AtakanPehlivanoglu
Copy link
Contributor

Thanks for raising the issue @Avyyys ,

Could you please share the sample publicly available TradingView Strategy with the exact 'start' 'end' parameters that you are running? So that I can reproduce the issue on my side.

Once you share it here, I will share the details regarding the issue.

@Avyyys
Copy link
Author

Avyyys commented Dec 21, 2023

This is not the same code as in the picture, but with this strategy I have had the same problem. Often, Optipie also calculates quite a lot of extra values ​​for some reason and sometimes it has finished earlier than it should and also made an incomplete report.

In this code, I have had 2 parameters open, the values ​​of the first parameter are 5 - 30 - 2 and the values ​​of the second parameter are 50 - 250 - 10. Once I tried to add two more parameters, both of which had values ​​of 1 - 6 - 1, but then it went completely messed and kept calculating extra values.

//@Version=5
strategy(title="Double MA Strategy", shorttitle="DMA", overlay=true)

// Input for the lengths of two MAs
len1 = input.int(9, minval=1, title="Length1")
len2 = input.int(80, minval=1, title="Length2")

// Function to calculate different types of MAs
ma(source, length, type) =>
switch type
1 => ta.sma(source, length) // SMA
2 => ta.ema(source, length) // EMA
3 => ta.wma(source, length) // WMA
4 => ta.vwma(source, length) // VWMA
5 => ta.rma(source, length) // SMMA
6 => ta.hma(source, length) // HMA

// Input for the types of two MAs
type1 = input.int(title = "Type1", defval = 2, minval = 1, maxval = 6) // Default is EMA
type2 = input.int(title = "Type2", defval = 2, minval = 1, maxval = 6) // Default is EMA

// Calculation of two MAs
ma1 = ma(close, len1, type1)
ma2 = ma(close, len2, type2)

// Plotting two MAs
plot(ma1, title="MA1", color=color.blue)
plot(ma2, title="MA2", color=color.red)

// Conditions for entry and exit signals
buySignal = ta.crossover(ma1, ma2)
sellSignal = ta.crossunder(ma1, ma2)

// Using strategy.entry and strategy.close for signals
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)

// Closing positions
strategy.close("Close Long Position", when = sellSignal)
strategy.close("Close Short Position", when = buySignal)

@AtakanPehlivanoglu
Copy link
Contributor

Hey @Avyyys

I have just checked that out and problem is that your OptiPie Step Size should always match Pinescript Step Size for the given input 'X'.

I have set 'step size' values explicitly for the first 2 inputs like this:

// Input for the lengths of two MAs
len1 = input.int(9, minval=1, title="Length1", step = 2)
len2 = input.int(80, minval=1, title="Length2", step = 10)

To match the step sizes which you set for OptiPie.

You can find the sample optimization report for this strategy, for BTCUSD

report-1703197950317.csv

Please let me know if you have further questions.

@AtakanPehlivanoglu
Copy link
Contributor

Apparently that is a quite common issue that has been raised here multiple times so that to mitigate this problem I will add this solution to FAQs

@AtakanPehlivanoglu AtakanPehlivanoglu linked a pull request Dec 21, 2023 that will close this issue
@AtakanPehlivanoglu AtakanPehlivanoglu changed the title Step size doesn't work correctly Troubleshooting - Step size doesn't work correctly Dec 21, 2023
@AtakanPehlivanoglu AtakanPehlivanoglu pinned this issue Dec 21, 2023
@AtakanPehlivanoglu AtakanPehlivanoglu linked a pull request Dec 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants