How to put reminder in Blackberry calendar - blackberry

I need to put several reminders in the BB calendar.
The idea is several hours, or days before a promo expires, the alarm will remind it for you.
Here's my code so far:
long ONE_HOUR = 3600;
long ONE_DAY = 24 * 3600;
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
BlackBerryEvent bbEvent = (BlackBerryEvent) eventList.createEvent();
FavoritePromo promo;
if (eventList.isSupportedField(BlackBerryEvent.ALARM)){
for (int x = 0; x < promos.size(); x++){
promo = (FavoritePromo) promos.elementAt(x);
time = (StringUtil.strToDate(promo.getExpireDate())).getTime() - value;
bbEvent.addString(BlackBerryEvent.SUMMARY, BlackBerryEvent.ATTR_NONE, promo.getTitle());
bbEvent.addDate(BlackBerryEvent.ALARM,0,time);
bbEvent.commit();
}
}
}
catch (PIMException e){
}
Every time i run it, an "IllegalArgumentException" is always thrown. I'm not really sure what goes wrong here...

BlackBerryEvent ev = (BlackBerryEvent) _event;
ev.addInt(BlackBerryEvent.ALARM,
BlackBerryEvent.ATTR_NONE,remMinInt*60);
_event.commit();

I think that this is wrong:
bbEvent.addDate(BlackBerryEvent.ALARM,0,time)
and that you should use:
bbEvent.addInt(BlackBerryEvent.ALARM,0,time2)
take care that "time2" is long !
And you can add two other dates for example:
bbEvent.addDate(bbEvent.START, PIMItem.ATTR_NONE,
System.currentTimeMillis()+120000);
bbEvent.addDate(bbEvent.END, PIMItem.ATTR_NONE,
System.currentTimeMillis()+360000);
Try it and tell me your experience in it.

Related

ThinkOrSwim function equivalent in MQL

I have never heard of ThinkOrSwrim till yesterday when someone asked me to convert a ThinkOrSwim script to an MQL4 indicator.
A part of the code is as follows:
input length = 21;
input price = close;
input ATRs=1;
input trueRangeAverageType = AverageType.WILDERS;
def flag;
def EMA = ExpAverage(close, length);
def shift1 = ATRs * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
I want to ask you to kindly check and let me know if my understanding is correct.
input ATRs=1; // This should be a multiplier for ATR, then I think I should give it a double
//type for more flexible control.
input trueRangeAverageType = AverageType.WILDERS;
//As far as I understood, wilders is the same as SMMA in MQL.
.
def shift1 = ATRs * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
Here is the main piece of this code which I need your help with.
My understanding is as follows
ATRs ==>> Just a multiplier
I think the rest of this line is calculating the ATR, right?
If so, then I can see that I cannot simply convert this to iATR (in mql), because we are not able to choose MA Methode of ATR in mql4.
Then I think first I have to put the "True Range" of each bar in an array and then use this array as a price source to get the averages.
MQL4:
for(int i = 0; i < rates_total; i++)
{
data[i] = iATR(_Symbol, TF_1, 1, i);
}
for(int i = 0; i < limit; i++)
{
ExtBuffer[i] = iMAOnArray(data, 0, Inplenght, 0, InpMAMethod, i);
}
If I'm in the right way yet, Then I think the iATR period has to be 1, to have the TrueRange of each bar and not the average of the TrueRanges.
And then have the variable length (from thinkOrSwim inputs) as the period parameter for iMAOnArray.
I would appreciate any help with it.
Regards
Edit:
I forgot to ask you something,
why should the programmer who wrote this thinkscript code call this variable shift1?

GKTurnBasedMatch doesn't consistently advance to the next player (Xamarin, Apple GameKit)

I'm using a turn-based match for a board game, and when a turn is complete I call GKTurnBasedMatch.EndTurn and pass the match participants and the new match data as the arguments. I need the game to advance to the unmatched players, but it only does so after some indeterminate time related to the timeout value. Setting the timeout value 0 only prevents the game from ever progressing past player 1. The match data is being updated, so the app is definitely communicating with Game Center servers. What am I missing here?
private void endTurn(double timeout)
{
// Copies list of participants to a mutable array
GKTurnBasedParticipant[] Participants = new GKTurnBasedParticipant[match.Participants.Length];
match.Participants.CopyTo(Participants, 0);
// Advances to the next player
match.EndTurn(Participants, timeout, matchData, (e) =>
{
// If there is an error message, print it to the console
if (e != null)
{
Console.WriteLine(e.LocalizedDescription);
Console.WriteLine(e.LocalizedFailureReason);
}
// Otherwise proceed normally
else
turnOverUpdate();
});
}
Apple's documentation is quite poor for the EndTurn method, but I figured it out. The NextParticipants field should be treated like EndTurnWithNextParticipant, so you have to copy GKTurnBasedMatch.Participants and reorder it so the next player is first and so fourth. The match only gives you the participants in order of joining, not relative to the local player, so you have to sort it. Below is the code I used to accomplish this.
List<GKTurnBasedParticipant> participants = new List<GKTurnBasedParticipant>();
// Gets the index of the local player
int index = 0;
for (int i = 0; i < match.Participants.Length; i++)
{
if (match.Participants[i].Player != null)
{
if (match.Participants[i].Player.PlayerID == GKLocalPlayer.LocalPlayer.PlayerID)
{
index = i;
break;
}
}
}
int offset = match.Participants.Length - index;
for (int i = 1; i < offset; i++)
participants.Add(match.Participants[i + index]);
for (int i = 0; i <= index; i++)
participants.Add(match.Participants[i]);
GKTurnBasedParticipant[] nextParticipants = participants.ToArray();

Why wont my MQL4 EA code change my open positions to breakeven?

Trying to add a StopLoss to my open market positions which also takes into account my brokers stoplevel. I have set this to add a breakeven stop loss when my trade gets to 100 points in profit.
This is the code - but its completely ignoring any order modification during my back testing.
OK this is now what I have so far, one for loop for the buy, one for the sell. I;ve also declared the "BuyMod" & "SellMod" to true as was suggested in pervious answers, as well as Normalzing prices in the OrderModify signature.
/*Breakeven Order Modification*/
bool BuyMod = true;
bool SellMod = true;
for(int b = OrdersTotal()-1;b>=0;b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
{
double aBidPrice = MarketInfo(Symbol(),MODE_BID);
double anOpenPrice = OrderOpenPrice();
double aNewTpPrice = OrderTakeProfit();
double aCurrentSL = OrderStopLoss();
double aNewSLPrice = anOpenPrice;
double pnlPoints = (aBidPrice - anOpenPrice)/_Point;
double stopPoints = (aBidPrice - aNewSLPrice)/_Point;
int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL));
int aTicket = OrderTicket();
if(OrderType() == OP_BUY)
if(stopPoints >= stopLevel)
if(aTicket > 0)
if(pnlPoints >= breakeven)
if(aNewSLPrice != aCurrentSL)
{
BuyMod = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(aNewSLPrice,Digits),NormalizeDouble(aNewTpPrice,Digits),0,buycolor);
SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
}
}
}
for(int s = OrdersTotal()-1; s>=0; s--)
{
if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
{
double anAskPrice = MarketInfo(Symbol(),MODE_ASK);
double anOpenPrice = OrderOpenPrice();
double aNewTpPrice = OrderTakeProfit();
double aCurrentSL = OrderStopLoss();
double aNewSLPrice = anOpenPrice;
double pnlPoints = (anOpenPrice - anAskPrice)/_Point;
double stopPoints = (aNewSLPrice - anAskPrice)/_Point;
int stopLevel = int(MarketInfo(Symbol(),MODE_STOPLEVEL));
int aTicket = OrderTicket();
if(OrderType()== OP_SELL)
if(stopPoints >= stopLevel)
if(pnlPoints >= breakeven)
if(aNewSLPrice != aCurrentSL)
if(aTicket > 0)
{
SellMod = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(aNewSLPrice,Digits),NormalizeDouble(aNewTpPrice,Digits),0,sellcolor);
SendMail("Notification of Order Modification for Ticket#"+IntegerToString(OrderTicket(),10),"Good news! Order Ticket#"+IntegerToString(OrderTicket(),10)+"has been changed to breakeven");
}
}
}
This code will not work due to several reasons:
First:The function-call signature of OrderModify() is wrong.
You might want to know, that OrderModify() call-signature requires as per MQL4 documentation to include also an OrderExpiration value in the call, even though the Order is currently not a pending order any more.
Check the documentation and the IDE tooltip, which helps one remind the order of the function call parameters.
Second:The other, less-visible reasons could be reported by GetLastError() after the OrderModify() function call returns a False as an indication of failure.

Action Script 3.0 from 2.0 Falling Randomly Placed Objects and a countdown timer

Looking for some help on a lesson I teach to my pupils in Flash Animation.
Not overly familiar with the code, I can essentially do this one thing
I have four layers on my animation. Background, snow, timer and action script.
I have the following code on my snow layer (which has a simple oval in white on it)
onClipEvent (load) {
movieWidth=550;
movieHeight=400;
i=1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 60+Math.random()*100;
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;
}
onClipEvent (enterFrame){
rad += (k/180)*Math.PI;
this._x -= Math.cos(rad);
this._y += i;
if(this._y>=movieHeight){
this._y = -5;
}
if((this._x>=movieWidth) || (this._x<=0)){
this._x = -10+Math.random()*movieWidth;
this._y = -5;
}
}
and this on my action script layer
this.onEnterFrame = function()
{
var today:Date = new Date();
var currentYear = today.getFullYear();
var currentTime = today.getTime();
var targetDate:Date = new Date(currentYear, 11, 25);
var targetTime = targetDate.getTime();
var timeLeft = targetTime - currentTime();
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
var hours = Math.floor(min/60);
var days = Math.floor(hours/24);
sec = String(sec % 60);
if(sec.length < 2){
sec = "0" + sec;
}
min = String(min % 60);
if(min.length < 2){
min = "0" + min;
}
hours = String(hours % 24);
if(hours.length < 2){
hours = "0" + hours;
}
days = String(days)
var counter:String = days + " Days\n" + hours + ":" + min + ":" + sec;
time_txt.text = counter;
}
for (k=0; k<100; k++){
duplicateMovieClip(this.snow, "snow"+k, k);
}
I know this worked previously in AS2, but I have trouble getting it to work.
Currently getting a syntax error which wasn't there when I used an older version
Any help is much appreciated
Thanks
You are using flash player 6 syntax with flash player 5 elements (onClipEvent() handlers assignable to movieclips on the timeline). I don't think one could possibly expect to see something like that now... As it started getting outdated by late 2001, when FP 6 with (almost) fully ECMA262-compliant ActionScript 1.0 emerged.
Anyway, you can compile it after setting File -> Publish Settings... -> Script option to ActionScript 1.0 or ActionScript 2.0. Your code does work this way, I copied and pasted it to make sure. Be carefull to place the onClipEvent() code on the snow clip and not on the timeline frame. This is the FP5 way of handling events. And the rest of the code goes to timeline frame (I guess this is what you did).
You may also need to change target Flash Player version in case your IDE doesn't allow you to set script version to 1.0 without that (with Flash Pro CS6 this is not the case).
Working example (open in CS5 or newer): snowCS5.fla

How to make if loop in grails?

I'm beginner in Grails, please help. I have this in my gsp
<div class="right66">
<g:select class="time_pick" name="pick_day" placeholder="" from="${['Dani', 'Sati', 'Minute']}" valueMessagePrefix="book.category"/>
</div>
In translation: Dani = Days, Sati = Hours, Minute = Minutes. I need to save data in minutes but the user can choose if the input is in minutes, hours, or days. So I have to do if loop. I know how if loop works but I don't know how to write it in Grails. I was thinking something like this:
n=1
if(params.type=Dani){
n= 3600
}else if(params.type=Sati) {
n=60
}
def minute=params.minute*n
but how do I call that chosen input "Dani"? I can't write Params.type=Dani. Does if loop go in controller in my case?
If you need to convert your input to minutes, you should do that in your controller or a service. An if here is the same as in Java or Groovy. The inputs from your view will be in the params object in your controller with the same name as the input's id.
def minutes = params.input
if (params.pick_day in ['Sati', 'Dani']) {
minutes *= 60
if (params.pick_day == 'Dani') {
minutes *= 24
}
}
groovy solutions in your controller
you can use below for looping ,but when do you end the loop either you have to decremented or increment the value of n to an end value like say 1.upto(n) means 1...100 ,but every time iu change its value and ur infinite some where...
List types = []
types = params?.type
def minute = 0;
1.upto(n) {
if(types[i]=='Dani'){
n=3600
}
else if(types[i]=='Sati') {
n=60
}
minute = params?.minute*n
}

Resources