Ask! - page 34

 
AnasFX:
Ok it worked, but now the problem is performance. Checking the whole history takes time. I did a backtest for a year and a half period and I noticed that it is slow. The reason is that I am checking all orders in history and compare thier close price and close time. So, is there anyway to limit the history search to make it search only the recent orders? Can I increase the performance anyhow?

you may try

OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY);

but i'm not sure for this one , i think it will pick up the last order in whole history

cheers

 

hallo folk...

can anybody help me..

i have some indicator to create EA....

 
phoenix:
you may try

OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY);

but i'm not sure for this one , i think it will pick up the last order in whole history

cheers

edited of mine fault..it has to be

OrderSelect(HistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);

 

Sorry for double posting but I really need help...

I'm desperate here. I've been trying all night to get my array to work but nothing happens. I've realy tried to be self-sufficient and to try to learn but I still can't get to where I need to go. If someone could please have mercy upon me and lend me some assistance....PLEASE!!!!!

I'm running a grid script but would like to track how many lots I'm running by Symbol. I want to be able to add up what my total position is by lotsize. Let's say I have 0.10, 0.10, 0.10, 0.10, 0.20, 0.30, I want to be able know that I have the equivalent to 0.90 lots. I would also like to know the minimum and maximum lot sizes....0.10 and 0.30

ArrayResize(OrderArray, i);

ArrayInitialize(OrderArray,0);

cnt = 0;

for (i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

////// I can't get anything to work!!!!!!!

BuyLots += OrderArray[cnt][LOTS];

////// This returns Zero when I place BuyLots in my Comments

////// This returns error messages

MaxBuyLots =ArrayMaximum(OrderArray[LOTS],WHOLE_ARRAY,0);

}

 
deeforex:
Sorry for double posting but I really need help...

I'm desperate here. I've been trying all night to get my array to work but nothing happens. I've realy tried to be self-sufficient and to try to learn but I still can't get to where I need to go. If someone could please have mercy upon me and lend me some assistance....PLEASE!!!!!

I'm running a grid script but would like to track how many lots I'm running by Symbol. I want to be able to add up what my total position is by lotsize. Let's say I have 0.10, 0.10, 0.10, 0.10, 0.20, 0.30, I want to be able know that I have the equivalent to 0.90 lots. I would also like to know the minimum and maximum lot sizes....0.10 and 0.30

The problem is that the arrayresize() only resizes the first element, not the second. Obviously your LOTS,PROFIT,and OPEN macros must be 0,1,2 respectively. Also the count object in the for loop is (i) however the block code is refering to (cnt). try this and see if this works.

double OrderArray[][3];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArray[cnt][LOTS];

MaxBuyLots =ArrayMaximum(OrderArray);

}

 

Thanks Nicholishen,

I'm getting a bit closer. BuyLots is returning what is I want but ArrayMaximum is giving me a strange number that I can't quite figure out. It's not returning the largest LotSize.

I really appreciate the help.

dee

 
deeforex:
Thanks Nicholishen,

I'm getting a bit closer. BuyLots is returning what is I want but ArrayMaximum is giving me a strange number that I can't quite figure out. It's not returning the largest LotSize.

I really appreciate the help.

dee

you will need to split the array into different arrays or write a loop to extract the array max. such as:

double OrderArray...[];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArrayProfit[cnt] = OrderProfit() + OrderSwap();

OrderArrayOpen[cnt] = OrderOpenPrice();

OrderArrayLots[cnt] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArrayLots[cnt];

MaxBuyLots =ArrayMaximum(OrderArrayLots);

}

[/CODE]

or

[CODE]double OrderArray[][3];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArray[cnt][LOTS];

}

double MBL;

for(int i=0;i<OrdersTotal();i++){

if(OrderArrayLots[LOTS]>MBL)MBL=OrderArrayLots[LOTS];

}

MaxBuyLots =MBL;

 

Here's another example of a function that tracks tight trailing stops across multiple trades on the same currency by pairing trailing data with the corresponding trade's ticket number - using arrays. Maybe this will help give you some ideas as well.

int tsTicket[21];

double tsPrice[21];

bool tsok[21];

int tkt3[20];

int SuperClose(){// superclose by nicholishen

int cnp=ordercnt();

for(int i=0;i<cnp;i++){

if(OrderMatch(i)){

if(0==0){//Pulls in order that meets the criteria for processing

int num=0;int pos=0;

for(int b=0;b<21;b++){// this (loopB) compares the ticket# of the selected order against the number stored in the ticket array

if(tsTicket==OrderTicket() ){

num++; pos=b;// if ticket numbers match, pos is the position in the array where the trailing data is stored

break;

}

}

if(num==0){ // if the loopB did not find a matching ticket number it is time to initialize the data

for(int j=0;j<21;j++){

if(tsTicket[j]==0){// this is looking for the earliest instance within the array to store the data

pos=j;

break;

}

}

tsTicket[pos]=OrderTicket();// setting the ticket number

tsok[pos]=false;// this is to determine when trailing kicks in

// Print("(",pos,") New ticket initialized = ",tsTicket[pos]);

}

if (OrderType()==OP_SELL) {

if (!tsok[pos] && (OrderOpenPrice()-Ask>=TSactivation*Point || TSactivation==0 ) ) {// if the trailing factor is false, but it has hit the activation point continue

tsPrice[pos]=Ask+TrailPips*Point;// this is the new trailinf stop price

tsok[pos]=true;// it's ok to proceed with trailing stop

if(TrailPips>8){// if this distance from the current price to the new stop, then modify the order.

ModifyStopLoss(Ask+TrailPips*Point,OrderTakeProfit());//modifies order

}

}

if (tsok[pos] && Ask+TrailPips*Point < tsPrice[pos] ){//if the position is gaining in profit

tsPrice[pos]=Ask+TrailPips*Point;

if(TrailPips>8){

ModifyStopLoss(Ask+TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Ask >= tsPrice[pos] ){// if the postion hits the stop price

if(CloseOrder(Ask)==STOP)return(STOP);

Print("Short Order ",tsTicket[pos]," Closed from TS");

}

}

else if (OrderType()==OP_BUY) {// reverse of SELL

if(!tsok[pos] && (Bid-OrderOpenPrice() >= TSactivation*Point || TSactivation==0 ) ) {

tsPrice[pos]=Bid-TrailPips*Point;

tsok[pos]=true;

if(TrailPips>8){

ModifyStopLoss(Bid-TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Bid-TrailPips*Point > tsPrice[pos] ){

tsPrice[pos]=Bid-TrailPips*Point;

if(TrailPips > 8){

ModifyStopLoss(Bid-TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Bid <= tsPrice[pos] ){

if(CloseOrder(Bid)==STOP)return(STOP);

Print("Long Order ",tsTicket[pos]," Closed from TS");

}

}

}

}

if(RefreshRates())return(STOP);

}

for(i=0;i<21;i++){// this searches the array for ticket numbers that are now obsolete due to an order that has closed

if(tsTicket>0){

bool found=false;

for(b=0;b<OrdersTotal();b++){

OrderSelect(b,SELECT_BY_POS);

if(tsTicket==OrderTicket()){

found=true;

break;

}

}

if(!found){// if there are matching ticket numbers in the trade pool and the array then nothing happens

tsTicket=0;tsPrice=0;tsok=false;// if there is an obolete ticket the the data is reset. And the next new ticket data can occupy this space

// Print("Array pos ",i," Cleaned");

}

}

}

return(0);

}

int ordercnt(){

int c;

for(int i=0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS)){

if(OrderMagicNumber()==ID && OrderSymbol()==Symbol()){

tkt3[c]=OrderTicket();

c++;

}

}

}

return(c);

}

//+------------------------------------------------------------------+

int curcnt(){

int c;

for(int i=0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS)){

if(OrderSymbol()==Symbol()){

c++;

return(c);

}

}

}

return(c);

}

//+------------------------------------------------------------------+

bool OrderMatch(int i){

if(OrderSelect(tkt3,SELECT_BY_TICKET)){

if(OrderMagicNumber()==ID && OrderSymbol()==Symbol()){

return(true);

}

}

return(false);

}
 

Thanks again!

I changed the 3rd from the last line to this

if(OrderArray[LOTS]>MBL)MBL=OrderArray[LOTS];

and got it to work. It's way past my bedtime. Tomorrow when I wake I will study the logic of your code. But because I am stubborn I am going to figure out how to use the darn ArrayMaximum function!! I will also have to read more about indexing to see how my old ways were sooooo wrong.

Thanks Again!!!!

dee

 
deeforex:
Thanks again!

I changed the 3rd from the last line to this

if(OrderArray[LOTS]>MBL)MBL=OrderArray[LOTS];

and got it to work. It's way past my bedtime. Tomorrow when I wake I will study the logic of your code. But because I am stubborn I am going to figure out how to use the darn ArrayMaximum function!! I will also have to read more about indexing to see how my old ways were sooooo wrong.

Thanks Again!!!!

dee

just to save you some time the reason the max function was not working for what you wanted is because you are using a multi dimensional array and you are storing different kinds of data. It will return the max of that data, so it is likely that you were returning a profit number or anything higher than your REAL max lot size