//+------------------------------------------------------------------+
//| Proba.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
extern double Lots = 0.1;
extern double distance = 10;
extern double StopLoss = 1;
extern double TakeProfit = 10;
int init()
{
if(Digits == 3 || Digits == 5)
{
distance*=10;
StopLoss*=10;
TakeProfit*=10;
}
return(0);
}
int start()
{
double close;
double open;
double SLsell;
double TPsell;
double SLbye;
double TPbye;
close = iClose(NULL,0,1);
open = iOpen(NULL,0,1);
SLsell = Bid+StopLoss*Point;
TPsell = Bid-TakeProfit*Point;
SLbye = Ask-StopLoss*Point;
TPbye = Ask+TakeProfit*Point;
close = NormalizeDouble (close,Digits);
open = NormalizeDouble (open,Digits);
SLsell = NormalizeDouble (SLsell,Digits);
TPsell = NormalizeDouble (TPsell,Digits);
SLbye = NormalizeDouble (SLbye,Digits);
TPbye = NormalizeDouble (TPbye,Digits);
if(open > close)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,0,SLsell,TPsell,0,0,0,Red);
}
else
OrderSend(Symbol(),OP_BUY,Lots,Ask,0,SLbye,TPbye,0,0,0,Green);
return(0);
}
- [Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2.
- Invalid stop driving me nuts
- [Archive!] I will write any expert or indicator for free.
slavispoon: Why it doesn't work
Play videoPlease edit your post.
For large amounts of code, attach it.
- "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
extern double TakeProfit = 10; ... int init(){ if(Digits == 3 || Digits == 5){ distance*=10; ...
Each time you change timeframes or pairs, the EA goes through a deinit/init cycle. So your externals become 10, 100, 1000, 10000 ....OrderSend(Symbol(),OP_SELL,Lots,Bid,0,SLsell,TPsell,0,0,0,Red);
Check your return codes (OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
With your default stoploss being 1 pip
SLsell = Bid+StopLoss*Point;
as a sell is closed at Ask, you are most likely trying to open orders where the current Ask is above the SL
Thanks, for the answer. I find a missing key. The code is right, but i was trying to start it with to close Stop Lost level. It is my first code ever on any programmer language.
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