# Why it doesn't work

19

//+------------------------------------------------------------------+
//|                                                        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;

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

return(0);
}
15543

slavispoon: Why it doesn't work
1.  Play video Please edit your post. For large amounts of code, attach it.

2. "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.
3. ```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 ....
4. ```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
Moderator
10561

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

19

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.