please check if code is correct i'm new to mql4

 
#define __STRATEGY_MAGIC 1525183756



//Inputs



//Declaration

double _Bollinger_Bands_up;

double _Bid;

bool _Compare;

bool _Open_Position;

double _Bollinger_Bands_lower_band;

double _Bid_2;

bool _Compare_2;

bool _Open_Position_2;



int start(){



   //Level 1

   _Bollinger_Bands_up = iBands(Symbol(),0,20,2,0,0,1,0);

   _Bid = Bid;

   _Bollinger_Bands_lower_band = iBands(Symbol(),0,20,2,0,0,2,0);

   _Bid_2 = Bid;



   //Level 2

   _Compare = _Bid >= _Bollinger_Bands_up;

   _Compare_2 = _Bid_2 <= _Bollinger_Bands_lower_band;



   //Level 3

   if(_Compare && !__isExist(0))_Open_Position = OrderSend(Symbol(),1,0.1,MarketInfo(Symbol(),MODE_BID),0,MarketInfo(Symbol(),MODE_BID)+MarketInfo(Symbol(),MODE_POINT)*100,MarketInfo(Symbol(),MODE_BID)-MarketInfo(Symbol(),MODE_POINT)*400,"",__STRATEGY_MAGIC + 0)>=0;

   if(_Compare_2 && !__isExist(0))_Open_Position_2 = OrderSend(Symbol(),0,0.1,MarketInfo(Symbol(),MODE_ASK),0,MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_POINT)*100,MarketInfo(Symbol(),MODE_ASK)+MarketInfo(Symbol(),MODE_POINT)*400,"",__STRATEGY_MAGIC + 0)>=0;

   return(0);

}



//Services

bool __selectOrderByMagic(int __magic){for(int __i=0;__i<OrdersTotal();__i++){if(OrderSelect(__i,SELECT_BY_POS,MODE_TRADES)&&OrderMagicNumber()==__STRATEGY_MAGIC+__magic)return(true);}return(false);}

bool __isExist(int __magic){return(__selectOrderByMagic(__magic));} 

Hello to everyone.

 I have question, could you just check the code above is it correct? I'm new to coding in mql4. I wanted to write a simple ea based on bolinger bands. To write code i used an ea builder form strategy tune. After running back test on my mt4 i have no results( I receive message order send error130). It looks like code is wrong or something else. Could you please check this code i've pasted above is it correctly written?

Thank you in advance for any answer.

 
Thank you   :-)
 
RaptorUK:
Thank you   :-)

you welcome :-), didn't know this src function.
 
pawelc:

Hello to everyone.

 I have question, could you just check the code above is it correct? I'm new to coding in mql4. I wanted to write a simple ea based on bolinger bands. To write code i used an ea builder form strategy tune. After running back test on my mt4 i have no results( I receive message order send error130). It looks like code is wrong or something else. Could you please check this code i've pasted above is it correctly written?

Thank you in advance for any answer.

The code is bad written and hard to read but I dont see why it should produce error 130 (and it does not for me. Tested on EURUSD)

What is your plan for preventing the EA from immediately open a new order if one order was closed by TakeProfit?
Why do you assign true/false to _Open_Position but do nothing with it?
What is the reason for assigning Bid to variables?
Why not using Bid and Ask in the OrderSend() function?

My recommendation is to start here and not to use anymore any EA builder.

btw. If you are intressted in the test result: The EA wiped out a 10000$ account in less than 2 years (EURUSD, H1, from 2010.01.01)

edit: Anyone, does the tester care about ECN broker? I dont know because I have never tried it. If so, you cannot send SL and TP with OrderSend() if your broker is an ECN broker

 
kronin:


edit: Anyone, does the tester care about ECN broker? I dont know because I have never tried it. If so, you cannot send SL and TP with OrderSend() if your broker is an ECN broker

The Strategy Tester does not simulate an ECN type Broker.  
 
RaptorUK:
The Strategy Tester does not simulate an ECN type Broker.

Thank you, I should have seen that or any of the other suggestions... sorry.

So I don't know why the code produces an error 130 for pawelc 

 
kronin:

Thank you, I should have seen that or any of the other suggestions... sorry.

So I don't know why the code produces an error 130 for pawelc 

Perhaps it wasn't in the ST when the error 130 was produced . . .  I don't see anything obvious either that would cause an error 130 in  the ST unless the instrument has an extremely large StopLevel
 

Hi Guys.

 Thanks for answers. Error code I solved somehow, but don't know how. I was trying to set up correctly ST and TP and it started working. Thanks for confirmation regarding code anyway it is not properly written. This are my beginnings with writing EA. I just had some idea I wanted to test, but this EA isn't the one.

 "What is your plan for preventing the EA from immediately open a new order if one order was closed by TakeProfit? " - Saying truly I don't want my EA to be prevented against opening new trade even tough it reaches TP or SL. If EA reach TP / SL and new position will be open after it accordingly to build in condition it is ok. Generally I want EA to trade all the time if the build in conditions are met. I accept loss. If at the end It will have profitable ratio above 1.0 or equal to it is ok.  

"Why do you assign true/false to _Open_Position but do nothing with it?" - this one I'm trying to figure out.

 "What is the reason for assigning Bid to variables?" - don't ask me yet, I'm using online automatic builder and so far have to trust it. Till I want learn the coding in MQL.

"Why not using Bid and Ask in the OrderSend() function?" - exactly why not? :-).  

I know that this EA I have sent is not ok, but thank you for testing it :-). However I just build one other that on 1H and 30 min and 15 min data is profitable around 4%-7% (results include cost of trading) annually. However I have checked it on two MT4 platforms from two different providers and results were weird. Profitability differs too much among two different providers. Maybe it is because of data they deliver. 

I'll definitively have to go through this book ( I wish it was an easy read :-) ) and learn it properly.

Thank you very much for help. 

 
pawelc:

Hi Guys.

 Thanks for answers. Error code I solved somehow, but don't know how. I was trying to set up correctly ST and TP and it started working. Thanks for confirmation regarding code anyway it is not properly written. This are my beginnings with writing EA. I just had some idea I wanted to test, but this EA isn't the one.

 "What is your plan for preventing the EA from immediately open a new order if one order was closed by TakeProfit? " - Saying truly I don't want my EA to be prevented against opening new trade even tough it reaches TP or SL. If EA reach TP / SL and new position will be open after it accordingly to build in condition it is ok. Generally I want EA to trade all the time if the build in conditions are met. I accept loss. If at the end It will have profitable ratio above 1.0 or equal to it is ok.   

The code above does open a new order on the next tick if the previous order hit TP and the condition is still met.
Nobody would do that, it only makes the broker happy because you pay again the spread and again the commission (if there is any).

 
kronin:

The code above does open a new order on the next tick if the previous order hit TP and the condition is still met.
Nobody would do that, it only makes the broker happy because you pay again the spread and again the commission (if there is any).


However, I want my ea to trade continuously. I don't know what others do or not. I'm not interested in scalping. I'd like EA to focus more on catching longer moves (150-140 pips TP with sl 70 pips) then some 20 - 40 or 5 or 2 pips. Therefore If I succeed in creating ea that will be able through long period generating annual rate of return around 4%-6% I would be very happy. What about cost (spread) I think it is normal (the tighter the better, but for majors spread up to 2 pips or 2,5 pips I'm able to accept), this is a part of a game. If you are trying outsmart (send off market price or manipulate the price) the broker, you will definitively be re quoted or will receive slippage which might be not exactly favorable for you. The only thing I should be worried are swap points and profitability of an ea in longer term.  
 
RaptorUK:
The
RaptorUK:
The Strategy Tester does not simulate an ECN type Broker.  


Strategy Tester does not simulate an ECN type Bro

Apologize to place here

Could you please help me how we could use EA,s that are introduced in online library?

Best Regards


Reason: