Forex



Go Back   Forex Trading > Programming > MetaTrader
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
  #1661 (permalink)  
Old 03-19-2009, 09:07 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
Quote:
Originally Posted by jan100 View Post
thanks. i'll try that.

how is it possible to select the last closed order with the right magic number?
If you find it in the history list, this is a closed order, if in total list - opened yet.
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
  #1662 (permalink)  
Old 03-20-2009, 11:00 PM
darkkiller's Avatar
Senior Member
 
Join Date: Jul 2007
Location: Malaysia
Posts: 258
darkkiller is on a distinguished road
Ea code request: Close previous order when open new position

Hi, i would like to make request for code for when the new position is open,automatically the previous order will close.Mean i dont want to use take profit or trailling.

Example:
When order buy is open,previous order sell will close
When order sell is open,previous order buy will close

i found the code is OrderCloseBy() but i dont know exactly where to put this code

thanks
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
  #1663 (permalink)  
Old 03-21-2009, 06:56 AM
darkkiller's Avatar
Senior Member
 
Join Date: Jul 2007
Location: Malaysia
Posts: 258
darkkiller is on a distinguished road
Quote:
Originally Posted by darkkiller View Post
Hi, i would like to make request for code for when the new position is open,automatically the previous order will close.Mean i dont want to use take profit or trailling.

Example:
When order buy is open,previous order sell will close
When order sell is open,previous order buy will close

i found the code is OrderCloseBy() but i dont know exactly where to put this code

thanks


Problem solve

Quote:
put after OrderSend BUY
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position

}

put after OrderSend SELL
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position

}

Other code i get from ForexFactory thanks to(Fulltime247,magnumfreak)

Quote:
extern int MAGICTerminal=101;
extern double LOTSize=0.10;
extern string ORDERComment="Order Comment Text";

//TOTAL Count..
int btotal=0; int stotal=0; int ticket=0; double closelots=0; bool xbool;
for( int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
xbool=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && OrderMagicNumber()==MAGICTerminal && OrderSymbol()==Symbol()){btotal++; ticket=OrderTicket(); closelots=OrderLots();}
if(OrderType()==OP_SELL && OrderMagicNumber()==MAGICTerminal && OrderSymbol()==Symbol()){stotal++; ticket=OrderTicket(); closelots=OrderLots();}

}// END TOTAL count..


if(WHATEVER YOUR CONDITION FOR A BUY)
{

if(btotal>0){OrderClose(ticket,closelots,Bid,3,CLR _NONE);}
ticket=OrderSend(Symbol(),OP_BUY,LOTSize,Ask,3,0,0 ,ORDERComment,MAGICTerminal,0,Magenta);
}

if(WHATEVER YOUR CONDITION FOR A SELL)
{
if(stotal>0){OrderClose(ticket,closelots,Ask,3,CLR _NONE);}

ticket=OrderSend(Symbol(),OP_SELL,LOTSize,Bid,3,0, 0,ORDERComment,MAGICTerminal,0,Lime);
}
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
  #1664 (permalink)  
Old 03-23-2009, 06:47 AM
Junior Member
 
Join Date: Jan 2009
Posts: 3
Guilhermesalgado is on a distinguished road
Trying to figure this out PLEASE HELP!!

Trying to figure this out PLEASE HELP!!

This programmer charged me $170 to make me this EA! As for now I am doing it myself and believe to be almost there. Here is what I got so far and the message it’s givin’ me when I try to compile it:

//+------------------------------------------------------------------+
//| Salgado.mq4 |
//| salgadoguilherme@hotmail.com|
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link "salgadoguilherme@hotmail.com"
extern bool trade=true;
extern int barstocount=50;
extern double lots=0.01;
extern int slippage=3;
extern int magicnumber=816;

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

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(trade==true)
{
//M15
double M15_resistance=iCustom(NULL,PERIOD_M15,"!LinRegrBu f","true",barstocount,2,0);
double M15_resistance_p=iCustom(NULL,PERIOD_M15,"!LinRegr Buf","true",barstocount,2,barstocount-1);
double M15_line=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","tr ue",barstocount,0,0);
double M15_support=iCustom(NULL,PERIOD_M15,"!LinRegrBuf", "true",barstocount,1,0);
double slopeM15=((M15_resistance-M15_resistance_p)/barstocount)/Point;

//Alert(DoubleToStr(slopeM15,2);

Comment(
"\n","M15 Slope | ",slopeM15,

//SHORT ENTRY
if(slopeM15<0 && IsTradeAllowed()==true)
{
bool shortopen=false;
int ord_cnt1=OrdersTotal();
for (int start1=0;start1<ord_cnt1;start1++)
{
OrderSelect(start1, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==magicnumber && OrderType()==OP_SELL)
{shortopen=true;}
}
if(shortopen==false)
{
double M15High=iHigh(Symbol(),PERIOD_M15,0);
if(M15High>=M15_resistance)
}

//LONG ENTRY
if(slopeM15>0 && IsTradeAllowed()==true)
{
bool longopen=false;
int ord_cnt=OrdersTotal();
for (int start=0;start<ord_cnt;start++)
{
OrderSelect(start, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==magicnumber && OrderType()==OP_BUY)
{longopen=true;}
}
if(longopen==false)
{
double M15Low=iLow(Symbol(),PERIOD_M15,0);
if(M15Low<=M15_support)
}

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

Than I get messages:

mt4 says '\end_of_program' - ending bracket '}' expected

'\end_of_program' - unbalanced left parenthesis

Please, what am I suppose to do here?? Thanks in advance guys..
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
  #1665 (permalink)  
Old 03-23-2009, 11:59 AM
Junior Member
 
Join Date: Dec 2008
Posts: 6
darvasboxes is on a distinguished road
I am new to MT4.

I want to calculate the number of bars after shortMA has crossed longMA, anyone know how to code this function?

Thanks in advance!
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
  #1666 (permalink)  
Old 03-23-2009, 12:46 PM
Member
 
Join Date: Feb 2009
Posts: 86
mrwobbles is on a distinguished road
Quote:
Originally Posted by Guilhermesalgado View Post
Trying to figure this out PLEASE HELP!!

This programmer charged me $170 to make me this EA! As for now I am doing it myself and believe to be almost there. Here is what I got so far and the message it’s givin’ me when I try to compile it:

-Snip-

Than I get messages:

mt4 says '\end_of_program' - ending bracket '}' expected

'\end_of_program' - unbalanced left parenthesis

Please, what am I suppose to do here?? Thanks in advance guys..
Somewhere in the code the brackets are unbalanced. Sounds like somewhere a } and a ) are missing from the code. You'll need to look through and count how many open and closed brackets there are (+1 for open and -1 for closed) that should tell you how many are missing (say a +2 count mean two right brackets '}' or vice versa). If he indented properly you should be able to figure out where to put the right } in. Happy hunting

The
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
  #1667 (permalink)  
Old 03-23-2009, 07:33 PM
Member
 
Join Date: May 2008
Posts: 57
fireslayer26 is on a distinguished road
Still trying to add an audible alert to this indicator...... Can someone check the code for me as it is not working?

PHP Code:
//+------------------------------------------------------------------+
//| 
//| 
//+------------------------------------------------------------------+
#property  copyright "niva"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red

extern bool Email_Enabled false;
extern bool Alert_Enabled true;
//---- input parameters

int CountBars=10000;


//---- buffers
double uptrend[];
double downtrend[];
bool AlertSent,EmailSent;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   
IndicatorBuffers(2);
   
SetIndexStyle(0,DRAW_ARROW);
   
SetIndexArrow(0,217);
   
SetIndexStyle(1,DRAW_ARROW);
   
SetIndexArrow(1,218);
   
SetIndexBuffer(0,val1);
   
SetIndexBuffer(1,val2);
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2                                            |
//+------------------------------------------------------------------+
int start()
  {   
   if (
CountBars>=BarsCountBars=Bars;
   
   
int i,shift,counted_bars=IndicatorCounted();


int uptrenddowntrend;

for (
shift CountBarsshift>=0shift--) 

     if(
High[shift-1]>High[shift]&&Low[shift-1]>Low[shift]&&uptrend!=3){
        
uptrend uptrend+1;
        
downtrend=0;
      }else if(
High[shift-1]<High[shift]&&Low[shift-1]<Low[shift]&&downtrend!=3){
         
downtrend=downtrend+1;
         
uptrend=0;
      } 
      else{
         
uptrend=0;
         
downtrend=0;
      }
   if (
uptrend==3)
    {
    
val1[shift]=Low[shift];
    }
   if (
downtrend==3
   {
   
val2[shift]=High[shift];
   }
}
   return(
0);
  }
  
//----

   
if (Alert_Enabled && (uptrend[0] != || uptrend[0] !=0) && !AlertSent)
      {
      
Alert(Symbol() + "HiLow+3");
      
AlertSent=true;
      }
   if (
Email_Enabled && (downtrend[0] != || downtrend[0] !=0) && !EmailSent)
      {
      
SendMail(Symbol() + "HiLow+3","HiLow+3 indicator triggered");
      
EmailSent=true;
      }
      
   if(
downtrend[0] == && uptrend[0] == )
      {
      
EmailSent=false;
      
AlertSent=false;
      }
   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
  #1668 (permalink)  
Old 03-23-2009, 09:15 PM
Junior Member
 
Join Date: Jan 2009
Posts: 3
Guilhermesalgado is on a distinguished road
Thanks

Quote:
Originally Posted by mrwobbles View Post
Somewhere in the code the brackets are unbalanced. Sounds like somewhere a } and a ) are missing from the code. You'll need to look through and count how many open and closed brackets there are (+1 for open and -1 for closed) that should tell you how many are missing (say a +2 count mean two right brackets '}' or vice versa). If he indented properly you should be able to figure out where to put the right } in. Happy hunting

The
I managed to change some settings and finally I believe to be almost there! Now after the following coding it says:

'shortSL' - variable not defined
'longSL' - variable not defined

Here is what it looks like:

//+------------------------------------------------------------------+
//| Salgado.mq4 |
//| salgadoguilherme@hotmail.com|
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link "salgadoguilherme@hotmail.com"
extern bool trade=true;
extern int barstocount=50;
extern double lots=0.01;
extern int StopLoss =40;
extern int TakeProfit =10;
extern int slippage=3;
extern int magicnumber=816;

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

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(trade==true)
{
//M15
double M15_resistance=iCustom(NULL,PERIOD_M15,"!LinRegrBu f","true",barstocount,2,0);
double M15_resistance_p=iCustom(NULL,PERIOD_M15,"!LinRegr Buf","true",barstocount,2,barstocount-1);
double M15_line=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","tr ue",barstocount,0,0);
double M15_support=iCustom(NULL,PERIOD_M15,"!LinRegrBuf", "true",barstocount,1,0);
double slopeM15=((M15_resistance-M15_resistance_p)/barstocount)/Point;

//Alert(DoubleToStr(slopeM15,2);

Comment(
"\n","M15 Slope | ",slopeM15,

//SHORT ENTRY
if(slopeM15<0 && IsTradeAllowed()==true)
{
bool shortopen=false;
int ord_cnt1=OrdersTotal();
for (int start1=0;start1<ord_cnt1;start1++)
{
OrderSelect(start1, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==magicnumber && OrderType()==OP_SELL)
{shortopen=true;}
}
if(shortopen==false)
{
double M15High=iHigh(Symbol(),PERIOD_M15,0);
if(M15High>=M15_resistance)
int shortticket=OrderSend(Symbol(),OP_SELL,lots,Bid,sl ippage,Bid+shortSL,M15_line,DoubleToStr(slopeM15,2 );
if(shortticket<0)
{

//LONG ENTRY
if(slopeM15>0 && IsTradeAllowed()==true)
{
bool longopen=false;
int ord_cnt=OrdersTotal();
for (int start=0;start<ord_cnt;start++)
{
OrderSelect(start, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==magicnumber && OrderType()==OP_BUY)
{longopen=true;}
}
if(longopen==false)
{
double M15Low=iLow(Symbol(),PERIOD_M15,0);
if(M15Low<=M15_support)
int longticket=OrderSend(Symbol(),OP_BUY,lots,Ask,slip page,Ask-longSL,M15_line,DoubleToStr(slopeM15,2);
if(longticket<0)
{

//----
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
  #1669 (permalink)  
Old 03-24-2009, 01:48 AM
Junior Member
 
Join Date: Jun 2008
Posts: 19
Pied Piper is an unknown quantity at this point
Candle-type Indy

Hi,

I'm badly in need of MQL tutorials on how to code candle-type indicators such as the attached chart. Just the links to somewhere within or outside this forum will be fine. Thanks so much.

Piper.
Attached Images
File Type: gif ma candles.gif (14.6 KB, 74 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
  #1670 (permalink)  
Old 03-24-2009, 02:09 AM
Junior Member
 
Join Date: Dec 2008
Posts: 6
darvasboxes is on a distinguished road
Could someone tell me how to code the following;

Count the number of bars since a short-term MA has crossed a long-term MA.


Thank you!
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
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 11:52 AM.



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