Problems with using arrays.

 

Can someone help me out please, I'm only getting 0's as a responce.


What's wrong with this code?


int start()
{
int ArrayName[];
int i;

for(i=0;i<=10;i++)
{
ArrayName[i] = i;
Alert(ArrayName[i]);
}
return(0);
}

 

You can't use dynamic arrays. You 1st need to declare it's size or use ArrayResize.

int ArrayName[3];

//or

int ArrayName[];
ArrayResize(ArrayName, 5);
 

What DataType are you guys using to store prices with longer than 4 decimal places?


obviusly Double is not good..

 
dannyboyonline:

What DataType are you guys using to store prices with longer than 4 decimal places?


obviusly Double is not good..

Double is the correct choice. It holds the value out past 4 decimal places. If you do a Print, that statement is designed to only show 4 decimal places, but the full value is still stored and used in any calculations. This would show you the value out to 5 decimals:

Print(DoubleToStr(Close[i],5));

 
Double should work just fine. I never had a problem storing 5 digits.
 
jmca:
Double should work just fine. I never had a problem storing 5 digits.

Ok thank you guys.


I've got another problem I'm trying to close an sell order 20 pips lower than the started price.

Here's the code I got so far, the program is just not closing the trade even though I know for a fact that the price moved way lower than the 20pips asked.


if ((OrdersTotal() >= 1) && (Bid <= (ibid-(20*Point)))) {
OrderClose(ticket,0.1,Bid,3,Red);
}


ticket is an integer that contains the order id.

ibid is double I used to store the price I placed the sell order at.

 

use:

OrderSelect(ticket, SELECT_BY_TICKET);
OrderClose(ticket, OrderLots(), Ask, 3, Red);

Long: buy at ASK, sell at BID

Short: buy at Bid, sell at ASK


Also, for now on, look at the journal to see if it throws error codes. That will give you/us a general idea of what the prob is.

 

please consider using NormalizeDouble() everywhere...

.

type double is great area of grief for many.

1. you can assume any Predefined variable of type double will be normalized relative to chart's default Symbol() - ie, Point and Digits datums associated with symPair.

2. you cannot assume any other variable of type double which you use is normalized.

3. idea is to be using like with like - simple as that really.

4. end game? you must ensure prior to using in conditional expr that all elements of the expr are normalized.

you may think this is crazy - seriously... just normalize all and then you will experience far fewer 'issues'... is guarantee ;)

5. please also fully understand that Print() by default only prints doubles to four decimal places.

why is this important? sub-pip brokers use three and five decimal places - this is another area where people start getting upset when Print() says ZERO.

Try it yourself!

You must realize this fully. Print() four and five decimal digit constants and see what is what, yes?

Then... use DoubleToStr(<double>,Digits) and compare results (if using Digits, assumes your feed is sub-pip broker :)

.

Print() is your ally but also can be your worst nightmare ;)

 
jmca:

use:

Long: buy at ASK, sell at BID

Short: buy at Bid, sell at ASK


Also, for now on, look at the journal to see if it throws error codes. That will give you/us a general idea of what the prob is.



The problem is the script is never going through the if statement to close the trade.



int start()
{

int ticket;
double ibid;

if (( Bid > (iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0) + (iCustom(NULL,0,"StdDev",20,1,0,0,0,0)* 1.9528)) ) && OrdersTotal() == 0)
{

ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+600*Point,0,"My Order",123456,0,Red);
ibid = Bid;
}

if ((OrdersTotal() >= 1) && (Ask <= (ibid-(20*Point)))) { // The script is never going through this part of the script

OrderSelect(ticket, SELECT_BY_TICKET); //I't not really a problem with the close statements
OrderClose(ticket, OrderLots(), Ask, 3, Red); //it's a problem with the if statement

}

return(0);
}


Thank you.

 
dannyboyonline:

The problem is the script is never going through the if statement to close the trade.



int start()
{

int ticket;
double ibid;

if (( Bid > (iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0) + (iCustom(NULL,0,"StdDev",20,1,0,0,0,0)* 1.9528)) ) && OrdersTotal() == 0)
{

ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+600*Point,0,"My Order",123456,0,Red);
ibid = Bid;
}

if ((OrdersTotal() >= 1) && (Ask <= (ibid-(20*Point)))) { // The script is never going through this part of the script

OrderSelect(ticket, SELECT_BY_TICKET); //I't not really a problem with the close statements
OrderClose(ticket, OrderLots(), Ask, 3, Red); //it's a problem with the if statement

}

return(0);
}


Thank you.

It doesn't look like it's going to remember the value for ibid. You'll need to make that a static variable, else it is reset to nothing each time you cycle through the start func via a new tick. Same thing with ticket. Static variables maintain their values through each new tick once they are set, or if it was a global variable (declared outside of the start function).

 
dannyboyonline:

The problem is the script is never going through the if statement to close the trade.



int start()
...
if ((OrdersTotal() >= 1) && (Ask <= (ibid-(20*Point)))) { // The script is never going through this part of the script

OrderSelect(ticket, SELECT_BY_TICKET); //I't not really a problem with the close statements
OrderClose(ticket, OrderLots(), Ask, 3, Red); //it's a problem with the if statement

20*Point is wrong on a 5 digit broker. You meant 20 pips == 20*0.0001 but get 20*0.00001 == 0.00020 (2 pips)

On a 4 digit broker, Point is one currency pip.

On a 5 digit broker, Point is 1/10 of a currency pip. You either need to multiply all your constants or change the code:


double pips2dbl = Point, pips2points=1;

if (Digits == 3 || Digits == 5) {pips2dbl *= 10.0; pips2points*=10;}


if ((OrdersTotal() >= 1) && (Ask <= (ibid-(20*pips2dbl)))) {


Ask, 3, is the same problem. You need 3*pips2dbl

OrderClose(ticket, OrderLots(), Ask, 3*pips2points, Red);

Reason: