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
  #881 (permalink)  
Old 12-09-2007, 10:54 PM
Putz's Avatar
Junior Member
 
Join Date: Aug 2006
Posts: 24
Putz is on a distinguished road
Hi Michel,

Thank you very much for your prompt response and help.

I have deleted CurrentHigh and now understand a lot better. I have also defined CurrentLow at the top of the program and now it actually places orders.

I have also added a second order based on a larger retracement and that seems to work. Now I have to figure out how to stop it from creating a new order on every tick but I will work on that on my own for now as I will learn it better that way.

I'm sure I will be back here with more questions.

Thanks again.
Putz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #882 (permalink)  
Old 12-09-2007, 11:33 PM
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
Quote:
Originally Posted by Putz View Post
Hi Michel,

Thank you very much for your prompt response and help.

I have deleted CurrentHigh and now understand a lot better. I have also defined CurrentLow at the top of the program and now it actually places orders.

I have also added a second order based on a larger retracement and that seems to work. Now I have to figure out how to stop it from creating a new order on every tick but I will work on that on my own for now as I will learn it better that way.

I'm sure I will be back here with more questions.

Thanks again.

Putz
Don't forget to initialize CurrentLow with a big value (like 1000); if its' initialized with 0, you will never have a Bid < 0
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #883 (permalink)  
Old 12-10-2007, 04:43 AM
Junior Member
 
Join Date: Dec 2007
Location: Sabah, Malaysia
Posts: 2
bzbug is on a distinguished road
Which programming luaguage shall I learn?

Quote:
Originally Posted by codersguru View Post
Hi folks,

I've got a lot of private messages asking me for helping with some pieces of code.

Here you can post your questions related to MQL4, and I'll do my best to answer them.

Dear codersguru,
If I wish to learn to write MQL4 codes, which programming language shall I learn? Visual basic or C++? Thank your for your answer.
__________________
~NoVenture No Gain~
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #884 (permalink)  
Old 12-11-2007, 03:21 AM
Putz's Avatar
Junior Member
 
Join Date: Aug 2006
Posts: 24
Putz is on a distinguished road
More help please

Hello,

I'm back for more help. I've been reading and looking at many other EA's to try to figure it out but I still can't get it to work properly.

What I am trying to do is place two orders.
1) Sell 0.1 lot once price retraces by Ret1 (75 pips) with TP1 (75) and SL1 (150)
2) Sell 0.2 lot once price retraces by Ret2 (150 pips) with TP1 (75) and SL1 (75)

In the long term, I want to get a buy order like above to be placed based on direction of trend. I haven't yet determined which indicator I will use to determine trend yet but I will get there at some point.

The following is what I currently have. It seems to place the first order properly but the second one never gets triggered. Any help will be highly appreciated.

extern string Expert_Name = "Albatross v1";
extern int MagicNumber = 757575;
extern int Slippage = 3.0;

//---- input parameters
extern double TP1=75.0;
extern double TP2=75.0;
extern double Ret1=75.0;
extern double Ret2=150.0;
extern double SL1=150.0;
extern double SL2=75.0;
extern double Lots=0.1;
double CurrentLow=1000;
//double CurrentHigh=0;
int OpenOrders=0,cnt=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
//int init()
// {
//---- indicators

//----
// return(0);
// }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
// int deinit()
// {
//---- TODO: add your code here

//----
// return(0);

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
// int start()
// {
//---- TODO: add your code here

//----
// return(0);
// }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}

//+------------------------------------------------------------------+
//| Check Open Position Controls |
//+------------------------------------------------------------------+

int CheckOpenTrades()
{
int cnt;
int NumTrades; // Number of buy and sell trades in this symbol

NumTrades = 0;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;

if(OrderType() == OP_BUY ) NumTrades++;
if(OrderType() == OP_SELL ) NumTrades++;

}
return (NumTrades);
}

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
double TP;

if(Bars<100)
{
Print("bars less than 100");
return(0);
}

total = CheckOpenTrades();
if(total < 1)
{
if(Bid < CurrentLow) CurrentLow = Bid;
if(Bid >= CurrentLow+(Point*Ret1))
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+(SL1*Poi nt),Bid-(TP1*Point),"Albatross_v1",MagicNumber,0,Green);
}

if(total < 2)
{
if(Bid >= CurrentLow+(Point*Ret2))
OrderSend(Symbol(),OP_SELL,Lots*2,Bid+(Point*Ret2) ,3,Bid+(SL2*Point),Bid-(TP2*Point),"Albatross_v1",MagicNumber,0,Green);
return(0);
}
}

//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #885 (permalink)  
Old 12-13-2007, 03:37 AM
Senior Member
 
Join Date: Oct 2007
Posts: 198
Dave137 is on a distinguished road
Cool Sorry to Bother You With This Question

How do you create an object [Box] that is filled with a color??

Dave
<><<<
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #886 (permalink)  
Old 12-13-2007, 09:07 AM
syedks's Avatar
Junior Member
 
Join Date: Dec 2007
Location: London
Posts: 28
syedks is on a distinguished road
Hello All, I am a coder and been coding for long time in C++ but my knowledege of FX and MQL4 is very basic. I am going thorugh an EA that someone wrote and trying to understand the code...

can you please explain me in simple english that what is SHIFT parameter in iMA method?

double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

according to MT4 help, its "Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago)." - what is indicator buffer???

he's also doing the following...

PHP Code:
 
     int RealTime 
0;
     if( 
UseCompletedBars )
     {
      if(
timeprev==Time[0]){return(0);} timeprev Time[0];
      
RealTime 1;
     }
 
double MA11 iMA(NULL,0,MA1Periods,0,MA1MethodSelectedMA1ArraySelected,0+RealTime);
double MA12 iMA(NULL,0,MA1Periods,0,MA1MethodSelectedMA1ArraySelected,1+RealTime);
double MA21 iMA(NULL,0,MA2Periods,0,MA2MethodSelectedMA2ArraySelected,0+RealTime);
double MA22 iMA(NULL,0,MA2Periods,0,MA2MethodSelectedMA2ArraySelected,1+RealTime);
if( 
MA11 MA21 && MA12 MA22 ) { EnterLong True; }
if( 
MA11 MA21 && MA12 MA22 ) { EnterShort True; } 
what would that return? since i dont know the shift, i think thats why i cant get it ...


your answer will be highly appritiated.
please help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #887 (permalink)  
Old 12-13-2007, 09:18 AM
Junior Member
 
Join Date: Mar 2007
Posts: 5
pgtips is on a distinguished road
time calculation

Hi,

I've been working on a place pending order script but can't set the expiry time based on my entered time i.e if I want the order to expire at 15:30 I need to calculate distance between curr time and expiry time, this will give me a vlaue which is time to expire.

I've asked for the following values
extern int To_Hour = 15;
extern int To_Min = 30;

and used the following code to get the correct time distance but it doesn't work.
PHP Code:
//make time hr & min one value
int time_expire To_Hour 60 To_Min 60 60;
//get curr time as value
datetime curr TimeCurrent();
//subtract one from the other so 15:30 - 10:15 = 5hrs 15 mins to expire
expiry time_expire curr
I think I am right in understanding you can't just set time to expire as a time value but need to tell MQ4 number of hrs, mins and seconds to expire time.

Thanks in advance for help with this,

Kev
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #888 (permalink)  
Old 12-13-2007, 09:13 PM
Putz's Avatar
Junior Member
 
Join Date: Aug 2006
Posts: 24
Putz is on a distinguished road
Getting closer

I am getting closer with my coding but there is still a couple of errors.

After the first two orders are placed, it does not reset itselt to start over with a new CurrentLow and recalculate the retracements from there. Can someone help me figure out what I'm doing wrong. I have been trying a variety of things but none seem to make it work properly.

Attached is the cord:

Code:
//+------------------------------------------------------------------+
//|                                                  Bruno test1.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Putz Canada Corp"
#property link      "http://www.Putzfx,com"

extern string     Expert_Name    = "Albatross v1";
extern int        MagicNumber    = 757575;
extern int        Slippage       =     3.0;

//---- input parameters
extern double    TP1=75;
extern double    SL1=150;
extern double    Ret1=75;
extern double    TP2=75;
extern double    SL2=75;
extern double    Ret2=150;
extern double    Lots=0.1;
double CurrentLow=1000;
double CurrentHigh;
int  OpenOrders=0,cnt=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//int init()
//  {
//---- indicators

//----
//   return(0);
//  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
// int deinit()
//  {
//---- TODO: add your code here
   
//----
//   return(0);

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
// int start()
// {
//---- TODO: add your code here

//----
//   return(0);
//  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Check Open Position Controls                                     |
//+------------------------------------------------------------------+
  
int CheckOpenTrades()
{
   int cnt;
   int NumTrades;   // Number of buy and sell trades in this symbol
   
   NumTrades = 0;
   for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {
      OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
      if ( OrderSymbol() != Symbol()) continue;
      if ( OrderMagicNumber() != MagicNumber)  continue;
      
      if(OrderType() == OP_BUY )  NumTrades++;
      if(OrderType() == OP_SELL ) NumTrades++;
             
     }
     return (NumTrades);
  } 
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
 {   
   int cnt, ticket, total;
   double TP;
   
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
     total = CheckOpenTrades();
     if(Bid < CurrentLow) CurrentLow = Bid; 
     {
     if(total < 1) 
      {    
      if(Bid >= CurrentLow + (Point*Ret1))
         OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+(SL1*Point),Bid-(TP1*Point),"Albatross_v1",MagicNumber,0,Green);
         return(0);  
      }
      
      if(total < 2) 
      {        
      if(Bid >= CurrentLow+(Point*Ret2))
         OrderSend(Symbol(),OP_SELL,Lots*2,Bid,3,Bid+(SL2*Point),Bid-(TP2*Point),"Albatross_v1",MagicNumber,0,Green); 
         total = 0; 
         return(0);  
      } 
     }
  }

//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #889 (permalink)  
Old 12-13-2007, 11:56 PM
Senior Member
 
Join Date: Feb 2006
Posts: 513
Michel is on a distinguished road
if(Bid >= CurrentLow+(Point*Ret2))
OrderSend(Symbol(),OP_SELL,Lots*2,Bid,3,Bid+(SL2*P oint),Bid-(TP2*Point),"Albatross_v1",MagicNumber,0,Green);
total = 0;
return(0);

total = 0 doesn't have sense, try CurrentLow = 1000 instead. But it depends of what you want to do: may be you want to restart once both orders are closed, not immediately after the second one is open ?

Also, return(0) is not needed here, and you have to delete the empty ini(), deinit() and start() function : you cannot have two functions with the same name; you have mixed a template to build an indicator with one to build an EA.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #890 (permalink)  
Old 12-14-2007, 01:34 AM
granpa's Avatar
Junior Member
 
Join Date: Oct 2006
Posts: 24
granpa is on a distinguished road
2 EA in 1 code

Hi all, i'm now trying to build 2 ea in 1 code, that's mean, 2 different indicator, 2 rules for entry and exit..is there any sample?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram

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 On
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
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 11:46 AM


All times are GMT. The time now is 01:29 AM.



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