Error due to invalid combination of Toast and OnSensor Changed - toast

In this the error being displayed is mentioned below. I have searched online for the right answer none is applicable so far. I am trying to toast a simple message upon detecting a sudden change in the accelerometer readings so as to detect a fall. I don't think there is any other mistake in the code, if there is you are most welcome to rectify it.
Error: cannot find symbol method maketext(MainActivity,String,int)
This is my Code:
#Override
public void onSensorChanged(SensorEvent event) {
if (started) {
double x = event.values[0];
double y = event.values[1];
double z = event.values[2];
long timestamp = System.currentTimeMillis();
Data data = new Data(timestamp, x, y, z);
sensorData.add(data);
}
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
double gacc=SensorManager.STANDARD_GRAVITY;
double a=event.values[0];
double b=event.values[1];
double c=event.values[2];
long mintime=System.currentTimeMillis();
boolean min = false;
boolean max = false;
int m = 0;
double xyz=Math.round(Math.sqrt(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2)));
if(xyz<=3.0){
min = true;
}
if(min==true){
m++;
if(xyz>=14){
max=true;
}
}
if(min && max==true){
Toast.maketext(MainActivity.this,"FALL DETECTED!",Toast.LENGTH_LONG).show();
m=0;
min=false;
max=false;
}
if (m>4) {
m=0;
min=false;
max=false;
}
}
}

You are calling maketext instead of makeText. Note that camelCase.
Replace with:
Toast.makeText(MainActivity.this,"FALL DETECTED!",Toast.LENGTH_LONG).show();
After you correct it, make sure that you are using the android.widget.Toast.

Related

How can I solve the duplicates of pending order issues?

My code below places sell pending orders when certain candle patterns are met on the H_1 chart. But duplicate pending orders are created when I change the chart timeframe and return to H_1. Also old orders that should have hit stop loss or take profit seem to still be open.
I need to have multiple pending orders, but the duplicates and orders that should have closed are not wanted. How can I solve this?
string prefix = "HG";
const int N_bars = 1;
int numBars = 1;
int numBarsArray[];
int tempVal = 0;
int NumOfDisplayBars = 300;
int count = 0;
extern double lotSize = 0.01;
int magicnumber = 1337;
void showRectangles()
{
for (int i=NumOfDisplayBars;i>=1;i--)
{
if(isBearishEngulfing(i))
{
drawBearRectangle(i + 1,iHigh(_Symbol,0,i + 1),iOpen(_Symbol,0,i + 1));
}
}
}
bool isBearishEngulfing(int current)
{
if( (iClose(_Symbol,0,current ) < iOpen( _Symbol,0,current ))
&& (iClose(_Symbol,0,current + 1) > iOpen( _Symbol,0,current + 1))
&& (iOpen( _Symbol,0,current ) > iClose(_Symbol,0,current + 1))
&& (iClose(_Symbol,0,current ) < iOpen( _Symbol,0,current + 1))
)
return true;
return false;
}
bool drawBearRectangle(int candleInt,const double top,const double bottom)
{
const datetime starts = iTime(_Symbol,0,candleInt);
const datetime ends = starts+PeriodSeconds()*N_bars;
const string name = prefix+"_"+(candleInt>0?"DEMAND":"SUPPLY")+"_"+TimeToString(starts);
if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0,0))
{
printf("%i %s: failed to create %s. error=%d",__LINE__,__FILE__,name,_LastError);
return false;
}
ObjectSetInteger(0,name,OBJPROP_TIME1, starts);
ObjectSetInteger(0,name,OBJPROP_TIME2, ends);
ObjectSetDouble( 0,name,OBJPROP_PRICE1,bottom);
ObjectSetDouble( 0,name,OBJPROP_PRICE2,top);
ObjectSetInteger(0,name,OBJPROP_COLOR, clrChocolate);
ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_DASHDOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH, 1);
ObjectSetInteger(0,name,OBJPROP_FILL, false);
if(_Period == 60){
double entryPrice=bottom-3*_Point;
double stopLoss=top;
double slDist=fabs(entryPrice-stopLoss);
double dTakeProfit=entryPrice-2*slDist;
int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, entryPrice,0,stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red);
}
return true;
}
void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}
void OnTick()
{
if(!isNewBar())
return; // not necessary but waste of time to check every second
showRectangles();
}
bool isNewBar()
{
static datetime lastbar;
datetime curbar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
if(lastbar != curbar)
{
lastbar = curbar;
return true;
}
return false;
}
Q : How can I solve the duplicates of pending order issues?... when I change the chart timeframe and return to H_1.
Well, this is rather a feature of the MQL4/5 code-execution ecosystem.
Solution:
Configure a preventive checkmark, setup in MT4-Terminal in Tools > Options > Expert Advisor-tab so as to become:
[x] Disable automated trading when the chart symbol or period has been changed

Rectangle on a specific timeframe doesn't extend on a lower timeframe

I have written the following code that draws a rectangle for bearish engulfing patterns for two inputed timeframes. I set the defaults to daily and 4 hours. When I am on the daily chart I expect that only the daily rectangles should appear for one candle and when I am on the 4 hour chart, the daily rectangle region should extend for 6 candles whiles the 4-hour rectangle shows for only one candle, and so on as I move to lower time frames.
The general idea is the rectangle should extend to cover the candles that sum it's period. But that is not happening, only one candle appears always. How can I solve this? Here's my code below:
int numBars = 1;
extern ENUM_TIMEFRAMES higherRegionPeriod = PERIOD_D1;
extern ENUM_TIMEFRAMES lowerRegionPeriod = PERIOD_H4;
extern color higherRegionColorSupply = clrRed;
extern color lowerRegionColorSupply = clrChocolate;
bool isBearishEngulfing(int current, ENUM_TIMEFRAMES cDuration) {
if((iClose(_Symbol,cDuration,current) < iOpen(_Symbol,cDuration,current)) &&
(iClose(_Symbol,cDuration,current + 1) > iOpen(_Symbol,cDuration,current + 1)) &&
(iOpen(_Symbol,cDuration,current) > iClose(_Symbol,cDuration,current + 1)) &&
(iClose(_Symbol,cDuration,current) < iOpen(_Symbol,cDuration,current + 1)))
return true;
return false;
}
void showRectangles() {
for (int i=300;i>=1;i--) {
if(isBearishEngulfing(i, lowerRegionPeriod)) {
drawBearRectangle(i + 1,iHigh(_Symbol,lowerRegionPeriod,i + 1),iOpen(_Symbol,lowerRegionPeriod,i + 1), lowerRegionPeriod, lowerRegionColorSupply);
}
if(isBearishEngulfing(i, higherRegionPeriod)) {
drawBearRectangle(i + 1,iHigh(_Symbol,higherRegionPeriod,i + 1),iOpen(_Symbol,higherRegionPeriod,i + 1), higherRegionPeriod, higherRegionColorSupply);
}
}
}
bool drawBearRectangle(int candleInt,const double top,const double bottom, ENUM_TIMEFRAMES cDuration, color rectColor)
{
const datetime starts=iTime(_Symbol,cDuration,candleInt);
const datetime ends=starts+PeriodSeconds()*NumBars;
const string name=prefix+"_"+(candleInt>0?"DEMAND":"SUPPLY")+"_"+TimeToString(starts);
if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0,0))
{
printf("%i %s: failed to create %s. error=%d",__LINE__,__FILE__,name,_LastError);
return false;
}
ObjectSetInteger(0,name,OBJPROP_TIME1,starts);
ObjectSetInteger(0,name,OBJPROP_TIME2,ends);
ObjectSetDouble(0,name,OBJPROP_PRICE1,bottom);
ObjectSetDouble(0,name,OBJPROP_PRICE2,top);
ObjectSetInteger(0,name,OBJPROP_COLOR, rectColor);
ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_DASHDOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetInteger(0,name,OBJPROP_FILL, false);
return true;
}
void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}
void OnTick()
{
if(!isNewBar(higherRegionPeriod))
return; //not necessary but waste of time to check every second
if(!isNewBar(lowerRegionPeriod))
return; //not necessary but waste of time to check every second
showRectangles();
}
bool isNewBar(ENUM_TIMEFRAMES cDuration)
{
static datetime lastbar;
datetime curbar = (datetime)SeriesInfoInteger(_Symbol,cDuration,SERIES_LASTBAR_DATE);
if(lastbar != curbar)
{
lastbar = curbar;
return true;
}
return false;

Rectangle is not drawing the bullish engulfing pattern

I wrote the following code to look through the last 100 candlesticks and draw a rectangle around a bullish engulfing candlestick patterns. I hope extend it for bearish engulfing pattern too. I don't know why, but the rectangles don't draw. Please take a look at the code below
bool isBullishEngulfing(int current) {
if((iClose(_Symbol,0,current) > iOpen(_Symbol,0,current)) && (iClose(_Symbol,0,current + 1) < iOpen(_Symbol,0,current + 1)) &&
(iOpen(_Symbol,0,current) < iClose(_Symbol,0,current + 1)) && (iClose(_Symbol,0,current) > iOpen(_Symbol,0,current + 1)))
return true;
return false;
}
void showRectangles() {
for (int i=100;i<=1;i--) {
if(isBullishEngulfing(i)) {
drawBullRectangle(i,iHigh(_Symbol,0,i),iLow(_Symbol,0,i));
}
}
}
bool drawBullRectangle(int candleInt,const double top,const double bottom)
{
const datetime starts=iTime(_Symbol,0,candleInt);
const datetime ends=starts+PeriodSeconds()*Numbars; //Numbars shows how long the rectangle should draw
const string name=prefix+"_"+(candleInt>0?"DEMAND":"SUPPLY")+"_"+TimeToString(starts);
if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0,0))
{
printf("%i %s: failed to create %s. error=%d",__LINE__,__FILE__,name,_LastError);
return false;
}
ObjectSetInteger(0,name,OBJPROP_TIME1,starts);
ObjectSetInteger(0,name,OBJPROP_TIME2,ends);
ObjectSetDouble(0,name,OBJPROP_PRICE1,top);
ObjectSetDouble(0,name,OBJPROP_PRICE2,bottom);
ObjectSetInteger(0,name,OBJPROP_COLOR, clrAqua);
ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
ObjectSetInteger(0,name,OBJPROP_FILL, true);
return true;
}
void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}
void OnTick()
{
if(!isNewBar())
return; //not necessary but waste of time to check every second
showRectangles();
}
bool isNewBar()
{
static datetime lastbar;
datetime curbar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
if(lastbar != curbar)
{
lastbar = curbar;
return true;
}
return false;
}
I would appreciate help to resolve this.
The error is mainly in the loop, it should be for (int i=100;i>=1;i--)
The other "possible" error is in the logic of theisBullishEngulfing() function.
Usually, the Close of the previous bar is equal to the Open of the current bar, so the following condition doesn't get fulfilled(most of the time)
iOpen(_Symbol,0,current) < iClose(_Symbol,0,current + 1)
(So, I suggest to remove this line, but this is just a suggestion, note there are occasions that your condition get fulfilled as well)

How to get residence time in a geofence?

Simple question need simple answer.
How can I track the residence time in a specific geofence.
When I add geofence with Trigger on Enter, will I automatic receive a trigger when I leave that geofence. Basically I need to remember the time when I enter a geofence and when I leave that geofence so I can subtract leave-enter time and have my duration time. But I believe its not that easy to do that. So any other idea or advise how to solve that problem efficient ?
Thanks
I found one solution for this problem. In order to determine the dwell time in a geofence i have to get the time when user trigger a geofence and then i use to calculate if user leave the geofence with this mathematical method
Handler handler = new Handler();
getCurrentLatLng();
final Runnable myRunnable = new Runnable() {
public void run() {
GeofenceFinished myFinishedGeofence = db.getGeofenceFinishedByID("Finished" + id);
if (!isUserInRegion(latitude, longitude, myLatLng.latitude, myLatLng.longitude, rd)
|| myFinishedGeofence == null) {
String time = convertTime(endTime - startTime);
// get the finishedGeofence and set the duration of stay time
if (myFinishedGeofence != null)
setDurationOfStay("Finished" + id, time, getCurrentTime(System.currentTimeMillis()));
Toast.makeText(mContext, "Finish to determine duration of stay of " + myFinishedGeofence.getAddress(), Toast.LENGTH_SHORT).show();
handler.removeCallbacks(this);
} else {
getCurrentLatLng();
endTime += Constants.DELAY;
handler.postDelayed(this, Constants.DELAY);
}
}
private void setDurationOfStay(String geofenceid, String time, String endTime) {
if (db == null) db = GeofenceDatabaseHelper.getInstance(mContext);
if (!db.setDurationOfFinishedGeofence(geofenceid, time, endTime)) {
Log.i("setDurationOfStay", "fail");
}
}
};
handler.postDelayed(myRunnable, Constants.DELAY);
private boolean isUserInRegion(double firstLat, double firstLog, double curLat, double curLog, float radius) {
double distance = calculateDistance(firstLat, firstLog, curLat, curLog);
return distance <= radius;
}
To calculate the distance of user and center of geofence, i need to convert the current latitude and longitude in meter, so i can calculate that with the parametic equation for circle
So I use this approach from github
// https://github.com/mgavaghan/geodesy
private double calculateDistance(double firstLat, double firstLog, double curLat, double curLog) {
GeodeticCalculator geoCalc = new GeodeticCalculator();
Ellipsoid reference = Ellipsoid.WGS84;
GlobalPosition pointA = new GlobalPosition(firstLat, firstLog, 0.0); // Point A
GlobalPosition userPos = new GlobalPosition(curLat, curLog, 0.0); // Point B
// Distance between Point A and Point B
double distance = geoCalc.calculateGeodeticCurve(reference, userPos, pointA).getEllipsoidalDistance();
return distance;
}
hope it helps someone :D

How to fill series data in candle chart in xamarin (TeeChart and MonoTouch)

I am using a tee chart library in xamarin (Android). i am facing a problem to daynamic binding data in "Candle Chart"
The Sample Code Like this!
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.CandleChart);
//InitializeComponent();
chart = new Steema.TeeChart.TChart(this.ApplicationContext);
chart.Zoom.Style = Steema.TeeChart.ZoomStyles.InChart;
Steema.TeeChart.Themes.BlackIsBackTheme myTheme = new Steema.TeeChart.Themes.BlackIsBackTheme(chart.Chart);
myTheme.Apply();
Type tmp = (Type)Steema.TeeChart.Utils.SeriesTypesOf[12];
Steema.TeeChart.Styles.Series series;
series = chart.Series.Add(tmp);
series.FillSampleValues(); /* Here i want to fill series with my data listed bellow */
chart.Aspect.View3D = Needs3D(chart[0]);
chart.Panel.Transparent = true;
SetContentView(chart);
}
now i want add series data manually
like :
currentItem.Data.Close
currentItem.Data.Open
currentItem.Data.High
currentItem.Data.Low
currentItem.Time
etc.. so, plz help me to achieve this ..
thanks, in advance
==================================================================================
My Code Like as Bellow
private void LoadChart(GraphOutput resGraph)
{
DataSet_Obj.Tables.Add("CandleTable");
DataSet_Obj.Tables["CandleTable"].Columns.Add(new DataColumn("Date", System.Type.GetType("System.DateTime")));
DataSet_Obj.Tables["CandleTable"].Columns.Add(new DataColumn("Open", System.Type.GetType("System.Double")));
DataSet_Obj.Tables["CandleTable"].Columns.Add(new DataColumn("Close", System.Type.GetType("System.Double")));
DataSet_Obj.Tables["CandleTable"].Columns.Add(new DataColumn("High", System.Type.GetType("System.Double")));
DataSet_Obj.Tables["CandleTable"].Columns.Add(new DataColumn("Low", System.Type.GetType("System.Double")));
for (int i = 0; i < resGraph.graphSymbol[0].CandleSticks.Length; i++)
{
DataRow_Obj = DataSet_Obj.Tables["CandleTable"].NewRow();
DataRow_Obj["Date"] = resGraph.graphSymbol[0].CandleSticks[i].CandleTime; //DateTime
DataRow_Obj["Low"] = resGraph.graphSymbol[0].CandleSticks[i].CandleData.Low; //Float
DataRow_Obj["Close"] = resGraph.graphSymbol[0].CandleSticks[i].CandleData.Close; //Float
DataRow_Obj["Open"] = resGraph.graphSymbol[0].CandleSticks[i].CandleData.Open; //Float
DataRow_Obj["High"] = resGraph.graphSymbol[0].CandleSticks[i].CandleData.High; //Float
DataSet_Obj.Tables["CandleTable"].Rows.Add(DataRow_Obj);
DataRow_Obj = null;
}
Tag_Serie_Candle = new Steema.TeeChart.Styles.Candle ();
chart.Series.Add(Tag_Serie_Candle);
chart.Aspect.View3D = Needs3D(chart[0]);
chart.Panel.Transparent = true;
try
{
Tag_Serie_Candle.DataSource = DataSet_Obj.Tables["CandleTable"]; /* here I got Error Like: "Cannot bind to non-supported datasource: CandleTable" */
Tag_Serie_Candle.OpenValues.DataMember = DataSet_Obj.Tables["CandleTable"].Columns["Open"].ToString();
Tag_Serie_Candle.CloseValues.DataMember = DataSet_Obj.Tables["CandleTable"].Columns["Close"].ToString();
Tag_Serie_Candle.DateValues.DataMember = DataSet_Obj.Tables["CandleTable"].Columns["Date"].ToString();
Tag_Serie_Candle.DateValues.DateTime = true;
Tag_Serie_Candle.HighValues.DataMember = DataSet_Obj.Tables["CandleTable"].Columns["High"].ToString();
Tag_Serie_Candle.LowValues.DataMember = DataSet_Obj.Tables["CandleTable"].Columns["Low"].ToString();
Tag_Serie_Candle.LabelMember = "Candle Chart";
Tag_Serie_Candle.CheckDataSource();
chartpie.AddView(chart, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
}
catch (Exception exe)
{
exe.Message.ToString();
}
}
You should do something as in the examples here:
http://www.teechart.net/support/viewtopic.php?f=4&t=2978&p=10547#p10547
http://www.teechart.net/support/viewtopic.php?f=4&t=3291&p=11691#p11691
http://www.teechart.net/support/viewtopic.php?f=4&t=2741&p=11681#p11681
I have found that, at the present moment, this is not working. I added the defect (ID566) list to be fixed as soon as possible (now fixed, see update at the bottom of the reply). If you register at Steema Software's Bugzilla system, you will be able to be in the CC List and be notified about status updates. In the meantime you can manually read values from the DataSet using this code:
Tag_Serie_Candle.DateValues.DateTime = true;
for (int i = 0; i < DataSet_Obj.Tables["CandleTable"].Rows.Count; i++)
{
DataRow row = DataSet_Obj.Tables["CandleTable"].Rows[i];
DateTime dt = Convert.ToDateTime(row["Date"]);
Double open = Convert.ToDouble(row["Open"]);
Double high = Convert.ToDouble(row["High"]);
Double low = Convert.ToDouble(row["Low"]);
Double close = Convert.ToDouble(row["Close"]);
Tag_Serie_Candle.Add(dt, open, high, low, close);
}
UPDATE: As of 11th February 2014, the defect has been fixed. Anyone interested in testing the solution please let me know.

Resources