Hi,
I am a little frustrated about how MQL4 deal with numbers.
Below is my code. It is supposed to print the array values of “floor” and “ceiling”. Their variable type is double, and they serve as the potential entry point.
However, when I executed the code. It only returned 0.
What happened?
Cheng
//***********************************************************************
int Number=1; //Number of Orders
Number= NormalizeDouble(AccountBalance()/1000, 0) ;
double ceiling[];
double floor[];
for (int i=1; i<=Number; i++)
{
ceiling[i]= NormalizeDouble(target+(((high-target)/Number)*i), 5);
floor[i] = NormalizeDouble(target-(((target-low)/Number)*i), 5);
Print (Number, " ", ceiling[i]," ", floor[i]);
}
Your code is missing something. Hard to say what’s going on without to know what is target etc.
Just an assumption: You know that prices are not measured in pips but fractions of 1 on common pairs?
1.10 - 1.05 is not 5 but 0.05.
Here is the full code:
//This system set up trade based on a TARGET RATE.
//
//Operates on a daily chart
#property copyright "Copyright © 2011, Cheng Yu"
#property link "http://www.chengyuofficial.com"
double target_automated=1.30000;
double target=1.30000;
double high=1.60000;
double low=0.90000;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
//
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int Number=1; //Number of Orders
Number= NormalizeDouble(AccountBalance()/1000, 0) ;
double ceiling[];
double floor[];
for (int i=1; i<=Number; i++)
{
ceiling[i]= NormalizeDouble(target+(((high-target)/Number)*i), 5);
floor[i] = NormalizeDouble(target-(((target-low)/Number)*i), 5);
Print (Number, " ", ceiling[i]," ", floor[i]);
}
if (OrdersTotal()>=Number)
{
return;
}
for (i=1; i<=Number; i++)
{
OrderSend(Symbol(), OP_BUYLIMIT, 0.1, floor[i], 3, 0, 0, NULL, 0, 0, Green);
OrderSend(Symbol(), OP_SELLLIMIT, 0.1, ceiling[i], 3, 0, 0, NULL , 0, 0, Red);
}
//----
return(0);
}
//+------------------------------------------------------------------
Just a glance and as I said. If you wanna have pips, you must multiply by 10000. If not most of your numbers are below zero.
Oh well, not sure now. That variable calling floor was a little confusing to me, lol. A return code of 0 is success imho.
No, the ordersend delivers the ticket number. However, your return there is zero so it for sure delivers zero. Really, you need to better explain what exactly is the issue please.
Number is accountbalance. If that is well below 1000 then it is below 1 or zero. So all numbers are maybe multiplied by zero. Really, I have seen a lot of code, but it’s really confusing. Ceiling and floor is usually a math function, lol.
I need more info. What exactly is accountbalance? And why do you put that Normalize function around that? Makes no sense to me.
What is the value if you print number? Would be nice to see all the output how it is printed.
Plus then please let print the value of ALL the other variables as well. That makes it a lot easier to go over somebody elses code and find an issue.
However, the issue is sure to seek inside of your code. The metatrader computes rather accurate.
I just joined this forum to reply you
Let’s forget ur returning NormalizeDouble to Number which you declared as int.
But before we forget the following functions will help u decide how many £$1000s in ur account balance.
MathFloor
docs.mql4.com/math/MathFloor
MathMin
docs.mql4.com/math/MathMin
The main issue you have is ceiling and floor are arrays:
Double ceiling[] for example.
But u are using them as scalars - simple numbers without [] in ur loops. We should see [ i ] in ur loops as these are arrays.
Also in ur Print statements.
Arrays are indexed from zero so ur i loop variable should start from 0 not 1 as the first element in ur arrays are ceiling[0] and floor[0]. ceiling and floor used alone (to keep it simple) mean nothing in ur code while they are declared as arrays.
If u know ceiling[i] corresponds to target 1 when i is 0 then u can say i = 0; i < Number; in ur loop then in ur equations use i+1 where u had i before cos ceiling[0] is for target 1, ceiling[1] is for target 2 and/so ceiling[ i ] is for target i+1
Wrote this on an iPhone, the software doesn’t let me write ‘[ ]’ all the time. Thinks I want italics