• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Kotlin project

I have this app I'm bulding that the interfere I have to take user inputs from first edittext and second one and display answers on the 3 text views one lebeled no of pips to hold, expected loss and third one for displaying lot size I'm having trouble writing the code in kotlin to do so I'm a beginner
For for lotsize = (equity*((risk/100)*500)/100 000
Formula for no of pips to hold = equity*(%risk/100)/(lotsize*10).
Formula for expected loss = pips*(lotsize*10)
 

Attachments

  • Screenshot_20181017-023911.png
    Screenshot_20181017-023911.png
    74.5 KB · Views: 91
What part of this are you having problems with? Please show the code you've written so far.
 
Slightly confused here. You've shown a screenshot, so there's some code behind this. Let's have a look at that code.
Your question can't really be answered until the context is understood i.e. how do we get the values of 'risk' and 'equity'. Judging by your screenshot, there are a couple of EditText components holding those values. So until we see the code behind the screenshot, your question can't be answered.
 
<?xml version='1.0' encoding='utf-8'?>
<android.support.constraint.ConstraintLayout
xmlns:android='http://schemas.android.com/apk/res/android'
xmlns:tools='http://schemas.android.com/tools'
xmlns:app='http://schemas.android.com/apk/res-auto'
android:layout_width='match_parent'
android:layout_height='match_parent'
tools:context='.CalActivity'>

<TextView
android:text='ENTER EQUITY:$'
android:layout_width='138dp'
android:layout_height='25dp'
android:id='@+id/textView'
android:layout_marginTop='36dp'
app:layout_constraintTop_toTopOf='parent' app:layout_constraintEnd_toStartOf='@+id/edEquity'
android:layout_marginEnd='8dp' android:layout_marginRight='8dp'
app:layout_constraintStart_toStartOf='parent' android:layout_marginLeft='8dp'
android:layout_marginStart='8dp'
app:layout_constraintHorizontal_bias='0.0' app:layout_constraintHorizontal_chainStyle='spread_inside'/>
<TextView
android:text='ENTER % TO RISK'
android:layout_width='138dp'
android:layout_height='26dp'
android:id='@+id/textView2' app:layout_constraintStart_toStartOf='parent' android:layout_marginLeft='8dp'
android:layout_marginStart='8dp' app:layout_constraintEnd_toStartOf='@+id/edRisk'
android:layout_marginEnd='8dp' android:layout_marginRight='8dp'
app:layout_constraintHorizontal_bias='0.0'
android:layout_marginTop='40dp' app:layout_constraintTop_toBottomOf='@+id/textView'/>
<TextView
android:text='NO OF PIPS TO HOLD'
android:layout_width='140dp'
android:layout_height='26dp'
android:id='@+id/textView3'
app:layout_constraintStart_toStartOf='parent'
android:layout_marginLeft='8dp' android:layout_marginStart='8dp'
android:layout_marginTop='52dp'
app:layout_constraintTop_toBottomOf='@+id/textView2'/>
<TextView
android:text='EXPECTED LOSS:$'
android:layout_width='137dp'
android:layout_height='24dp'
android:id='@+id/textView4' app:layout_constraintStart_toStartOf='parent' android:layout_marginLeft='8dp'
android:layout_marginStart='8dp'
android:layout_marginTop='48dp' app:layout_constraintTop_toBottomOf='@+id/textView3'
/>
<View
android:id='@+id/divider'
android:layout_width='368dp'
android:layout_height='14dp'
android:background='?android:attr/listDivider'
tools:layout_editor_absoluteY='302dp' app:layout_constraintStart_toStartOf='parent'
android:layout_marginLeft='8dp' android:layout_marginStart='8dp' app:layout_constraintEnd_toEndOf='parent'
android:layout_marginEnd='8dp' android:layout_marginRight='8dp'/>
<Button
android:text='COMPUTE LOT SIZE'
android:layout_width='228dp'
android:layout_height='wrap_content'
android:id='@+id/btnCompute' app:layout_constraintEnd_toEndOf='parent' android:layout_marginEnd='8dp'
android:layout_marginRight='8dp' app:layout_constraintStart_toStartOf='parent'
android:layout_marginLeft='8dp' android:layout_marginStart='8dp'
android:layout_marginBottom='20dp' app:layout_constraintBottom_toTopOf='@+id/txtSize'
/>
<Button
android:text='BROKER'
android:layout_width='wrap_content'
android:layout_height='wrap_content'
android:id='@+id/btnBroker'
app:layout_constraintEnd_toEndOf='parent' android:layout_marginEnd='8dp'
android:layout_marginRight='8dp' android:layout_marginBottom='16dp'
app:layout_constraintBottom_toBottomOf='parent'/>
<EditText
android:layout_width='183dp'
android:layout_height='wrap_content'
android:inputType='number'
android:ems='10'
android:id='@+id/edEquity' android:layout_marginTop='28dp'
app:layout_constraintTop_toTopOf='parent'
app:layout_constraintEnd_toEndOf='parent'
app:layout_
 
package com.gatsheni.fx_risk_calculator

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_cal.*

class CalActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cal)

btnBroker.setOnClickListener {
val intent = Intent(this, BrokerActivity::class.java)
startActivity(intent)


val lev = 500
val compute = findViewById<Button>(R.id.btnCompute)
val equity = findViewById<EditText>(R.id.edEquity)
val risk = findViewById<EditText>(R.id.edRisk)
val pip = findViewById<TextView>(R.id.txtPip)
val lotsize = equity*((risk/100)*lev)/100000
val loss = pip*(lotsize*10)
val hold = (risk/100)/(lotsize*10)


}


}
 
Back
Top Bottom