| New signals service! | |
|
|||||||
| 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 |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
|||
|
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 ? |
|
|||
|
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. |
|
|||
|
This one is according to arrow sign
http://www.forex-tsd.com/149633-post758.html |
|
||||
|
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);
}
//+------------------------------------------------------------------+
Last edited by darkkiller; 12-29-2007 at 07:01 AM. |
|
|||
|
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 |
|
||||
|
Quote:
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. |
|
|||
|
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 |
![]() |
| Bookmarks |
| Tags |
| candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading |
| Thread Tools | |
| Display Modes | |
|
|
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 |