Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (2) Thread Tools Display Modes
  #341 (permalink)  
Old 09-12-2006, 05:58 AM
deeforex's Avatar
Member
 
Join Date: Oct 2005
Posts: 91
deeforex is on a distinguished road
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

Code:
      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);

            }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #342 (permalink)  
Old 09-12-2006, 06:12 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by 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.
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];

             

             
             MaxBuyLots =ArrayMaximum(OrderArray);

            }
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein

Last edited by Nicholishen; 09-12-2006 at 06:17 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #343 (permalink)  
Old 09-12-2006, 06:36 AM
deeforex's Avatar
Member
 
Join Date: Oct 2005
Posts: 91
deeforex is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #344 (permalink)  
Old 09-12-2006, 06:47 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by 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:
Code:
 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);

            }
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[i][LOTS]>MBL)MBL=OrderArrayLots[i][LOTS];
            }
            MaxBuyLots =MBL;
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #345 (permalink)  
Old 09-12-2006, 06:53 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
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.

PHP Code:
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[b]==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==) ) {// 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==) ) {
                  
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[i]>0){
         
bool found=false;
         for(
b=0;b<OrdersTotal();b++){
            
OrderSelect(b,SELECT_BY_POS);
            if(
tsTicket[i]==OrderTicket()){
               
found=true;
               break;
            }
         }
         if(!
found){// if there are matching ticket numbers in the trade pool and the array then nothing happens
            
tsTicket[i]=0;tsPrice[i]=0;tsok[i]=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[i],SELECT_BY_TICKET)){
      if(
OrderMagicNumber()==ID && OrderSymbol()==Symbol()){
         return(
true);
      }
   }
   return(
false);

__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #346 (permalink)  
Old 09-12-2006, 07:03 AM
deeforex's Avatar
Member
 
Join Date: Oct 2005
Posts: 91
deeforex is on a distinguished road
Thanks again!

I changed the 3rd from the last line to this
Code:
                  if(OrderArray[i][LOTS]>MBL)MBL=OrderArray[i][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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #347 (permalink)  
Old 09-12-2006, 07:11 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by deeforex
Thanks again!

I changed the 3rd from the last line to this
Code:
                  if(OrderArray[i][LOTS]>MBL)MBL=OrderArray[i][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
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #348 (permalink)  
Old 09-14-2006, 01:21 PM
Senior Member
 
Join Date: Feb 2006
Posts: 111
tirou is on a distinguished road
HI CG,
Is it possible programatically to do the following action.
a. To delete an indicator from a chart.
b. Wait for "X" time.
c. Reload the Indicator.
d. Wait for "X" time.
e. Repeat from "a".
If it is possible, can you please post it in the forum. Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #349 (permalink)  
Old 09-14-2006, 01:39 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Cool

Quote:
Originally Posted by tirou
HI CG,
Is it possible programatically to do the following action.
a. To delete an indicator from a chart.
b. Wait for "X" time.
c. Reload the Indicator.
d. Wait for "X" time.
e. Repeat from "a".
If it is possible, can you please post it in the forum. Thanks in advance.
This couldn't be coded with normal MQL4, you need to go to:
Send Keyboard keys to MetaTrader!
and
Programmatically Refresh your charts

The idea is to send keys to MetaTrader, the keys you might need:
Ctrl+I to open Indicator list window. Then Send the first letter of the Indicator's name key (For example: C for CCI). Then you have to send ALT_D to delete the indicator then send ESC key.

Hope it works!
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #350 (permalink)  
Old 09-14-2006, 01:53 PM
Junior Member
 
Join Date: Aug 2006
Posts: 15
jsevero83 is on a distinguished road
anyone know if is possible lock an EA to not work in backtests?
thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram, forex

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 09:53 PM