Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


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 (1) Thread Tools Display Modes
  #591 (permalink)  
Old 12-25-2007, 06:06 PM
MrM MrM is offline
Member
 
Join Date: Jul 2007
Posts: 75
MrM is on a distinguished road
quick coding question

How do you put a horizontal line on the screen at the average value (of all closing prices)? Is there a specific code for that?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #592 (permalink)  
Old 12-26-2007, 07:31 AM
Senior Member
 
Join Date: Jul 2007
Posts: 186
jjk2 is on a distinguished road
simple breakout EA

Code:
//+------------------------------------------------------------------+
//|                                                   SimpleBreakoutEA.mq4 |
//|                                                          |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "jjk2"
#property link      ""

//---- input parameters

extern int       ____TIME_RANGE____;
extern int       TimeRange = 1; // # of Hours to look back from TimeEnd. ex) if breakout is @ 22:00 GMT to 23:00 GMT. Total TimeRange to lookback is 8 hrs.
extern int       TimeBegin = 22;
extern int       TimeEnd = 23;
extern int       CancelTime = 20; // ALL REMAINING ORDERS WILL BE CANCELED AT THIS INDICATED TIME.

extern int       ______FILTERS______;
extern int       TriggerFilter = 0;
extern bool      AllowBreakEven = True;

extern int       ______ORDERS______;
extern double    Lots = 0.1;
extern int       StopLoss = 50;
extern int       TakeProfit = 100;
extern int       Slippage = 2;
extern int       MagicNumber = 23423;

                                                                                          int init()
                                                                                            {
                                                                                             return(0);
                                                                                            }

                                                                                          int deinit()
                                                                                            {
                                                                                             return(0);
                                                                                            }

int start()
  {
           


// OPEN ORDERS @ HIGH/LOW from TIMEBEGIN to TimeEND

      if (Hour() >= TimeBegin-1 && Hour() >= TimeEnd)
         {
            int HH = iHighest(NULL, 0, MODE_HIGH,TimeRange,0);
            int LL = iLowest(NULL, 0, MODE_LOW,TimeRange,0);
         }
    
         double SL_High = Ask - (StopLoss * Point);
         double SL_Low = Bid + (StopLoss*Point);
         double TP_High = Ask + (TakeProfit*Point);
         double TP_Low =  Bid - (TakeProfit*Point);
    
   
    if ( Ask > HH + TriggerFilter) OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, SL_High, TP_High, "Breakout Buy", MagicNumber, NULL, Blue);
    if ( Bid < LL + TriggerFilter) OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, SL_Low, TP_Low, "Breakout Sell", MagicNumber, NULL, Red);
    





// MOVE SL @ BreakEven if allowed. MarketPrice distance Open Price > stop*point, then stop must equal to MarketPrice - Stop*point as new stoploss.
   
   int total = 0;
      
   if ( AllowBreakEven == True )
          
    {     
      
      for(total = OrdersTotal() - 1; total >= 0; total--)
         {
         OrderSelect(total, SELECT_BY_POS);
   
         if ( Bid - OrderOpenPrice() > SL_High*Point )
            OrderModify(OrderTicket(), OrderOpenPrice(), Bid - SL_High*Point, OrderTakeProfit(),0, CLR_NONE);
            
         if ( OrderOpenPrice() - Ask > SL_Low*Point )
            OrderModify(OrderTicket(), OrderOpenPrice(), Ask + SL_Low*Point , OrderTakeProfit(),0, CLR_NONE);
         
         }
   
     }
   
   return(0);
  }
  
//+------------------------------------------------------------------+

for some reason its not working....anyone know why ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #593 (permalink)  
Old 12-27-2007, 07:18 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 362
Beno is on a distinguished road
Gidday

I am looking for a piece of code/EA to restrict percentage of balance I can use lets say 10% of $10000 ( to keep things simple) so the ea can only use $1000 spread over a selected number of pairs each pair using mini or micro lots which ever pairs signal appears first uses some of the $1000. I think someone has done this already but I can’t seem to find it.


Cheers


Beno
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #594 (permalink)  
Old 12-28-2007, 06:44 PM
Junior Member
 
Join Date: Aug 2006
Posts: 13
ericlooi is on a distinguished road
How to turn indicator to EA?

Hi, may I know how to turn an indicator to EA?

Many indicators have the arrow sign when it comes to certain conditions and I would like to test them with EA.

I would like the EA to take the trade according to the arrow formed.

Can somebody help me? Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #595 (permalink)  
Old 12-28-2007, 07:01 PM
Administrator
 
Join Date: Sep 2005
Posts: 16,817
Blog Entries: 145
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
This one is according to arrow sign
http://www.forex-tsd.com/149633-post758.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #596 (permalink)  
Old 12-28-2007, 07:11 PM
Junior Member
 
Join Date: Aug 2006
Posts: 13
ericlooi is on a distinguished road
What about to turn the attached indicator to EA?

Can someone help? Thanks.

Last edited by ericlooi; 12-29-2007 at 03:24 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #597 (permalink)  
Old 12-29-2007, 06:44 AM
darkkiller's Avatar
Senior Member
 
Join Date: Jul 2007
Location: Malaysia
Posts: 207
darkkiller is on a distinguished road
Fill colour/opaque code

Hello there
anyone can teach me how to insert the code to make between 2 line of Envelops indicator fill with colour?
i allready try change SetIndexStyle(0,DRAW_LINE); to DRAW_HISTOGRAM...but its look weird

Code:
//+------------------------------------------------------------------+
//|                                                    Envelopes.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- indicator parameters
extern int MA_Period=14;
extern int MA_Shift=0;
extern int MA_Method=0;
extern int Applied_Price=0;
extern double Deviation=0.1;
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(0,MA_Shift);
   SetIndexShift(1,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=14;
   draw_begin=MA_Period-1;
//---- indicator short name
   IndicatorShortName("Env("+MA_Period+")");
   SetIndexLabel(0,"Env("+MA_Period+")Upper");
   SetIndexLabel(1,"Env("+MA_Period+")Lower");
   SetIndexDrawBegin(0,draw_begin);
   SetIndexDrawBegin(1,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   if(Deviation<0.1) Deviation=0.1;
   if(Deviation>100.0) Deviation=100.0;
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   if(Bars<=MA_Period) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   limit=Bars-ExtCountedBars;
//---- EnvelopesM counted in the buffers
   for(int i=0; i<limit; i++)
     { 
      ExtMapBuffer1[i] = (1+Deviation/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
      ExtMapBuffer2[i] = (1-Deviation/100)*iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i);
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
thanks!
Attached Files
File Type: mq4 Envelopes.mq4 (2.8 KB, 5 views)

Last edited by darkkiller; 12-29-2007 at 07:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #598 (permalink)  
Old 12-29-2007, 11:07 AM
Member
 
Join Date: Dec 2007
Location: Outside Stockholm
Posts: 32
ingvar_e is on a distinguished road
Code Structure

Hi,
I am new to Metatrader but very experienced in programming. I have created some sample Expert Advisors and some slightly complicated Indicators in MT. What is not clear is how to structure a rather complicated EA. I want the EA to call some "signal" functions to check for different setup condition.
How should I code these functions?
1. As "inline" functions in the EA
2. As "separate" Indicators that return a value instead of write on the screen?
3. some other "separate" function to call like calling iMA

If I choose alternative 1 can the inline function in the EA run thru the last 200 bars using Close[i] and call iMA?

Is alternative 2 OK?. When coding an indicator all bars "available" are processed which of course is not needed for the EA.

Alternative 3 to me seems like the logical choice but I am not sure how to structure it so it will work in backtesting and what I need to pass to it and what the function has access to by default, like for instance Close[i]

As an example of what I need to establish in the "signal" function is what is the current trend and when did it start. I have coded it in an indicator so I know how to do the actual code.

Grateful for any advice.

Ingvar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #599 (permalink)  
Old 12-29-2007, 07:01 PM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
Quote:
Originally Posted by ingvar_e View Post
Hi,
I am new to Metatrader but very experienced in programming. I have created some sample Expert Advisors and some slightly complicated Indicators in MT. What is not clear is how to structure a rather complicated EA. I want the EA to call some "signal" functions to check for different setup condition.
How should I code these functions?
1. As "inline" functions in the EA
2. As "separate" Indicators that return a value instead of write on the screen?
3. some other "separate" function to call like calling iMA

If I choose alternative 1 can the inline function in the EA run thru the last 200 bars using Close[i] and call iMA?

Is alternative 2 OK?. When coding an indicator all bars "available" are processed which of course is not needed for the EA.

Alternative 3 to me seems like the logical choice but I am not sure how to structure it so it will work in backtesting and what I need to pass to it and what the function has access to by default, like for instance Close[i]

As an example of what I need to establish in the "signal" function is what is the current trend and when did it start. I have coded it in an indicator so I know how to do the actual code.

Grateful for any advice.

Ingvar
You probably already know how to do this, so sorry if you do.

Moving average of current bar:
iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,0);

Moving average of 200 bars ago.
iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,200);

You can call the moving average from whatever bar you want form current to any bar in the past.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #600 (permalink)  
Old 12-29-2007, 08:19 PM
Member
 
Join Date: Dec 2007
Location: Outside Stockholm
Posts: 32
ingvar_e is on a distinguished road
Thanks Wolfe,

Yes I have seen that this is possible. That is not really my problem. One way to illustrate the problem is to try to use a library function as that is in manner that I am used to program. But in a library routine I dont seem to have access to things like Close[i]. Does that mean that I have to pass arrays for open, high, low and close fro the number of bars I need to the library routine? Seems a bit awkward since "everything" is available in a Indicator type of routine. So should I write 5 different indicator routines and call them from the EA routine? In that case can I just skip the screen writing in the Indicator routine and just return a value to the EA routine instead. Or do i have to return an array of values that match all the bars?

Struggling along
Ingvar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

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/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

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 12:14 PM.



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