# Adding a basic math calculation within UiPath StudioX

Hi all,

I’ve been working on a fairly simple bot to automate a crypto arbitrage system I’m using which is working well so far. I would like to improve it by doing a simple math calculation prior to initiating a trade and ensuring that only the higher value trades are going through.

Basically I want to be able to collect data from the page which would be the Market price and the Transaction price and then perform this calculation:

Market price - Transaction price / Transaction price = xyz

Then I would like the resulting calculation to proceed to an ‘If’ 'or ‘Else If’ flow:

If xyz is greater than 0.015 then proceed to trade if less than 0.015 then reinitiate another trade.

I imagine the only way to perform this calculation would be to get the text from the page and store that data as variables but where I’m getting stuck is how to perform the calculation within the expression editor of the ‘Else If’ ‘If’ activities. Or if there are any other Activities i can add to Studio X to peform basic math calculations that would be great.

Any help would be much appreciated and would be great to discuss with anyone further.

Thank you
Kris

Hello @kris.bowman ,

Here you are getting 2 values Transaction_price and Market_price but it will be like a string. So you have to convert it.

In the if condition:

(CInt(Market_price)-CInt(Transaction_price))/CInt(Transaction_price)>0.015
Then do another action for initiate trade.
else “another action”

Try this and let me know whether this works or not

Hi @Rahul_Unnikrishnan thank you so much for getting back to me, I really appreciate it. I’ve come across another issue now where when I run the Get Text function to gather the Transaction and market price. Whenever a new trade happens that price changes and the Get text activity is always looking for the same value, not sure how I get around that so that it looks for the text in that field as opposed to a specific set of text.

@kris.bowman Plz go to the selector. There you will able to find some attribute which is holding the amount. Replace that with *

Then it will take any valuescoming in that place. Else you can share the selector here… Let me have a look.

HI @Rahul_Unnikrishnan When i use the ‘Get Text’ activity there is no option to change the selector. I’ve tried to use the "Get OCR Text’ activity where i can edit the selector but that is coming up with the following error when I’m trying to scrape the Transaction price.

Any idea on another way to do this or why i might be getting that error?

Hello @kris.bowman

Which ocr are you using?? If it is Uipath ocr then get the pin key from orchestrator.

Else use tessaract or other ocr

You can delete the default ocr and drag and drop any of the other ocr

Hi @Rahul_Unnikrishnan thanks for getting back to me and i appreciate your support so far! I have tried with tessaract OCR and the text recognition that comes back isn’t correct. I’ve even validated the selector with UIexplorer and it’s highlighting the correct area but the text comes back wrong. Any chance you’d be free to teams or skype chat and i can share my screen with you to show what the issue is?