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
Check the time functions in Metatrader help. then try something like this
if (TimeHour(Time[0]) TradeHourStop)
{
Comment("Trading suspended - outside trade hours");
return(false);
}
where TimeHourStart and stop are external variables set by you. The return(false); will exit the start function without further processing.
Good Luck,
Thanks for the quick reply, Tzuman.
Unfortunately, my MT4 programming is limited to an online EA builder at the moment.
This is just what I was looking for though!
How to code config of text color and font size of comments..
Hi everybody,
I am working on an EA and I am only a beginning programmer...
And I have a question in general how to code font size and text color of the comments and make it user configurable. What external variables do I have to create? And how do I program it?
I know how to use the comment function, for example like this:
if(TextOnScreen == true) Comment("This text appears on the screen ");
But how to program it so the user can change the fontsize of the text that appears on the screen and also how to change the text color of that text by changing the setting in the options of the EA?
Can anybody help me with a few lines of code? It is much appreciated.
Thank you very much.
Johan
Hi everybody,
I am working on an EA and I am only a beginning programmer...
And I have a question in general how to code font size and text color of the comments and make it user configurable. What external variables do I have to create? And how do I program it?
I know how to use the comment function, for example like this:
if(TextOnScreen == true) Comment("This text appears on the screen ");
But how to program it so the user can change the fontsize of the text that appears on the screen and also how to change the text color of that text by changing the setting in the options of the EA?
Can anybody help me with a few lines of code? It is much appreciated.
Thank you very much.
JohanYou need to use graphic objects like for example lables. How to do this - you can easy read in manual.
Hi everybody,
I am working on an EA and I am only a beginning programmer...
And I have a question in general how to code font size and text color of the comments and make it user configurable. What external variables do I have to create? And how do I program it?
I know how to use the comment function, for example like this:
if(TextOnScreen == true) Comment("This text appears on the screen ");
But how to program it so the user can change the fontsize of the text that appears on the screen and also how to change the text color of that text by changing the setting in the options of the EA?
Can anybody help me with a few lines of code? It is much appreciated.
Thank you very much.
JohanJohan,
Study the attached indicator.
Some of the code is for when a template is used.
I discovered that the hard way when text from one pair appeared on another pair chart because of the template.
If more lines of text are needed you should be able to figure that out.
If not post again and I will show an example with multiple lines.
Robert
why close order fail and how to limit order n.o.?
I am an newbie in MQL4,just tested an EA of myself,but it looks like could not close order,and it would open order in each bar till freemargin become 0,then it would force stop all orders. I donot know how to limit open order NO. Who could tell me ,TKS appreciating!
the code as follow:
//+------------------------------------------------------------------+
//| Moving Average.mq4 |
//| Copyright ?2005, MetaQuotes Software Corp. |
//| TeamWox Groupware / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#define MAGICMA 20110309
extern double Lots = 1;
extern double MaximumRisk = 0.02;
extern double DecreaseFactor = 10;
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(sells);
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/100.0,1);
Print(MarketInfo(Symbol(), MODE_LOTSIZE));
Print(MarketInfo(Symbol(), MODE_MINLOT));
Print(MarketInfo(Symbol(), MODE_LOTSTEP));
Print(MarketInfo(Symbol(), MODE_MAXLOT));
//---- calculate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
//this is an smart technical design,but losses stands lossing profit,not money may cause problems.
//modify them follow as:accountfreemargin()-orderprofit()
}
//---- return lot size
if(lot<1) lot=1;
return(lot);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double m1,m2,m3,m4,ticket1,ticket2;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
m1=iMA(NULL,0,21,0,MODE_SMA,PRICE_CLOSE,0);
m2=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,0);
m3=iMA(NULL,0,21,0,MODE_SMA,PRICE_CLOSE,1);
m4=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,1);
//---- sell conditions
if (m1<m3-0.0002)
{
ticket1=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+105*Point,0,"My order #1",MAGICMA,0,Red);
return;
}
if (m2<m4-0.0001)
{
ticket2=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+105*Point,0,"My order #2",MAGICMA,0,Yellow);
return;
}
//---- buy conditions
if ( m1>m3+0.0002)
{
ticket1=OrderSend(Symbol(),OP_BUY,1,Ask,5,Bid-105*Point,0,"My order #1",MAGICMA,0,Blue);
return;
}
if (m2>m4+0.0001)
{
ticket2=OrderSend(Symbol(),OP_BUY,1,Ask,5,Bid-105*Point,0,"My order #2",MAGICMA,0,Green);
return;
}
//----
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
double m1,m2,m3,m4;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
m1=iMA(NULL,0,21,0,MODE_SMA,PRICE_CLOSE,0);
m2=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,0);
m3=iMA(NULL,0,21,0,MODE_SMA,PRICE_CLOSE,1);
m4=iMA(NULL,0,55,0,MODE_SMA,PRICE_CLOSE,1);
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(m1<m3+0.0002)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
break;
}
if(m2<m4+0.0001)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
break;
}
}
if(OrderType()==OP_SELL)
{
if(m1>m3-0.0002)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Tan);
break;
}
if(m2<m4-0.0001)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Salmon);
break;
}
}
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<55 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
//+------------------------------------------------------------------+
Detect Windows Version
Does any one now a easy way to find out what version of windows MT4 is running using just a windows API call.
Can any one tell me how to make this work:
#import "kernel32.dll"
int GWINAPI GetVersionEA(_inout LPOSVERSIONINFO lpVersionInfo);
#import
GetVersionEx Function (Windows)
Thank You
Help Needed. Small Adjustment To My CCI Divergence EA
I have a CCI Divergence EA that uses a custom CCI Divergence Indicator in the Indicators folder in MT4 to determine when to place a trade.
What I want to do is use a custom Stochastics Divergence Indicator (which I have) instead.
I don't know how to change the EA code to direct it to the Stochastics Divergence Indicator in the indicators folder.
In the EA inputs I think I need to replace:
extern int CCI_Period = 10;
with
extern int Stoch_K = 5;
extern int Stoch_D = 3;
extern int Stoch_Slowing = 3;
In the main portion of the code I found the area that points to the custom CCI Divergence Indicator in the Indicators folder:
dUp = iCustom(Symbol(), 0, "CCI_Divergence_Indicator", "", CCI_Period, 9, "", false, false, false, 0, 2);
dDn = iCustom(Symbol(), 0, "CCI_Divergence_Indicator", "", CCI_Period, 9, "", false, false, false, 1, 2);
I know I have to change "CCI_Divergence_Indicator" to "Stochastics_Divergence_Indicator" which is the name of the custom stochastics divergence indicator in the Indicators folder. And I have to remove the CCI_Period and 9.
But I don't know how to add the Stoch_K, Stoch_D, and Stoch_Slowing to this portion of the code.
I tried changing it on my own, but then the EA won't open.
Does anyone know how to code this portion of the code so the stochastics divergence indicator can replace the cci divergence indicator?
I paid a programmer to create the ea, but he is very busy with other customers projects. So when it comes to minor changes/fixes he doesn't have time to do it for me - at least not right away. So that is why I am asking here.
The CCI Divergence Indicator has way too many false signals. The Stochastics Divergence Indicator is much better. That is why I want to do the switch.
Thanks in advance.
Help Please
I have a line of code that will alert me when the price of 1 bar(be it 1m 5m 189m)moves 200 pips IN 1 BAR. but I can't for the life of me figure out how to set it to alert ONLY specific direction. here it is..
if(High[0]-Low[0]>200*Point)PlaySound("Alert.wav"); //This works fine.
But I want to be able to distinguish between a 200 pip UP and 200 pip DOWN. I've read, asked in forums, been in chat rooms, and drove myself crazy for 3 days. im over it please for the love of god help me
if(High[0]-Low[0]>200*Point && Close[0]<Open[0])PlaySound("Down.wav");[/CODE]
Actually, you should rather look at highs and lows of two last bars and compare close to close, to ensure gaps are included, too:
[CODE]if(Mathmax(High[0],High[1])-Mathmin(Low[0],Low[1])>200*Point && Close[0]>Close[1])PlaySound("Up.wav");
if(Mathmax(High[0],High[1])-Mathmin(Low[0],Low[1])>200*Point && Close[0]<Close[1])PlaySound("Down.wav");