
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
thanks Kalenzo,
I have tried with OP_BUYLIMIT but it doesn't work.
I will try with OP_BUYSTOP.
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?
simple breakout EA
//| 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
https://www.mql5.com/en/forum/173249/page51
What about to turn the attached indicator to EA?
Can someone help? Thanks.
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 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
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
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 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
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.
IngvarYou 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.