if(condition) return true else return false
same as
return condition;if(Close[3] < Open[3] && Close[2] > Open[2] && Close[1] > Open[1] && Close[2] < Close[1]) return (true); else return (false); }
simplified return Close[3] < Open[3] && Close[2] > Open[2] && Close[1] > Open[1] && Close[2] < Close[1];
double sl_long = Open[2]; double sl_short = Open[2]; int start(){ : ticket_long=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl_long,0, "My Order",16384,0,Green);
You never update sl_long except on load.
Hey Roeder, thank you very much for your help :-)
I changed the condition as you showed and it really makes the code much easier.
But what does the : mean?
And i´m not sure what you mean with update the sl_long...something like this(?):
for(int i=0;i<=total-1;i++) { if(OrdersTotal() > 0 && OrderSelect(i,SELECT_BY_POS) && OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderCloseTime()==0 ){ if(OrderStopLoss()< sl_long) { bool ordermodify = OrderModify(ticket_long,OrderOpenPrice(),sl_long,0,0,Green); if(ordermodify = false) Print("LONG Stoploss von Order",OrderTicket()," wurde NICHT nachgezogen",GetLastError()); else Print("LONG Stoploss von Order",OrderTicket()," wurde nachgezogen"); } } }
It´s a simple ordermodify function after the Ordersend function.... but i don´t get why the ea still opens no order..
Again thanks for your help and your patience with a newbie :)
Best regards
ttromberino
TTromberino:
But what does the : mean? And i´m not sure what you mean with update the sl_long...something like this(?): |
|
Thank you very much! It´s working now!
I´m sorry, but something seems still not working right:
When the EA opens an order he gives it a stoploss with more than 1000 points.
And he doesn´t open short orders with error 130. I think this is caused by the stoploss, but i don´t know how to fix it.
I have to add that i use this ea on renkocharts. But it should work on normal charts aswell.
The
funny thing is: In that moment when the price is going above the
opening price of the order he immediately puts the stoploss to the right
place.
And with short orders: He doesn´t even open them. But i have no idea why because the stoploss should be correct....i think.
The stoploss ist just: Open[2]; (see int start -> stoplossdefinition, or for() and then the ordermodifyfunction.
//+------------------------------------------------------------------+ //| rengomacd.mq4 | //| Korbinian Gabriel | //| - | //+------------------------------------------------------------------+ #property copyright "Korbinian Gabriel" #property link "-" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ extern double Lots = 0.2; extern string Start = "09:15"; // Start the EA extern string Ende = "17:00"; // Finish the EA int OldBar = 0; double macd_signal = iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); double macd_main = iMACD(Symbol(),0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); bool dc_long(){ return Close[3] < Open[3] && Close[2] > Open[2] && Close[1] > Open[1] && Close[2] < Close[1] && macd_signal < macd_main; } bool dc_short(){ return Close[3] > Open[3] && Close[2] < Open[2] && Close[1] < Open[1] && Close[2] > Close[1] && macd_signal > macd_main; } //--- condition 2: Docht muss 1,5 groß sein wie eine Kerze. bool sc_long(){ return Low[1] < Close[2] && Close[1] > Open[1]; //Achtung es fehlt condition, dass es wirklich 1,5 und nicht 1,3 sind. } bool sc_short(){ return High[1] > Close[2] && Close[1] < Open[1]; //Achtung es fehlt condition, dass es wirklich 1,5 und nicht 1,3 sind. } int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ int start() { //--- 1 Check per bar if(OldBar != Bars) { if (TimeCurrent() >= StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Start) && TimeCurrent() <= StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + Ende)) { int ticket_long; int ticket_short; int total = OrdersTotal(); //Stoplossdefinition: int sl_long = Open[2]; int sl_short = Open[2]; if(OrdersTotal() == 0 && dc_long() == true) { ticket_long=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,sl_long,0, "My Order",16384,0,Green); if(ticket_long < 0) { Print("OrderSend ",ticket_long," long with error #",GetLastError()); } else{ Print("OrderSend ",ticket_long," long successfully #" + string(ticket_long)); } } if(OrdersTotal() == 0 && dc_short() == true) { ticket_short=OrderSend(Symbol(),OP_SELL,Lots,Bid,10,sl_short,0, "My Order",16384,0,Red); if(ticket_short < 0) { Print("OrderSend ",ticket_short," short with error #",GetLastError()); } else{ Print("OrderSend ",ticket_short," short successfully #" + string(ticket_short)); } } for(int i=0;i<=total-1;i++) { if(OrdersTotal() > 0 && OrderSelect(i,SELECT_BY_POS) && OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderCloseTime()==0 ){ double sl_long = Open[2]; if(OrderStopLoss()< sl_long) { bool ordermodify = OrderModify(OrderTicket(),OrderOpenPrice(),sl_long,0,0,Green); if(ordermodify = false) Print("LONG Stoploss von Order",OrderTicket()," wurde NICHT nachgezogen",GetLastError()); else Print("LONG Stoploss von Order",OrderTicket()," wurde nachgezogen"); } } } for(int i=0;i<=total-1;i++) { if(OrdersTotal() > 0 && OrderSelect(i,SELECT_BY_POS) && OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderCloseTime()==0 ){ double sl_short = Close[2]; if(OrderStopLoss()< sl_short) { bool ordermodify = OrderModify(OrderTicket(),OrderOpenPrice(),sl_short,0,0,Green); if(ordermodify = false) Print("SHORT Stoploss von Order",OrderTicket()," wurde NICHT nachgezogen",GetLastError()); else Print("SHORT Stoploss von Order",OrderTicket()," wurde nachgezogen"); } } } } OldBar = Bars; } return(0); } //+------------------------------------------------------------------+
So normally this isn´t very complex at all and i don´t get why he puts the stoploss that far away.
Thanks for your help and patience.
Best regards
TTromberino
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
i know you may have read this like 100 times and this may get on your nerves now but i have a big problem with OrderSend Error 130.
I literally can do what i want and still get this error but maybe you have an idea what i am doing wrong.
Would be really happy if someone could tell me what could be false.
Sincerely
Ttromberino
PS: The ......... stands for some code like ordermodify etc.
extern double Lots = 0.2; extern string Start = "09:15"; // Start the EA extern string Ende = "17:00"; // Finish the EA int OldBar = 0;