Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1341 (permalink)  
Old 10-06-2008, 11:08 PM
Senior Member
 
Join Date: Aug 2008
Location: London
Posts: 138
Limstylz is on a distinguished road
Magic number

cutzpr - you need to use a magic number and then use something like the following:

for (cnt = total ; cnt >=0 ; cnt-- )
{

OrderSelect(0,SELECT_BY_POS,MODES_TRADES);
if (OrderMagicNumber()==yourmagicnumber)

{if(OrderType()==OP_BUY)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1342 (permalink)  
Old 10-07-2008, 02:03 PM
cutzpr's Avatar
Member
 
Join Date: Jan 2008
Posts: 60
cutzpr is on a distinguished road
Well taking a look at that code, I conjured up this piece of code below. I am not sure if it coded properly. I set up

int MaxLong=5,MaxShort=5;
extern double Magic=10000;
extern int MaxOpenOrders=10;

so..

if (b<=MaxLong)
{trade
}
if (s<=MaxShort)
{trade
}

But the EA is still sending out the max buy, and the max sell. Instead of counting how many orders there are of each and limiting itself to the MaxLong and Short. I know there must be something wrong with the code but I cant see it.


PHP Code:
 for (int cnt total cnt >=cnt-- )
           {
            
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
               
             if (
OrderMagicNumber()==Magic)
                 {if(
OrderType()==OP_BUY)
                  {
                   
b++;     // add order to Long Quantity
                   
if(TP != 0)
                   {
                    if(
b!= 0)
                    {
                     if(
Bid >= ((OrderOpenPrice()+TP*Poin)+Spread))
                     {
                             
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // Long position closed.
                             
CMT=OrderCloseTime();
                             
b--; // Long Order closed. Remove one order from total Longs
                            
return(0);
                          }
                    }
                   }
                  }
                    
             if (
OrderMagicNumber()==Magic)
                  {if(
OrderType()==OP_SELL)
                  
s++; // Add one to Short order Quantity
                  
if (TP != 0)
                  {
                   if(
s!= 0)
                   {
                    if(
Ask <= ((OrderOpenPrice()-TP*Poin)+Spread))
                    {
                       
OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // Short position closed.
                         
CMT=OrderCloseTime();
                         
s--; // Short Order Closed. Remove one order from total shorts
                         
return(0);      
                        } 
                   }
                  }
                 } 
              } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1343 (permalink)  
Old 10-07-2008, 02:33 PM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 722
Kalenzo is on a distinguished road
Quote:
Originally Posted by cutzpr View Post
Well taking a look at that code, I conjured up this piece of code below. I am not sure if it coded properly. I set up

int MaxLong=5,MaxShort=5;
extern double Magic=10000;
extern int MaxOpenOrders=10;

so..

if (b<=MaxLong)
{trade
}
if (s<=MaxShort)
{trade
}

But the EA is still sending out the max buy, and the max sell. Instead of counting how many orders there are of each and limiting itself to the MaxLong and Short. I know there must be something wrong with the code but I cant see it.
Well i think you are complicating things too much. Try using few shorter parts of code instead of one big function. This should give you some hint:

Code:
int totalOrders(int type)
{
	int totalNumber = 0;
	for (int cnt = total ; cnt >=0 ; cnt-- )
	{
        OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
       if (OrderMagicNumber() == Magic && OrderType() == type) totalNumber++;
    }
	return(totalNumber);
}
AND HERE IS EXAMPLE HOW YOU CAN USE IT

Code:
int totalBuy = totalOrders(OP_BUY); 
int totalSell = totalOrders(OP_SELL);

if( (totalBuy + totalSell) <  MaxOpenOrders)/*TOTAL NUMBER OF ORDERS WASN'T REACHED*/
{
	if(totalBuy <= MaxLongOrders) 
	{
		//OPENING LONG IS PERMITED
	}
	if(totalSell <= MaxShortOrders) 
	{
		//OPENING SHORT IS PERMITED
	}	
}
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1344 (permalink)  
Old 10-07-2008, 06:39 PM
Junior Member
 
Join Date: Aug 2008
Posts: 4
willya is on a distinguished road
[ASK] Indicator "SilverTrend_Signal"

I'm a beginner in forex and mql4 programming. I have a indicator SilverTrend_Signal (i attach here) and
i want to make an EA from this indicator but i have a problem with this indicator, the signal can change
in the same bar, such as the uptrend signal arrow appear in the chart then can disappear and maybe
change to the downtrend signal arrow in the same bar. Can someone help me to solve this problem?
I use this indicator in M1 time period and EU.
Thankyou very much.
(I'm sorry, my english is not good enough)
Attached Files
File Type: mq4 SilverTrend_Signal.mq4 (2.7 KB, 9 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1345 (permalink)  
Old 10-07-2008, 10:55 PM
cutzpr's Avatar
Member
 
Join Date: Jan 2008
Posts: 60
cutzpr is on a distinguished road
My personal opinion is that you should stay away from using indicators that repaint for signals. Especially on the M1 chart. Signals will change too often. You are just asking for non-stable signals and trouble. Past history looks good cause its the past.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1346 (permalink)  
Old 10-08-2008, 03:01 AM
Senior Member
 
Join Date: Feb 2007
Posts: 986
FerruFx is on a distinguished road
Quote:
Originally Posted by willya View Post
I'm a beginner in forex and mql4 programming. I have a indicator SilverTrend_Signal (i attach here) and
i want to make an EA from this indicator but i have a problem with this indicator, the signal can change
in the same bar, such as the uptrend signal arrow appear in the chart then can disappear and maybe
change to the downtrend signal arrow in the same bar. Can someone help me to solve this problem?
I use this indicator in M1 time period and EU.
Thankyou very much.
(I'm sorry, my english is not good enough)
Not sure about how this one repaints but if it does ONLY on the current bar, then use the signal at bar (confirmed) close will be fine.

If it repaints more than the current bar, so you can forget to use its signal for an EA.

FerruFx
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1347 (permalink)  
Old 10-08-2008, 03:30 AM
cutzpr's Avatar
Member
 
Join Date: Jan 2008
Posts: 60
cutzpr is on a distinguished road
Thumbs up

Quote:
Originally Posted by Kalenzo View Post
Well i think you are complicating things too much. Try using few shorter parts of code instead of one big function. This should give you some hint:
Thank you for your help. I tried to add the code you said, but to tell you honestly I am lost. After I added the code, the EA is showing a slue of problems. I have been going through the syntax but but I am lost.

I also had a question about using functions inside the int start() function. Is that allowed? Isn't the vairables initialized within a function unable able to be seen by other functions?

So
int start()
{
function( int x)
{
// Do something
return(x)
}

// Do Something ... "Can x be called in the start() function?'

return0;
}

Ive attached my EA source. Your help is very much appreciated.
PHP Code:
//+------------------------------------------------------------------+
//|                                  CCCCCCCCIEA.mq4 aka 8xCIEA.mq4  | 
//|                                              By CuTzPR           |
//|------------------------------------------------------------------+
#property copyright "CuTzPR@Forex-TSD"

//---- input parameters
extern double Risk_Percent=10;
extern bool Turned_On=true;
extern bool Allow_Risk=false;
extern bool TimeFilter=false;
extern double FromHourTrade=0//Adjust for Broker GMT Time
extern double ToHourTrade=23;  //Adjust for Broker GMT Time
extern double TP=20;           // Take Profit Level
extern int MaxLong=5,MaxShort=5
extern int MaxOpenOrders=10;
extern double Magic=10000;     

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int start()
{
int ticket;
double Lots;
bool Canopen,BlockTrade;
double Poin// This variable was included to solve the problem where some brokers use 6 digit quotes instead of 5
static datetime timeprev// Portion of coded was added to alloy only one trade per bar.
datetime CMT//Close time of last trade
int total=OrdersTotal();
double Spread=Ask-Bid;


//This portion of code was added to only allow one trade per bar.
    
    
if(timeprev==Time[0])
    {
    return(
0); //only execute on new bar
    

    else if (
timeprev==0)
    {
    
timeprev=Time[0]; // do nothing if freshly added to chart
    
return(0);
    } 
    else 
    {
    
timeprev=Time[0];
    }
    
// End of alllow one trade per bar code

//*****Following code was added to control the Risk per trade.

        
if (Allow_Risk==true)
            
Lots=MathCeil(AccountFreeMargin() * Risk_Percent 10000) / 10;
            
        else 
Lots=0.1;
        
//End of Risk Code
            
//The following code was also included to solve the 6 digit broker quoting

        
if (Point == 0.00001Poin 0.0001//6 digits
        
else if (Point == 0.001Poin 0.01//3 digits (for Yen based pairs)
        
else Poin Point//Normal
        
//End Point Code

// Custom Functions
double cci=iCCI(NULL,PERIOD_M5,5,PRICE_TYPICAL,0);
double SATL=iCustom(NULL,PERIOD_H1,"$SATL",0,1);
// End of Custom Function 
     
//Start of total count of open Long and Short Orders.
       
   
int totalOrders (totalBuy)
    {
      
int totalNumber0;
         for (
int cnt total cnt >=cnt-- )
            {
            
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
            if (
OrderMagicNumber() == Magic && OrderType() == OP_BUY)
                
totalNumber++;
           }
       return (
totalNumber);
    }

   
int totalOrders (totalSell)
    {
       
int totalNumber 0;
         for (
int cnt total cnt >=cnt-- )
            {
            
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
            if (
OrderMagicNumber() == Magic && OrderType() == OP_SELL)
            
totalNumber++;
           }
      return(
totalNumber);
    }

int totalBuy totalOrders(totalBuy); 
int totalSell totalOrders(totalSell);
int EAopenOrders=totalBuy+totalSell;
//End of total Open Long and Short count code
     
// Time filter Code

if (TimeFilter==true)
    {
        if (!(
Hour() >= FromHourTrade && Hour() <= ToHourTrade && Minute() <=2))
            
BlockTrade=true;
        else 
BlockTrade=false;
    }
//End of time Filter code
     
     
// Are trades allowed to be opened?                                
  
if(EAopenOrders<=MaxOpenOrders && BlockTrade==false && Turned_On==true)
     
Canopen=true;
     
  else if(
EAopenOrders>MaxOpenOrders || BlockTrade==true || Turned_On==false)
     
Canopen=false;
// End of Allow code
    
         
//*****Trade Open Order Functions

   
if(Canopen==true)
        {
      if (
totalBuy<=MaxLong)
         {
          if (
cci>-100 && SATL<Ask)
              {
            
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"CCI0",Magic,0,Blue);
                if(
ticket>0)
              {
               if(
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                  Print(
"BUY order opened : ",OrderOpenPrice());
              }
                 else Print (
"Error opening BUY order : ",GetLastError());
               return (
0);
                }
          }
         
      else if (
totalSell<=MaxShort)
            {
            if (
cci<100 && SATL>Bid)
                {
              
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"CCI",Magic,0,Red);
                 if (
ticket>0)
                 {
                  if(
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                     Print (
"Sell order opened : ",OrderOpenPrice());
                 }
                else Print(
"Error opening SELL Order : ",GetLastError());
               return (
0);
                }
                }    
         }
// End of Trade Open Order Functions

//****Close Orders if they are profitable

   
for (int cnt total cnt >=cnt-- )
           {
            
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
               
             if (
OrderMagicNumber()==Magic)
               {
                if(
OrderType()==OP_BUY && TP != && totalBuy!= 0)
                  {
                   if(
Bid >= ((OrderOpenPrice()+TP*Poin)+Spread))
                    {
                            
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // Long position closed.
                            
CMT=OrderCloseTime();
                            return(
0);
                         }
                   }
                 }
                  
                    
             if (
OrderMagicNumber()==Magic)
              {
               if(
OrderType()==OP_SELL && TP != && totalSell!=)
                 {
                  if(
Ask <= ((OrderOpenPrice()-TP*Poin)+Spread))
                   {
                       
OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // Short position closed.
                         
CMT=OrderCloseTime();
                         return(
0);      
                       } 
                  }
                 }
              
              } 
// Close Profitable trades loop closed 
                     

    
}// End of Start function 
Your help is greatly appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1348 (permalink)  
Old 10-08-2008, 03:41 AM
cutzpr's Avatar
Member
 
Join Date: Jan 2008
Posts: 60
cutzpr is on a distinguished road
Quote:
Originally Posted by Limstylz View Post
Hi All,

I originally posted this as a new thread, but it was moved into another programming thread (I have no objections to its move BTW) and now seems to have got lost due to the amount of posters in that thread.

Perhaps someone here can help me?
Limstylz take a look at this Ask! thread page 39. I think there might be some information that might help you. Good luck
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1349 (permalink)  
Old 10-08-2008, 06:02 AM
Senior Member
 
Join Date: Aug 2008
Location: London
Posts: 138
Limstylz is on a distinguished road
Cheers buddy...

Quote:
Originally Posted by cutzpr View Post
Limstylz take a look at this Ask! thread page 39. I think there might be some information that might help you. Good luck

Thanks cutzpr, but I managed to sort it out already... bloody internet connection was down all day and I had to use my own brain cells for once

Anyway, to answer your question about the int start ()... This is your main body of the EA and is updated continuously, every tick (I think thats right).

Your code is a little discombobulating... can you explain where you are experiencing an issue? I might be able to help if you can break down the problems, although I'm really just only learning MQL4 myself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1350 (permalink)  
Old 10-10-2008, 01:26 AM
bakhul's Avatar
Junior Member
 
Join Date: Jun 2008
Posts: 20
bakhul is on a distinguished road
what`s wrong with this?

Could someone here help me,if i copy this indicator to my meta,i need more than 5 minutes just to open my meta.But when i deleted it,and i reopen my meta, it become normal again.
Attached Files
File Type: mq4 KG_PIVOT_8H.mq4 (4.0 KB, 10 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
forex, histogram, JMASlope, ToR 1.20, ZUP_v1.mq4


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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


All times are GMT. The time now is 01:26 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.