AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Round-Off to nearest 0.05 in a ClassNN Edit
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Vik
Guest





PostPosted: Tue Mar 11, 2008 7:51 pm    Post subject: Round-Off to nearest 0.05 in a ClassNN Edit Reply with quote

I use an on-line trading software which when the Numpad Add key is pressed, opens up a window that allows me to input an order to buy a stock and when the Numpad Sub key is pressed it opens up a similar but different window that allows me to input an order to sell a stock. The WinTitle for these Windows is “Buy Orders” and “Sell Orders” respectively. These windows that open up either for buying or selling have small separate input boxes wherein a user can enter the desired quantity and price for the stock that they would like to either buy or sell. Finally to submit the intended transaction to the trading system the user has to press either the Enter or Numpad Enter key. WinSpy reveals that the Input Box for the Quantity to be entered in both these Windows (Buy & Sell) is ClassNN Edit2 and the Input Box for the Price to be entered is ClassNN Edit3.

This software in the price input box (ClassNN Edit3) only allows a tick of 0.05 to be entered – that is, for example – a price of 125.00, 125.05 or 125.10 is allowed whereas a price of 125.01, 125.02, 125.03, 125.04, 125.06, 125.07, 125.08 and 125.09 will not be allowed.

My query is – Is there a way whereby any input made in this ClassNN Edit3 can be automatically rounded off to the nearest 0.05 equivalent? This in other words means – If the user were to in error type in 125.01, 125.02, 125.03 or 125.04 it will automatically be converted / rounded-off to either a lower (125.00) or higher (125.05) tick when either the Enter or Numpad Enter key is pressed for submitting the transaction to the trading system and similarly if the user were to type in 125.06, 125.07, 125.08 or 125.09 it will automatically be converted / rounded-off to either a lower (125.05) or higher (125.10) tick when either the Enter or Numpad Enter key is pressed for submitting the transaction to the trading system.

Even a conversion / rounding-off to only a higher or only a lower 0.05 level for all entries would be acceptable.

As my coding proficiency is quite weak, I cannot think of a solution for this but there are two things that do cross my mind. Firstly – Perhaps a code can be devised that runs on a continuous timer system wherein it monitors any entry in the ClassNN Edit3 input box and automatically converts / rounds-off that entry on the fly to the nearest 0.05, if it isn’t so, though this does not seem like a practical or workable solution. The other thought I had was perhaps a Hotkey can be coded / assigned to both the Enter and Numpad Enter keys that first round-offs the figure in the ClassNN Edit3 input box if it isn’t in a multiple of 0.05 and then submits the transaction to the trading system as the user has to compulsorily first press either the Enter or Numpad Enter key to submit the transaction to the trading system, which is when the Hotkey(s) would check if the figure in ClassNN Edit3 is equal to the 0.05 tick. If the user has entered a figure that is with the correct 0.05 tick – like 125.00, 125.05 or 125.10 then it will do nothing and let the order pass through as intended. The directive for the Hotkey assigned to the Enter and Numpad Enter keys can be given to function only under the specific windows for which the WinTitles are available.

Would obviously be acceptable to any other method that can make this work and would be grateful for a code for the same.
Back to top
Lurker1457



Joined: 10 Mar 2008
Posts: 11

PostPosted: Tue Mar 11, 2008 8:22 pm    Post subject: Reply with quote

Code:
#IfWinActive YOURWINDOWTITLE
$Enter::
$NumpadEnter::
ControlGetText, numb, Edit3, A
SetFormat, Float, 0.0
numb := (numb*20)
SetFormat, Float, 0.2
numb /= 20.0
If (numb)
   ControlSetText, Edit3, %numb%, A
sleep 10
Send {enter}
return
#IfWinActive
(untested) Maybe something like this?
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Tue Mar 11, 2008 10:34 pm    Post subject: Reply with quote

You can write Lurker1457's script in a little shorter form:
Code:
SetFormat Float, 0.2
#IfWinActive YOURWINDOWTITLE
$Enter::
$NumpadEnter::
   ControlGetText numb, Edit3, A
   ControlSetText Edit3, % Round(numb*20)/20, A
   Send {Enter}
Return
#IfWinActive
Back to top
View user's profile Send private message
Vik
Guest





PostPosted: Wed Mar 12, 2008 3:33 pm    Post subject: Reply with quote

Thank you Lurker1457 and Laszlo – the given codes work like a charm… (I am using the code given by Laszlo at the moment)
I just had a related question about implementing this code and hope it can be answered.

I preceded the code offered with SetTitleMatchMode, 2 and gave the directive #IfWinActive, Orders so that the code would work in both the Buy and Sell Orders Windows. This option of SetTitleMatchMode also allows the code to function in another Window titled “Outstanding Orders” as “Orders” is a part of the WinTitle in this Window also. That is fine and what I want.

My question is – Ideally I would like to use the SetTitleMatchMode, 3 option as I would like to specify the exact Windows where this code should work as there are a few other Windows having the word “Orders” within their WinTitle where I do not want this code to work. If I precede the code with SetTitleMatchMode, 3 followed by the names of the three WinTitles of the three specific Windows where I would want this code to work – it just does not do it. I believe one way to solve this would be to create a Group of the WinTitles where I want this code to work and then give the directive #IfWinActive followed by the Group. My problem is I do not know how to Group Add and make the code work.

Would be grateful for a code for the same.
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Wed Mar 12, 2008 3:46 pm    Post subject: Reply with quote

Code:
GroupAdd OrdersGroup, Buy Orders
GroupAdd OrdersGroup, Sell Orders
GroupAdd OrdersGroup, Outstanding Orders

#IfWinActive ahk_group OrdersGroup
...
Back to top
View user's profile Send private message
Vik
Guest





PostPosted: Wed Mar 12, 2008 3:55 pm    Post subject: Reply with quote

Thank you, Laszlo for your post. I will try this and hope it works. In case of problems I know where to go Smile
Back to top
Vik
Guest





PostPosted: Fri Mar 14, 2008 5:13 pm    Post subject: Reply with quote

The code for the GroupAdd worked as desired – Thank You Laszlo for that but I now have a problem with the original code used for rounding off. Basically what the code given above does is rounds off the figure in the ClassNN Edit3 (which is what I had requested for) but also if there is no value or if there is anything else but a numerical value it changes it to 0.00. The problem I face is that there are these few times when I must type in the actual word “BEST” in the ClassNN Edit3 instead of a numerical amount for the transaction to go through. The only way for the transaction to be entered in the system is via the NumpadEnter key. This is when the Hotkey assigned to the NumpadEnter key takes over and changes the word BEST to 0.00 and does not allow the transaction to proceed.

Therefore, I wanted to know whether a code can be devised whereby if the word BEST were to appear in the ClassNN Edit3 then the key would not do anything; else it would proceed as usual by rounding off the amount in the ClassNN Edit3. The word BEST is the only other word / thing other than numerical values that the software will accept in the ClassNN Edit3, which is to say that BEST is the only exception.
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Fri Mar 14, 2008 6:45 pm    Post subject: Reply with quote

Insert one of the following lines above the ControlSetText line:
Code:
If numb is number
or
Code:
If numb != BEST
Back to top
View user's profile Send private message
Lurker1457



Joined: 10 Mar 2008
Posts: 11

PostPosted: Fri Mar 14, 2008 6:47 pm    Post subject: Reply with quote

I'm pretty sure my script would deliver in that respect, since it uses controlsettext after the conditional If (numb). It should discriminate non-numerical values instead of sending them to the edit box.

Er... Laszlo's code is shorter... and therefore more 1337 Razz
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Fri Mar 14, 2008 6:54 pm    Post subject: Reply with quote

Lurker1457 wrote:
Laszlo's code...
It is still your code, only tweaked a little, and the original does leave a non-numerical input unchanged.
Back to top
View user's profile Send private message
Vik
Guest





PostPosted: Fri Mar 14, 2008 7:54 pm    Post subject: Reply with quote

Thank you Laszlo and Lurker1457. Just to be double sure – Is this code correct –

Code:
#IfWinActive, YOURWINDOWTITLE
$Enter::
$NumpadEnter::
SetFormat Float, 0.2
   ControlGetText, Numb, Edit3, A
   If Numb is Number
   ControlSetText, Edit3, % Round(Numb*20)/20, A
   Send {Enter}
Return
#IfWinActive

I think I would prefer using If Numb is Number over If Numb != BEST, simply because today the software uses BEST, which could be changed at a later date whereas I feel using an option that categorically states numbers is a safer bet.

Appreciate the help…

Lurker1457 wrote:

Er... Laszlo's code is shorter... and therefore more 1337 Razz


Confused - What does that mean? Exclamation
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Fri Mar 14, 2008 8:45 pm    Post subject: Reply with quote

Wikipedia: Leet (~elite)

Leet (written as 31337, 1337, and l33t), or Leetspeak, is a written argot used primarily on the Internet, but becoming increasingly common in many online video games, which uses various combinations of alphanumerics to replace proper letters. The term itself is a degenerate form of the word "elite", and the language it describes resembles a highly specialized form of electronic shorthand. Initially, the word leet was used as an adjective, to primarily describe the behavior or accomplishments of others in the community. In that usage, Leet generally carries the same meaning when referring to either the game prowess or, in original usage, hacking expertise of another person. From adjective form its use then expanded to include use as an expletive in reaction to a demonstration of the former qualities. With the mass proliferation of Internet use in the 1990s into the 21st century, Leet has since become a part of Internet culture and slang. Leet may also be considered a substitution cipher, albeit with much variation from user to user.
Back to top
View user's profile Send private message
Vik
Guest





PostPosted: Wed Apr 02, 2008 4:14 pm    Post subject: Reply with quote

I have another query and am posting it here rather than starting a new Topic as it is somewhat related to the above.

In my above post the problem of rounding-off to the nearest 0.05 in ClassNN Edit3 was effectively solved. Now, I would like to know if it’s possible to round-off in ClassNN Edit2 as per the data contained in ClassNN Edit1. Before I continue, let me give an idea of what I would exactly need. As mentioned earlier, I would like to use this in an on-line trading software. When I press the NumpadAdd key to buy a stock (or the NumpadSub to sell) there is a pre-defined data in ClassNN Edit1 along with pre-defined data in ClassNN Edit2. The user can enter the price in ClassNN Edit3.

For Example –

ClassNN Edit1 – ABC
ClassNN Edit2 – 75
ClassNN Edit3 – Price

ClassNN Edit1 – DEF
ClassNN Edit2 – 209
ClassNN Edit3 – Price

ClassNN Edit1 – GHI
ClassNN Edit2 – 144
ClassNN Edit3 – Price

The above in other words means that when the data contained in ClassNN Edit1 is ABC, the system will accept the transaction only if the quantity in ClassNN Edit2 is 75 and its multiples thereof. Ditto for DEF, multiples of 209 and GHI, multiples of 144 etc.

My query is – Can a Hotkey be assigned to the Enter and NumpadEnter key(s) whereby it will – obviously continue to round-off the price in ClassNN Edit3 (as before) and depending on the data in ClassNN Edit1, it rounds off the data in ClassNN Edit2 to the nearest multiple thereof.

So say,

- When the data in ClassNN Edit1 is ABC and if an user enters 156 in ClassNN Edit2, it will automatically round it off to 150 as that is the nearest multiple of 75.

- When the data in ClassNN Edit1 is DEF and if an user enters 200 in ClassNN Edit2, it will automatically round it off to 209 as that is the nearest multiple of the minimum defined quantity (which I can define in my code).

- When the data in ClassNN Edit1 is GHI and if an user enters 425 in ClassNN Edit2, it will automatically round it off to 432 as that is the nearest multiple of 144.

I know that this would be a slightly lengthy code as each option in ClassNN Edit1 along with its corresponding data in ClassNN Edit2 would need to be defined but I am prepared to do it if it can work. I just need a starting code that can do the same.

I would like to know if this is possible and would be grateful for a code.
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Wed Apr 02, 2008 6:51 pm    Post subject: Reply with quote

You can do the I/O, here is the math
Code:
N = ,ABC,DE,ABCD,    ; list of names with leading and trailing comma
Q =  75,209,144      ; list of the corresponding numbers
StringSplit Q, Q, `,

S = ABC              ; selected name
T = 222              ; selected amount

M := SubStr(N,1,InStr(N, "," . S . ","))
StringReplace M, M, `,, `,, UseErrorLevel
Q := Q%ErrorLevel%   ; number corresponding to the active name
T := round(T/Q)*Q    ; corrected number

MsgBox %T%
Back to top
View user's profile Send private message
Vik
Guest





PostPosted: Wed Apr 02, 2008 7:34 pm    Post subject: Reply with quote

Thank You for your code Laszlo but unfortunately I cannot make head or tail of it Confused . Nothing whatsoever… Confused Embarassed. This is way beyond what I can put into perspective as I have never worked with something like this. Sure I will do the I/O – it’s just that with this I wouldn’t even know how to Rolling Eyes . In the earlier code, I could at least understand what was going on with ControlGetText and ControlSetText though I still don’t know how Round(Numb*20)/20 rounds-off the number in ClassNN Edit3.

Why is there a section of the code with a list of names with leading and trailing commas (N=) and then later S= and T= and then why is there a Message Box when it has to put and round-off the data in ClassNN Edit2. Plus how would I assign a Hotkey to the Enter and NumpadEnter keys that will round-off to 0.05 in ClassNN Edit3 and round-off in ClassNN Edit2 as per data in ClassNN Edit1 to the nearest multiple. Oh! I am so confused and have no clue how to work this out.

Help please…
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group