MultiTimeFrame Indicator BackTesting mql4 - indicator

before posting any code I would like to understand if it is possible to backtest a Custom Indicator, for a MetaTrader4 Terminal, based on a multi time frame strategy.
I have looked on mql5 forum, but I could not find any clear indications or approach to the issue.

...before posting any answer I would like to understand, what do you consider a multi-time frame strategy in custom indicator context.
How to make the step forward?
Select your own way - The Approach
In any case, one can use function calls aimed to retrieve values, collected from a perspective of a different time-frame, with a use of proper indication of { PERIOD_M1 | .. | PERIOD_H1 | PERIOD_H4 | .. } in the function call protocol,
or
one can create and maintain one's own virtual super-framing / sub-framing independently of the current graph's "own" time-frame.
double v30SEC_O[], v30SEC_H[], v30SEC_L[], v30SEC_C[],
vM1_O[ ], vM1_H[ ], vM1_L[ ], vM1_C[ ],
vM3_O[ ], vM3_H[ ], vM3_L[ ], vM3_C[ ],
vH7_O[ ], vH7_H[ ], vH7_L[ ], vH7_C[ ]; // vTF as needed
bool v30SEC_newBarEVENT = False,
vM1_newBarEVENT = False,
vM3_newBarEVENT = False,
vH7_newBarEVENT = False;
void aNewBarEventMONITOR(){ ...
static int v30SEC_Bars = EMPTY,
vM1_Bars = EMPTY,
vM3_Bars = EMPTY,
vH7_Bars = EMPTY;
// check aNewBarEVENT:
// update state-vars:
}
Does it work in spite of many posts on failed MTF [StrategyTester] results?
In each of cases posted above, one may use the other one to check and proof the correctness of the outputs.
Yes, unit-tests are a good safety belts habit in this domain.
The recent "new"-MQL4.56789+ shifts and frequent interim compiler ( syntax ) live-updates ( you get a new Help to notice them ) make unit-testing a must-do part of the pre-release testing + production code maintenance.

Related

Karate: can we make multiple calls from scenario outline using an array variable? [duplicate]

I currently use junit5, wiremock and restassured for my integration tests. Karate looks very promising, yet I am struggling with the setup of data-driven tests a bit as I need to prepare a nested data structures which, in the current setup, looks like the following:
abstract class StationRequests(val stations: Collection<String>): ArgumentsProvider {
override fun provideArguments(context: ExtensionContext): java.util.stream.Stream<out Arguments>{
val now = LocalDateTime.now()
val samples = mutableListOf<Arguments>()
stations.forEach { station ->
Subscription.values().forEach { subscription ->
listOf(
*Device.values(),
null
).forEach { device ->
Stream.Protocol.values().forEach { protocol ->
listOf(
null,
now.minusMinutes(5),
now.minusHours(2),
now.minusDays(1)
).forEach { startTime ->
samples.add(
Arguments.of(
subscription, device, station, protocol, startTime
)
)
}
}
}
}
}
return java.util.stream.Stream.of(*samples.toTypedArray())
}
}
Is there any preferred way how to setup such nested data structures with karate? I initially thought about defining 5 different arrays with sample values for subscription, device, station, protocol and startTime and to combine and merge them into a single array which would be used in the Examples: section.
I did not succeed so far though and I am wondering if there is a better way to prepare such nested data driven tests?
I don't recommend nesting unless absolutely necessary. You may be able to "flatten" your permutations into a single table, something like this: https://github.com/intuit/karate/issues/661#issue-402624580
That said, look out for the alternate option to Examples: which just might work for your case: https://github.com/intuit/karate#data-driven-features
EDIT: In version 1.3.0, a new #setup life cycle was introduced that changes the example below a bit.
Here's a simple example:
Feature:
Scenario:
* def data = [{ rows: [{a: 1},{a: 2}] }, { rows: [{a: 3},{a: 4}] }]
* call read('called.feature#one') data
and this is: called.feature:
#ignore
Feature:
#one
Scenario:
* print 'one:', __loop
* call read('called.feature#two') rows
#two
Scenario:
* print 'two:', __loop
* print 'value of a:', a
This is how it looks like in the new HTML report (which is in 0.9.6.RC2 and may need more fine tuning) and it shows off how Karate can support "nesting" even in the report, which Cucumber cannot do. Maybe you can provide feedback and let us know if it is ready for release :)

Unable to display text output with Alexa Show via flask-ask

So I have built a custom pool control system in Python. I then used Flask-ask to integrate this with my Echo Dots and Show. With the Echo Show, I was using a simple_card format which reads back all my information while showing it on the screen:
#ask.intent("GetAllStats")
def get_pool_stats():
pool_current_ph = read_database("pool_chemicals", "pool_current_ph")
pool_current_orp = read_database("pool_chemicals", "pool_current_orp")
pool_current_temp = int(float(read_database("system_status", "pool_current_temp")))
pool_level_percentage = read_database("pool_level", "pool_level_percentage")
pic = 'https://richard.mydomian.net/pool_control.jpg'
msg = render_template('our_stats', temperature=pool_current_temp,
ph=pool_current_ph,
orp=pool_current_orp,
level=pool_level_percentage)
return statement(msg).simple_card(title='Pool Control', content='Pool Temperature: {0}\n Pool PH: {1}\n Pool ORP: {2}\n Water Level: {3}% .format(pool_current_temp,pool_current_ph,pool_current_orp,pool_level_percentage))
Here is my our_stats from my templates.yaml:
our_stats: |
<speak>
The pool temperature is currently {{temperature}} degrees. The P H of our pool water is currently {{ph}}, while our oxygen reduction potential
is right at {{orp}}. The level of our water is at {{level}} percent.
</speak>
This works great, but I do not have any font control (that I can find) and the background is always grey.
So I started to research using the display_render method and I was able to get it to put up a really nice background picture of my pool and still read back my stats, but now I cannot get it to display the information in printed form.
I changed my return statement above to:
return statement(msg).display_render(template='BodyTemplate3', title='Pool Control', background_image_url=pic)
Again, this works great and reads back my information, but it I try to pass any content to it via textContent, primaryText, content, or text it always fails. I have also tried various templates including BodyTemplate's and listTemplate's. All to no avail. Anytime I try to add content to the screen the skill fails. I remove the content and I get a fantastic picture and it will speak to me all of the information, but that is as far as I can get.
One of the main problems is that I just have not been able to find any pertinent kind of examples using Flask-Ask and the Echo Show with anything but the simple_card.
I am hoping someone has figured this out and can point me in the right direction.
You have to edit your flask-ask models.py.
In the method display_render delete:
,
'textContent': text
change:
def display_render(self, template=None, title=None, backButton='HIDDEN', token=None, background_image_url=None, image=None, text=None, hintText=None):
to:
def display_render(self, template=None, title=None, backButton='HIDDEN', token=None, background_image_url=None, image=None, text=None, format=None, hintText=None):
and add after:
if background_image_url is not None:
directive[0]['template']['backgroundImage'] = {
'sources': [
{'url': background_image_url}
]
}
this:
if format == None:
format = 'PlainText'
if text is not None:
directive[0]['template']['textContent'] = {
'primaryText': {
'type': format,
'text': text
},
'secondaryText': {
'type': format,
'text': None
},
'tertiaryText': {
'type': format,
'text': None
}
}
Now you should be able to use:
display_render(template='BodyTemplate6', title='Pool Control', background_image_url=pic, text='Text', format='Format')
I'm using BodyTemplate6 here because some Templates don't support text, format can be 'PlainText' or 'SSML'

Exporting all rules in SonarQube

I need to export all rules by language. I can get a set of 100 rules from the web API for a given language, but it seems the web API is limited to paging through the rules 100 rules at a time. Obviously I can set the pagesize higher (i.e. 500) but what about rule sets that have more than 500 rules (i.e. Java)? Do I need to page through the rules until the end? How do I tell when I have the last page?
Try and see: https://sonarqube.com/api/rules/search?languages=java,js , returns the list of rules for Java and JavaScript . Response starts by:
{
"total": 537,
"p": 1,
"ps": 100,
"rules": [...] // 100 items
}
The rest of it is just good ol' maths: 537 items in total, page sizes of 100. So, all things considered, page 6 should be the last one: https://sonarqube.com/api/rules/search?languages=java,js&p=6 - 37 rules returned, job is done (and incrementing further p would anyhow only give you an empty JSON back.

Update AngularJS data from separate source

I'm working on my first Angular project and I've been thinking of the best way to word this question for a while now but I'm going to give this a shot.
I'm building an app that uses the Veralite (MiOS) to return device data in json format. The first request returns all of the devices on the system (example below).
"devices":[
{
"name":"Bedroom Light",
"altid":"4",
"id":6,
"category":2,
"subcategory":0,
"room":0,
"parent":1,
"status":"0",
"level":"0",
"state":-1,
"comment":""
},
{
"name":"Office Light",
"altid":"6",
"id":18,
"category":2,
"subcategory":0,
"room":0,
"parent":1,
"level":"0",
"status":"0",
"state":-1,
"comment":""
}
Once all of the devices are returned, my script begins long polling the vera engine. Once a change to a device is made the results of the long poll are returned, but the results only include the devices that were changed (example below).
"devices":[
{
"altid":"6",
"id":"18",
"subcategory":"0",
"room":"0",
"parent":"1",
"level":"20",
"status":"1",
"state":"4",
"comment":"Office Light: Transmit was ok"
}
What I am trying to wrap my head around, is the proper way to update the existing devices array with the newly updated data. Would I need to convert them to arrays, then loop through each array and try to match them by keys?
Hopefully I asked this as clearly as possible.
EDIT: Just to update this a bit for anyone that stumbles across this, specifically people interested in developing for the Veralite. The ID returned from the original request will be returned as an integer, but when long polling the engine, the ID will be returned as a string. So even though the selected answer is correct, you'll need to either parse the updated device ID as an integer (parseInt), or only use a == instead of a === when filtering the devices.
You can loop through the object fields just like you can loop through an array with Object.keys.
Conceptually something like:
Step 1) Find the updated product, by the field id:
var previousVersionDevice = $scope.devices.filter(function(item) {
return item.id === updateDevice.id; // Keep only the one existing device that matches id
})[0];
Step 2) Loop through the keys in the product and overwrite the previous values with the ones received.
Object.keys(updatedDevice).forEach(function(key) {
previousVersionDevice[key] = updatedDevice[key]; // Overwrite/add all from updated version
});
yes, you can loop through and find the matching device via some sort of unique key (assuming id is unique and won't change, you can use that).

Retrieving Specific Active Directory Record Attributes using C#

I've been asked to set up a process which monitors the active directory, specifically certain accounts, to check that they are not locked so that should this happen, the support team can get an early warning.
I've found some code to get me started which basically sets up requests and adds them to a notification queue. This event is then assigned to a change event and has an ObjectChangedEventArgs object passed to it.
Currently, it iterates through the attributes and writes them to a text file, as so:
private static void NotifierObjectChanged(object sender,
ObjectChangedEventArgs e)
{
if (e.ResultEntry.Attributes.AttributeNames == null)
{
return;
}
// write the data for the user to a text file...
using (var file = new StreamWriter(#"C:\Temp\UserDataLog.txt", true))
{
file.WriteLine("{0} {1}", DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString());
foreach (string attrib in e.ResultEntry.Attributes.AttributeNames)
{
foreach (object item in e.ResultEntry.Attributes[attrib].GetValues(typeof(string)))
{
file.WriteLine("{0}: {1}", attrib, item);
}
}
}
}
What I'd like is to check the object and if a specific field, such as name, is a specific value, then check to see if the IsAccountLocked attribute is True, otherwise skip the record and wait until the next notification comes in. I'm struggling how to access specific attributes of the ResultEntry without having to iterate through them all.
I hope this makes sense - please ask if I can provide any additional information.
Thanks
Martin
This could get gnarly depending upon your exact business requirements. If you want to talk in more detail ping me offline and I'm happy to help over email/phone/IM.
So the first thing I'd note is that depending upon what the query looks like before this, this could be quite expensive or error prone (ie missing results). This worries me somewhat as most sample code out there gets this wrong. :) How are you getting things that have changed? While this sounds simple, this is actually a somewhat tricky question in directory land, given the semantics supported by AD and the fact that it is a multi-master system where writes happen all over the place (and replicate in after the fact).
Other variables would be things like how often you're going to run this, how large the data set could be in AD, and so on.
AD has some APIs built to help you here (the big one that comes to mind is called DirSync) but this can be somewhat complicated if you haven't used it before. This is where the "ping me offline" part comes in.
To your exact question, I'm assuming your result is actually a SearchResultEntry (if not I can revise, tell me what you have in hand). If that is the case then you'll find an Attributes field hanging off of that guy, and from there there is AttributeNames and Values. I think you'll see how it works from there if you have Values in hand, for example:
foreach (var attr in sre.Attributes.Values)
{
var da = (DirectoryAttribute)attr;
Console.WriteLine(da.Name);
foreach (var val in da.GetValues(typeof(byte[])))
{
// Handle a byte[] val ...
}
}
As I said, if you have something other than a SearchResultEntry in hand, let us know and I can revise the code sample.

Resources