Why returned value is always 1.797693134862316e+308 - mql4

i try to include a indicator in my ea, but i still get as results always "1.797693134862316e+308" if i print out the copied datas from the icustom-function.
int iCustomHandle;
double trendline_buy_signal[];
double trendline_sell_signal[];
double trendline_sl_price[];
double trendline_tp1_price[];
double trendline_tp2_price[];
double trendline_tp3_price[];
int OnInit()
{
iCustomHandle = iCustom(symbol, time, "\\Indicators\\Market\\myindicator.ex5");
if(iCustomHandle == INVALID_HANDLE){ return(INIT_FAILED); }
return (INIT_SUCCEEDED);
}
void OnTick()
{
int valueDistance = 0;
int calculatedInd = BarsCalculated(iCustomHandle);
ArraySetAsSeries(trendline_buy_signal, true);
ArraySetAsSeries(trendline_sell_signal, true);
ArraySetAsSeries(trendline_sl_price, true);
ArraySetAsSeries(trendline_tp1_price, true);
ArraySetAsSeries(trendline_tp2_price, true);
ArraySetAsSeries(trendline_tp3_price, true);
int copied;
copied = CopyBuffer(iCustomHandle, 2, 0, calculatedInd, trendline_buy_signal);
copied = CopyBuffer(iCustomHandle, 8, 0, calculatedInd, trendline_sell_signal);
copied = CopyBuffer(iCustomHandle, 9, 0, calculatedInd, trendline_sl_price);
copied = CopyBuffer(iCustomHandle, 10, 0, calculatedInd, trendline_tp1_price);
copied = CopyBuffer(iCustomHandle, 11, 0, calculatedInd, trendline_tp2_price);
copied = CopyBuffer(iCustomHandle, 12, 0, calculatedInd, trendline_tp3_price);
Print("calculatedInd:",calculatedInd," > iCustom bufferr: buy_signal:", trendline_buy_signal[valueDistance],
" > sell_signal:",trendline_sell_signal[valueDistance],
" > sl_price:",trendline_sl_price[valueDistance],
" > tp1:",trendline_tp1_price[valueDistance],
" > tp2:",trendline_tp2_price[valueDistance],
" > tp3:",trendline_tp3_price[valueDistance]);
}
What is the reason for it and how i can solve it?
Thanks a lot!

you get EMPTY_VALUE so You should use something like this:
if(Value != EMPTY_VALUE)
Print(Value);

Related

Create nested tables from C

I'm trying to create this datastructure from C:
local table = {
id = 12,
items = {
{
id = 1,
name = "foo",
},{
id = 2,
name = "bar",
}
}
}
However I don't manage to get the anonymous tables working. (It's an array I want but array and tables is the same in lua afaik).
lua_newtable(L);
lua_pushinteger(L, 1);
lua_setfield(L, -2, "id");
lua_newtable(L);
lua_newtable(L);
lua_pushinteger(L, 1);
lua_setfield(L, -2, "id");
lua_pushstring(L, "foo");
lua_setfield(L, -2, "name");
lua_setfield(L, -2, "1");
lua_newtable(L);
lua_pushinteger(L, 1);
lua_setfield(L, -2, "id");
lua_pushstring(L, "bar");
lua_setfield(L, -2, "name");
lua_setfield(L, -2, "2");
lua_setfield(L, -2, "items");
And this gives
{
id = 1,
items = {
["1"] = {
id = 1,
name = "foo"
},
["2"] = {
id = 1,
name = "bar"
}
}
}
I'm using lua 5.1 so I don't have access to lua_seti
As previously mentioned, a table and an array is the same data structure in Lua. In order to “set an array item” it is paramount to use a number as a key. One can’t set an array item with lua_setfield as it uses string keys. From the output we can see that the function worked exactly as advertised - items were inserted into the table under string keys “1” and “2”.
Please use lua_settable.
void lua_settable (lua_State *L, int index); Does the equivalent to
t[k] = v, where t is the value at the given valid index, v is the
value at the top of the stack, and k is the value just below the top.
Use lua_pushnumber to push the desired index into the stack, to be used as the key by lua_settable.

Dart how to get max duplicated element in a list

I have List list= [1,2,3,4,4,4,9,6,7,7,7,8,8,8,8,8,8,8];
how can i return 8 as max repeated value
Something like this?
void main() {
final list = [1, 2, 3, 4, 4, 4, 9, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8];
print(findMaxDuplicatedElementInList(list)); // 8
}
T findMaxDuplicatedElementInList<T>(Iterable<T> list) => list
.fold<Map<T, int>>(
{},
(map, element) =>
map..update(element, (value) => value + 1, ifAbsent: () => 1))
.entries
.reduce((e1, e2) => e1.value > e2.value ? e1 : e2)
.key;
I'd just write it out, as straight-forward as possible:
Assuming the equal elements are always adjacent, and list cannot be empty, return arbitrary element with maximal count if there is more than one:
T maxDuplicated<T>(List<T> elements) {
var element = elements.count;
var count = 1;
var maxElement = element;
var maxCount = count;
for (var i = 1; i < elements.length; i++) {
var nextElement = elements[i];
if (element != nextElement) {
element = nextElement;
count = 1;
} else {
count += 1;
if (count > maxCount) {
maxElement = element;
maxCount = count;
}
}
}
return maxElement;
}
Assuming elements come in random order, so we need to remember every element we have seen,
still not allowing an empty list as input:
T maxDuplicated<T>(List<T> elements) {
var maxCount = 1;
var maxElement = elements.first
var seen = <T, int>{maxElement: maxCount};
for (var i = 1; i < elements.length; i++) {
var element = elements[i];
var count = seen[element] = (seen[element] ?? 0) + 1;
if (count > maxCount) {
maxCount = count;
maxElement = element;
}
}
return maxElement;
}
(Alternatively, I'd sort the list first, if allowed, to always be in the former situation. It's not faster than using a map, if we assume hash map lookup to be a constant time operation, but it will be more memory efficient.)

Swift 2 sqlite - library routine called out of sequence

I am using below code to insert records to sqlite. SQLite DB is already created and sqlite file exists in the right place.
However, when i run my test it gives an error:
Any help on this is appreciated. Already spent some time on this.
By the way, am new to SWIFT :(
"sqlite3_errmsg(carParkDB) UnsafePointer 0x000000010f44a863 "library routine called out of sequence"
Error appears at the first bind statement
sqlite3_bind_text(insertStmt, 1, carParkData.dataSource.rawValue, -1, SQLITE_TRANSIENT)
Below is my DAOImpl
import Foundation
class CarParkDaoImpl : CarParkDao{
var carParkDB : COpaquePointer = nil
var insertStmt: COpaquePointer = nil
let SQLITE_TRANSIENT = unsafeBitCast(-1, sqlite3_destructor_type.self)
func initializeDB(){
let carParkDataSQ = Constants.Paths.path + "/CarParkData.sqlite"
print("Sqlite file: \(carParkDataSQ)")
if(sqlite3_open(carParkDataSQ, &carParkDB) == SQLITE_OK){
let ret:Int32 = sqlite3_exec(carParkDB, Constants.CAR_PARK_SQL.createSql, nil, nil, nil);
if ( ret != SQLITE_OK){
print("Failed to create table: \(Constants.CAR_PARK_SQL.createSql)")
print("Error: \(sqlite3_errmsg(carParkDB))")
closeDB()
}
}else{
print("Falied to open : \(carParkDataSQ)")
print("Error: \(sqlite3_errmsg(carParkDB))")
closeDB()
}
}
func closeDB(){
sqlite3_close(carParkDB)
}
init(){
initializeDB()
}
/**
Responsible to insert the car park data
- Parameter carParkData: CarParkData.
- returns Bool
*/
func insert(carParkData: CarParkData) -> Bool{
prepareInsStatments()
var ret: Bool = false
sqlite3_bind_text(insertStmt, 1, carParkData.dataSource.rawValue, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 2, carParkData.address, -1, SQLITE_TRANSIENT)
sqlite3_bind_double(insertStmt, 3, carParkData.latitude)
sqlite3_bind_double(insertStmt, 4, carParkData.longitude)
sqlite3_bind_int(insertStmt, 5, Int32(carParkData.ltaCarParkID))
sqlite3_bind_text(insertStmt, 6, carParkData.ltaArea, -1, SQLITE_TRANSIENT)
sqlite3_bind_int(insertStmt, 7, Int32(carParkData.ltaLots))
sqlite3_bind_double(insertStmt, 8, carParkData.ltaPrice)
sqlite3_bind_text(insertStmt, 9, carParkData.hdbShortTermParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 10, carParkData.hdbCarParkType, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 11, carParkData.hdbFreeParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 12, carParkData.hdbNightParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_int(insertStmt, 13, Int32(carParkData.hdbId))
sqlite3_bind_text(insertStmt, 14, carParkData.hdbAdHocParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 15, carParkData.hdbCarParkNo, -1, SQLITE_TRANSIENT)
let rc:Int32 = sqlite3_bind_text(insertStmt, 16, carParkData.hdbTypeOfParking, -1, SQLITE_TRANSIENT)
if (rc != SQLITE_OK) {
print(stderr, "failed to prepare statement: %s\n",
sqlite3_errmsg(carParkDB));
sqlite3_close(carParkDB);
return ret;
}
if(sqlite3_step(insertStmt) == SQLITE_DONE){
ret = true;
}
sqlite3_reset(insertStmt)
sqlite3_clear_bindings(insertStmt)
return ret
}
/**
Responsible to finalize all the prepared statements
*/
func finalize(){
sqlite3_finalize(insertStmt)
sqlite3_finalize(updateStmt)
sqlite3_finalize(deleteStmt)
sqlite3_finalize(selectAllStmt)
sqlite3_finalize(selectByIdStmt)
sqlite3_finalize(selectByDataSourceStmt)
}
func prepareInsStatments(){
let stmt = Constants.CAR_PARK_SQL.insertSql.cStringUsingEncoding(NSUTF8StringEncoding)
let ret:Int32 = sqlite3_prepare_v2(carParkDB, stmt!, -1, &insertStmt, nil)
if (ret != SQLITE_OK) {
print(stderr, "failed to prepare statement: %s\n",
sqlite3_errmsg(carParkDB));
sqlite3_close(carParkDB);
}
}
}
Here is my insert sql
static let insertSql:String =
"INSERT INTO CAR_PARK_DATA ( DATASOURCE, ADDRESS, LATITUDE, LONGITUDE "
+ " , LTA_CAR_PARK_ID, LTA_AREA, LTA_LOTS, LTA_PRICE, HDB_SHORT_TERM_PAKING "
+ " , HDB_CAR_PARK_TYPE, HDB_FREE_PARKING, HDB_NIGHT_PARKING, HDB_ID "
+ " , HDB_ADHOC_PARKING, HDB_CAR_PARK_NO, HDB_TYPE_PARK_SYSTEM ) "
+ " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "
Here is my test method
func testInsert(){
carParkData = CarParkData(dataType: DataSourceType.LTA.rawValue, address: "This is Test address", latitude: 100.0, longitude: 200.0, carParkID : 10, ltaCarParkID : 20, ltaArea: "LTA Area", ltaLots: 20, hdbShortTermParking: "Test HDB Short Praking", hdbCarParkType: "HDB Car Park Type", hdbFreeParking: "HDB Free Parking", hdbNightParking: "HDB Night Parking", hdbId : 30, hdbAdHocParking: "HDB Ad Hoc Parking", hdbCarParkNo: "HDB Car Park No", hdbTypeOfParking: "HDB Parking type", ltaPrice: 10.96778, favourite: true)
var val:Bool = carParkDao.insert(carParkData);
XCTAssertTrue(val)

Making matrices in dart

Ok guys, i've tried this:
List<num> test
for(num i = ...){
test[i]...
(...)
for(num j = ...){
test[i][j] = ...
}
}
today but didn't seem to work. My question is... Is there a way to make this in Dart? :)
Here is one way to do it:
main() {
List<List<int>> matrix = new List<List<int>>();
for (var i = 0; i < 10; i++) {
List<int> list = new List<int>();
for (var j = 0; j < 10; j++) {
list.add(j);
}
matrix.add(list);
}
print(matrix);
print(matrix[2][4]);
}
If you know the length ahead of time, and it won't change, you can pass the length to the constructor:
main() {
int size = 10;
List<List<int>> matrix = new List<List<int>>(size);
for (var i = 0; i < size; i++) {
List<int> list = new List<int>(size);
for (var j = 0; j < size; j++) {
list[j] = j;
}
matrix[i] = list;
}
print(matrix);
print(matrix[2][4]);
}
Notice the main difference. In the first example, the list is created empty, so the loops need to explicitly add elements to the list. In the second example, the list is created with a fixed size, with null elements at each index.
Changelog: The original version of the second example used the List.fixedLength(size) constructor, which existed before Dart 1.0.
One way to construct a list with a different value in each position is to use the idiom
new Iterable.generate(size, function).toList()
makeMatrix(rows, cols) =>
new Iterable<List<num>>.generate(
rows,
(i) => new List<num>.fixedLength(cols, fill: 0)
).toList();
main() {
print(makeMatrix(3, 5));
}
prints: [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
It is slightly annoying that to get the fill: parameter you have to construct a fixed length list. Without a fill value, the inner lists would contain nulls. One way to get an extendable list with an initial value is to create an empty list and grow it.
(i) => <num>[]..insertRange(0, cols, 0)
This is using a method cascade to modify the list before returning it - a..b()..c() calls a.b() and a.c() before returning a. This is handy as it avoids the need for a temporary variable.
Note that, for some reason, insertRange has a positional rather than a named fill parameter.
If you want more control over the contents, you can extend the generate-to-list idea to two levels:
makeMatrix(rows, cols, function) =>
new Iterable<List<num>>.generate(
rows,
(i) => new Iterable<num>.generate(cols, (j) => function(i, j)).toList()
).toList();
main() {
print(makeMatrix(3,5, (i, j) => i == j ? 1 : 0));
}
prints: [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0]]
There are some excellent libraries on pub for handling matrices (like Kevin Moore's BOT for example), but if your looking for something quick, you can just do:
List<List> test = new List<List>(n);
for (var i = 0; i < n; i++) {
test[i] = new List(n);
}
for (var i = 0; i < n; i++) {
for (var j = 0; j < n; j++) {
test[i][j] = myValue;
}
}

Difficult couchdb query

I have the following query:
view.reduce.group_level(5).keys
which returns:
[["1f9c79a33f399a7937d880c5f31e8dbc", 2011, 12, 29, 13], ["1f9c79a33f399a7937d880c5f31e8dbc", 2011, 12, 29, 14], ["c38332ffc275b6c70bcf06ffc39ddbdd", 2011, 12, 29, 13], ["c38332ffc275b6c70bcf06ffc39ddbdd", 2011, 12, 29, 14]]
The first key is an id and the other keys are year, month, day, hour
I would like all the rows between 2010 and 2013. So I want to ignore the first key.
The problem is that i need to set the first parameter to get the results but i want to get all the results for all the keys.
for example: view.reduce.group_level(5).startkey(["every_possible_key", 2010]).endkey(['every_possible_key", 2013, {}])
If i leave the first key blank than i get nothing. If i give it "\u9999" than i get everything and it ignores the 2nd key.
Somebody knows what I am doing wrong?
Thanks a lot.
map:
function(d) {
if (d['type'] == 'State' && d['driver_id'] && d['name'] && d['created_at']) {
var dt = new Date(d.created_at);
emit([d.driver_id, dt.getFullYear(), dt.getMonth() + 1, dt.getDate(), dt.getHours()], d.name);
}
}
reduce:
function(k,v,r) {
var result = {
'hire': 0, 'hired': 0, 'arrived': 0, 'pick up': 0, 'drop off': 0,
'missed': 0, 'rider cancel': 0, 'driver cancel': 0, 'no show': 0,
'avail': 0, 'unavail': 0, 'other': 0
};
if (r) {
var row = null;
for (i in v) {
row = v[i];
for (j in row) {
result[j] += row[j];
}
}
} else {
for (i in v) {
if (result[v[i]] != null) {
result[v[i]] += 1;
} else {
result['other'] += 1;
}
}
}
return result;
}
What you're "doing wrong" is to use a key you don't need in your query as the first key of your view.
If you need it for another query, create another view.

Resources