I made an ExpertAdvisor, which opens an order if a price is getting higher or lower over a value of the past day.
Backtesting was fine, but problem is when I put this Expert on an MT4.Graph ( a live currency pair ), it opens an order immediately, because the current value of price, when I started the Expert, had greater or lower value than a max of past day.
I need a condition:
do not start trade if a price is greater or lower than any of extremums of the past day and it is the first Expert running on current currency pair.
You can just use a boolean variable that is initialized to FALSE. Then, before opening the order in the code, check for the value of that variable. The first time it will be FALSE, so your condition is not met and you don't open the order. Immediately set it to TRUE and adjust previous day min/max values accordingly.
On the next iteration it should then open your trade according to new scenario of previous date low/high.
Also, please do have a look to the IsExpertEnabled function here: http://docs.mql4.com/check/isexpertenabled
For further support on Server or Client side MT4 you can contact me via www.mt4software.com or Skype ID: mt4software
Related
I'm trying to develop a task management system where I need to check all the completed tasks for a given date.
Pls refer to the attached sheet.
When I check the box as complete (Column B), Column C automatically has to print the current date. For that I gave the equation: =if(B3=True,NOW(),"")
Each time a checkbox is checked, the date will be automatically added in column C.
But the real challenge is I also want to display the number of tasks I completed on a specific date in Column F. For that, I gave the equation: =COUNTIFs(B:B=true,C:C=E4)
But as you can see, the answer comes in zero. I even checked if the two dates are equal by checking: =if(E4=C4,True,False), and the answer came out False.
Although both the dates are equal, how come they are false? How can I solve this issue?
There are few changes, that you should do:-
Use TODAY() instead of NOW() in your case, as NOW returns Time also, which is the making it showing false, so change this =if(B3=True,NOW(),"") to =if(B3=True,TODAY(),"").
You're wrongly using COUNTIFS, so change this =COUNTIFs(B:B=true,C:C=E4) to =COUNTIFS(B:B,true,C:C,E4)
Reference:-
NOW()
TODAY()
COUNTIFS()
I have a data set scenario where I want to find the user has picked the call only once ,irrespective of the Time against each Order Id, it does not matter to me, when the user has picked the call once, either first time only, second time only or Nth time
only.
If user has picked Call only once then I want to consider "Yes" against that Order No. Other wise "No".
It can be possible that call attempts can be one or more than one against that Order No.
Note : ex :Order No: 44551 , only one attempt is made and the Status is Responsive, then against this order No. "No" should be there as only one attempt is made and which is Responsive.
Similarly Order No : 3456789, only one attempt is made and the Status is Not Responsive, then against this order No. "Yes" should be there as only one attempt is made and which is Not Responsive.
Data Set
Use COUNTIFS function to check the number of rows meeting various criteria (criteria being Order No. , whether it's responsive, which user made the attempt etc).
Then, either output the results to a new column using
=IF(COUNTIFS(...)=1, "Yes", "No") or put them in a conditional formatting rule with the formula =COUNTIFS(...)=1 to highlight relevant rows.
Is there a way to check and see if a time is between a time duration in Crystal Report? Our application has a field, let’s say, called StopTime but stored in integer format. It has the value of 0 at midnight, 60 at 1 am, … , 12x60= 720 at noon.
There is a need for me to create an input parameter with type Time which allows a range value so that user could select to view records within a certain time in the day.
My question is how do I check the value of the field again the input parameter in the record selection formula? I have tried
cast({StopTime}/60 as time) in {?TimeDuration}
but I got the error “There is an error in the formula. Do you want to save it anyway?”
I have also tried
{StopTime}/60 in {?TimeDuration}
and still got the error.
The only way to get around this error is declaring the parameter TimeDuration as Number that accepts a range. However, if possible, it is better to use the type of Time as I can foresee user issues with Number range when a time range is actually needed.
Your field {StopTime} is a number representing a number of minutes, and so must be cast to a time. In Crystal Syntax this is achieved using the CTime function which takes a parameter of a number in days. Therefore you must divide the number of minutes by 1440 to get it in to days. The following will do what you need.
ctime({StopTime}/1440) in {?TimeDuration}
I have an aggregation that looks at a sliding 30-day window (1 day period) of customer purchases, keyed by customer id, with the value being the purchase amount. I sum up the values by key, thus getting the aggregate purchase amount for each customer during the last 30 days. I store this number in a customer record in an external database.
My question is this: if a customer hasn't purchased anything in the last 30 days, how do I automatically reset the customer record to a default value, in this case zero? I'd prefer to keep all my logic in Dataflow and avoid doing too much work, since this will need to scale quite a bit. I'm basically looking for a way to automatically get a key-value for each key that was not in the current window but was in the last, and the value being a potentially configurable default.
Trying to answer my own question, but hoping for feedback as to whether this solution would scale:
I've thought about having a step after the initial window-and-sum. This transform would receive (customerId, purchaseSum) elements once a day, as the result of the 30-day window sum is made available. Since these elements are timestamped (with the timestamp of the most recent input element, I believe) I can re-window them. If I create a two-day window with a one-day period, I would then be able to group by key and process (customerId, [purchaseSumA, purchaseSumB]) for customers that had a purchase both in the last 30 days and in the last 31 days. In this case, I emit purchaseSumB. However, if there's only in element in the list, and the timestamp indicates that the purchase was made 31 days ago, I can assume that there were no purchases from the customer since, and I need to emit (customerId, 0). Does that make sense?
Is it an option to slightly amend the database schema? I suppose now you have something like
(customer_id int, purchases_last_month int)`
Instead how about
`(customer_id int, last_purchase datetime, purchases_last_month int)`
where this time last_purchase is the time of the last purchase made by this customer, and purchases_last_month refers to purchases made in the month before the last one? Then in your DoFn that writes to the database, you'd be making a conditional update (merge/upsert) that updates both last_purchase and purchases_last_month with the values from the current window, but only if last_purchase is increasing. This way you can deal with windows being processed out-of-order or in parallel, at the cost of slight increase in complexity in client queries (which you can address by adding a view on top of the table).
My goal is to add +1 every day to a global variable in Firebase to track how many days have passed. I'm building an app that give new facts every day, and at the 19:00 UTC time marker, I want the case statement number (the day global day variable) to increment by +1.
Some have suggested that I compare two dates and get the days that have passed that way. If I were to do that, I could hard code the initial time when I first want the app to start at 19:00 some day. Then when the function reached1900UTC() is called everyday thereafter, compare it to a Firebase timestamp of that current time which should be 19:00. In theory, it should show that 1 day or more day has passed.
This is the best solution so far, thanks to #DavidSeek and #Jay, but I would still like to figure it out with concurrent writes if anyone has a solution in that front. Until then, I'm marking David's answer as the correct one.
How would I make it so it can't increase more than +1 if multiple people call this? Because my fear is that, when say, 100 people calls this function, it increases by + 1 for every person that has called it.
My app works on a global time, and this function is called every day at 19:00 UTC. So when that function is called I want the day count to increase by one.
You should use transactions to handle concurrent writes:
https://firebase.google.com/docs/database/ios/read-and-write#save_data_as_transactions
You may know this but Firebase doesn't have a way to auto-increment a counter as there's no server side logic, so having a counter increment at 19:00 UTC isn't going to be possible without interaction from a client that happens to be logged on at that time.
That being said, it's fairly straightforward to have the first user that logs in increment that counter - then any other clients logging in after that would not increment it and would have access to that day's new content.
Take a look at Zapier.com - that's a service that can fire time based triggers for your app which may do the trick.
As of this writing, Zapier and Firebase don't play nice together, however, there are a number of other trigger options that Zapier can do with your app while continuing to use Firebase for storage.
One other thought...
Instead of dealing with counters and counting days, why not just have each day's content stored within a node for each day and when each user logs on, the app get's that days content:
2016-10-10
fact: "The Earth is an Oblate Spheroid"
2016-10-11
fact: "Milli Vanilli is neither a Milli or a Vanilli. Discuss."
2016-10-12
fact: "George Washington did not have a middle name"
This would eliminate a number of issues such as counters, updates, concurrent writing to Firebase, triggers etc.
It's also dynamic and expandable and a user could easily see that day's facts or the fact for any prior day(s)
I'm trying to split your question into different sections.
1) If you want to use a global variable to count the days from, let's say, today. Then I would set a timestamp hardcoded into the App that sets the NSDate.
Then In my App, when I need to know the days that have been passed by, I would call a function counting the days from the timestamp to NSDate().
2) If you have a function in your App that counts a +1 into a Firebase, then your fear is correct. It would count +1 for every person that uses the App.
3) If you want every User to have a variable count since when they use their App, then I would handle User registration. So I have a "UserID" and then I would set a Firebase tree like that:
UserID
------->
FirstOpen
-------> Date
That way you could handle each User's first open.
Then you are able to set a timestamp AND call +1 for every user independently. Because then you set the +1 for every user into their UserID .child