Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent 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
  #831 (permalink)  
Old 10-28-2009, 01:33 PM
Junior Member
 
Join Date: Aug 2009
Posts: 2
nikola5555 is on a distinguished road
Problem with EA coding

Hello!

I`m newbie on forex market. I`m trying to build my own EA, and I succeed but i have few question about some features...

I trade on 5 different currency pairs: EURUSD, AUDUSD, USDCAD, USDJPY and NZDUSD...on H1 timeframe.

I want to implement some new features in EA, for example when EA open long trade on one currency pair and that trade goes to -50pips that my EA open another long trade on the same pair.

And, if possible to code that they both close when I have cumulative profit...maybe first one is -20 pips, but the second is +30 and to close immediatelly both (so I have +10 pips profit).

Could someone help me code it?
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
  #832 (permalink)  
Old 10-28-2009, 11:24 PM
Junior Member
 
Join Date: Oct 2009
Posts: 4
davidm is on a distinguished road
need help

hello

please someone can explain me why this code dosen't work correctly
instead drawing 8 MA on chart it draws only first two i.e 5 and 8 periods moving averages

#property indicator_chart_window // Indicator is drawn in the main window
#property indicator_buffers 8 // Number of buffers
#property indicator_color1 Lime // Color of the 1st line
#property indicator_color2 Blue // Color of the 2nd line
#property indicator_color3 Red
#property indicator_color4 SeaGreen
#property indicator_color5 MediumVioletRed
#property indicator_color6 DeepSkyBlue
#property indicator_color7 OrangeRed
#property indicator_color8 Orange

extern int Aver5=5; // number of bars for calculation
extern int Aver8=8; // number of bars for calculation
extern int Aver21=21; // number of bars for calculation
extern int Aver55=55; // number of bars for calculation
extern int Aver89=89; // number of bars for calculation
extern int Aver144=144; // number of bars for calculation
extern int Aver233=233; // number of bars for calculation
extern int Aver377=377; // number of bars for calculation

double Buf_5[],Buf_8[],
Buf_21[],Buf_55[],
Buf_89[],Buf_144[],
Buf_233[],Buf_377[]; // Declaring indicator arrays
//--------------------------------------------------------------------
int init() // Special function init()
{
//--------------------------------------------------------------------
SetIndexBuffer(0,Buf_5); // Assigning an array to a buffer
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(0,0);
//--------------------------------------------------------------------
SetIndexBuffer(1,Buf_8); // Assigning an array to a buffer
SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(1,0);
//--------------------------------------------------------------------
SetIndexBuffer(2,Buf_21); // Assigning an array to a buffer
SetIndexStyle (2,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(2,0);
//--------------------------------------------------------------------
SetIndexBuffer(3,Buf_55); // Assigning an array to a buffer
SetIndexStyle (3,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(3,0);
//--------------------------------------------------------------------
SetIndexBuffer(4,Buf_89); // Assigning an array to a buffer
SetIndexStyle (4,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(4,0);
//--------------------------------------------------------------------
SetIndexBuffer(5,Buf_144); // Assigning an array to a buffer
SetIndexStyle (5,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(5,0);
//--------------------------------------------------------------------
SetIndexBuffer(6,Buf_233); // Assigning an array to a buffer
SetIndexStyle (6,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(6,0);
//--------------------------------------------------------------------
SetIndexBuffer(7,Buf_377); // Assigning an array to a buffer
SetIndexStyle (7,DRAW_LINE,STYLE_SOLID,1);// Line style
SetIndexShift(7,0);
//--------------------------------------------------------------------
return;
}
//--------------------------------------------------------------------
int start()
{
ma(Aver5,Buf_5);
ma(Aver8,Buf_8);
ma(Aver21,Buf_21);
ma(Aver55,Buf_55);
ma(Aver89,Buf_89);
ma(Aver144,Buf_144);
ma(Aver233,Buf_233);
ma(Aver377,Buf_377);

return;
}
//--------------------------------------------------------------------

void ma(int& average,double& buffer[])
{
int n,i;
int Counted_bars;
double Sum;
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
Sum=0; // Nulling at loop beginning
for(n=i;n<=i+average-1;n++) // Loop of summing values
{
Sum=Sum + Close[n]; // Accumulating maximal values sum
}
buffer[i]=Sum/average; // Value of buffer on i bar
i--; // Calculating index of the next bar
}
}

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
  #833 (permalink)  
Old 10-30-2009, 03:59 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,218
matrixebiz is on a distinguished road
How to bypass/trick MODE_STOPLEVEL

Hello, I'm using a MoveStopOnce with SL slide and Trailing Stop technique and was wondering why it wasn't triggering until way past my set BE level.

I was using settings of for example when price gets to +21, move SL to BE+19 then Trail every 3 pips after that. The issue was that BEslide didn't trigger first SL move until price got to +28 pips then I realized my broker for USH/CHF has a MODE_STOPLEVEL of 8 so hence the reason why BE wasn't getting triggered at my set amount of +21 pips, it wasn't allowing the SL being moved so close to price.

Is there anyway around that? or is it just that the Broker will not allow SL within MODE_STOPLEVEL of price no matter what Technique I use?

I guess I could somehow monitor the SL moves internally within the EA and not physically move the SL then when price drops to where it would have hit SL if BE and Trail was actually working then close the trade at that point ??
I'm just not that good of coder

Any help would be greatly appreciated.

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
  #834 (permalink)  
Old 10-30-2009, 07:01 PM
Junior Member
 
Join Date: Oct 2009
Posts: 4
aw7866 is on a distinguished road
Global crosshairs

Hi all,

is there a way to create global crosshairs in mt4? have several different tf up and would like to scroll through one tf while seeing position on others. have looked on net..found .mq4 from forex fac but could not get to work.

thx
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
  #835 (permalink)  
Old 11-02-2009, 10:50 PM
Junior Member
 
Join Date: Oct 2009
Posts: 4
herbertn is on a distinguished road
How do I compare time?

Hello,

How can I compare the time in MQ4?

If for instance I wanted my EA to trade at either 7am, 1pm or 4pm only, how would I do this?

Any help would be appreciated.

Nick
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
  #836 (permalink)  
Old 11-02-2009, 10:59 PM
Senior Member
 
Join Date: Dec 2007
Posts: 494
Enforcer is on a distinguished road
PHP Code:
if(TimeHour(TimeCurrent()) == 7  ||
   
TimeHour(TimeCurrent()) == 13 ||
   
TimeHour(TimeCurrent()) == 16)
   {....
your code here...} 
TimeCurrent() return server time
TimeLocal() return local time (your PC time)
__________________
www.signalcopy.com - Most advanced tools for copy Metatrader signals.
Free MT4 account statistics - advanced stats and graphs for MT4 accounts
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
  #837 (permalink)  
Old 11-02-2009, 11:21 PM
Junior Member
 
Join Date: Oct 2009
Posts: 4
herbertn is on a distinguished road
perfect,

Many thanks,

Nick
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
  #838 (permalink)  
Old 11-04-2009, 04:41 AM
Junior Member
 
Join Date: Sep 2006
Posts: 5
apres is on a distinguished road
Indicator drawing problem

I have a problem with my simple indicator .


PHP Code:
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue      
#property indicator_color2 Orange      

extern int      EMA_Period 12;
extern int      shift 1;

double EMA[];
double Dynamic[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
SetIndexBuffer(0,EMA);
   
SetIndexStyle(0,DRAW_LINE);
   
SetIndexBuffer(1,Dynamic);
   
SetIndexStyle(1,DRAW_LINE);
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                                      |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                                              |
//+------------------------------------------------------------------+
int start()
  {
   
int ilimit;
   
int counted_bars IndicatorCounted();
   if (
counted_bars 0) return(-1);
   if (
counted_bars 0counted_bars--;
   
limit=Bars-counted_bars;
//----
 
for(limit>= 0i--)
 
EMA[i] = iMA(NULL,0,EMA_Period,shift,MODE_EMA,PRICE_CLOSE,i);
 
 for(
limit>= 0i--)
 
Dynamic[i] = EMA[i]+((Close[i]-EMA[i])/(Close[i]/EMA[i]));
 
//----
   
return(0);
  } 


It draws the EMA line OK, but draws only three bars of the dynamic line history.

I'm sure I've overlooked something silly, but I'm at a loss.
Any help would be appreciated.

Last edited by apres; 11-04-2009 at 04:46 AM.
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
  #839 (permalink)  
Old 11-05-2009, 04:43 AM
Junior Member
 
Join Date: Oct 2009
Posts: 2
mercswish is on a distinguished road
Question Limiting Open Orders for each instance of EA

I have coded an EA but I want to limit the amount of open orders it has in each instance it is running, for example, if the EA is running on the USDJPY and EURUSD, how can I keep it to having a maximum of 3 orders open for each pair. I tried using orderstotal() but that gives me all the open orders for the account, and I want to be able to trade manually around the EAs. Anyone have some pseudo-code or ideas about how to implement this?

-Merc
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
  #840 (permalink)  
Old 11-05-2009, 05:23 AM
Senior Member
 
Join Date: Mar 2006
Posts: 794
Maji is on a distinguished road
Use the following Subroutine. Of course you can add buy limit and sell limit to it.

Code:
int CountTrades(int Magic)
{
 int count=0;
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
  
  if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic)
   continue;
   
  if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)   
  if(OrderType()==OP_BUY || OrderType()==OP_SELL ||
     OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
   count++;
 }//for
 return(count);
}
Now you can call it in your main routine something as
Code:
    NumberOfActiveTrades = CountTrades(Magic);
Hope this helps.
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
automated close order, close, eas, forex, learn mql4, learn mql4 video, learning mql4, mini std lotsize risk, mql4 ima, mql4 learning, mql4 video, OrderCloseBy, profit, reach, secure profit function, T101_v1.11_orest_IBFXm.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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning Cycles For New Traders Dan7974 General Discussion 350 01-18-2008 07:04 PM
Learning to code for autotrading GoatT MetaTrader 8 01-10-2007 09:55 PM
Self learning expert mrtools Expert Advisors - Metatrader 4 32 10-22-2006 06:29 PM


All times are GMT. The time now is 10:55 AM.



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