ramaParticipant
Senior
I there any code available to find the round number example for dax 11100 11200 etc
similarly for dow 24400 , 24500
code should give nearest round number the idea is to place 2 pips above round number 24400 buy and place stop loss 23990 etc
rama – You’ve been around long enough to know that your question is not a platform question but a strategy question. I’ve moved your topic to the correct forum. Please be more careful with future posts.
It took all of three seconds using the search box and typing in ’round numbers’ to find this:
Sweet Spots – round numbers
You should try the search box some time as it is quite useful! 🙂
ramaParticipant
Senior
Before I asked the question i searched and tried, can I ask you try to see the level for 24600 at 100 intervals in the thread you suggested
I’m not sure exactly what you are asking for. With MainLevels = 100 and SubLevels = 100 it draws lines at 100 intervals. I did spot a couple of little errors in the code. The FOR NEXT loop should start from 1 and not from zero and the addition or subtraction of 0.51 should be 0.5.
Here is a version of that code that simply returns the nearest round number above price and below price.
MainLevels = 100
DecAr = MainLevels*pointsize
myVarUp = close
myVarDn = close
if DecAr = 0 then
InvDec = 1
else
InvDec = 1/DecAr
endif
Floor = round(InvDec*myVarDn-0.5)/InvDec
Ceil = round(InvDec*myVarUp+0.5)/InvDec
return floor, ceil
To always round a number (using ROUND) to the lowest positive integer -0.5 needs to be subtracted, while always rounding to the highest positive integer +0.4 needs to be added.
I’m not sure that is correct Roberto. I tested it with this little code:
MainLevels = 100
DecAr = MainLevels*pointsize
myVarUp = close
if DecAr = 0 then
InvDec = 1
else
InvDec = 1/DecAr
endif
Ceil = round(InvDec*myVarUp+0.4)/InvDec
myround = round(InvDec*myVarUp+0.5)/InvDec
return ceil as "+0.4 ceil", myround as "+0.5 ceil", close as "close"
When using +0.4 sometimes it rounds it down rather than up.
because it rounds the first decimal position, to round the second one it should be 0.04 (or 0.05), 0.004 (or 0.005) for the third decimal position, etc…
Yes but in this indicator we always want to be a number above so if the current price is 1.0 then rounding with +0.4 will return 1.0 whereas we need it to be 2.0 To get 2.0 we have to add on 0.5
In a normal rounding situation you are correct as 1.0 should return 1 when rounded but not if we want to always find the next whole number above the current value.
PaulParticipant
Master