Can anyone point me why my EA generates an error 130 which is invalid stop loss for this particular trade (and every other shorts i'm trying to OrderSend)
Here is the screenshot of my trade:
http://img231.imageshack.us/my.php?image=60364059ls0.png
Here is code for EA:
//+------------------------------------------------------------------+//| GoldenFifties.mq4 |//| mjollnir / beebo |//| ircforex.com |//+------------------------------------------------------------------+#propertycopyright"mjollnir (monsieur.burns [AT] toutatis dot be) / beebo"#propertylink"ircforex.com"#defineLOT_SIZE1// Paramsexterndoublepips_delta;
externdoublesl;
externdoubletp;
// Own vars// Dateintcur_day;
// Quotesdoubleprev_day_low;
doubleprev_day_high;
doubleprev_day_average;
doublecur_day_low;
doublecur_day_high;
staticintorder_id=0;
staticintticket;
staticboolis_in_trade=false;
staticboolis_first_day=true;
intinit(){return(0);
}intdeinit(){return(0);
}intstart(){inti, j;
intlimit, counted_bars=IndicatorCounted();
// Don't recalc previous barsif(counted_bars>0)counted_bars--;
limit=Bars-counted_bars;
// Discard sundays!if(DayOfWeek()==0){return(0);
}// Is this a new day?if(Day()!=cur_day){// Close current trade if there is oneclose_trade();
// Yes, lets update prev_day varsupdate_prev_day();
// Reset cur varsreset_cur_day();
}// Continue withupdate_cur_day();
// Trading allowed?if(OrdersTotal()==0){// Check if we downcross 50% fib of yesterday.is_long_entry();
// Check for upcrossis_short_entry();
}return(0);
}voidupdate_prev_day(){prev_day_low=cur_day_low;
prev_day_high=cur_day_high;
prev_day_average=prev_day_low+(prev_day_high-prev_day_low)/2;
// Round price to remove trailing numbers from average calcprev_day_average-=MathMod(prev_day_average, Point);
Print("Prev day ("+GetYesterdayTime()+") values: Low@"+prev_day_low+" High@"+prev_day_high+" Avg@"+prev_day_average);
}voidreset_cur_day(){cur_day=Day();
cur_day_low=Bid;
cur_day_high=Bid;
}voidupdate_cur_day(){cur_day_low=MathMin(Low[0], cur_day_low);
cur_day_high=MathMax(High[0], cur_day_high);
}stringGetCurTime(){stringstr;
str=TimeToStr(TimeCurrent(), TIME_DATE);
str=str+""+TimeToStr(TimeCurrent(), TIME_SECONDS);
return(str);
}stringGetYesterdayTime(){stringstr;
str=TimeToStr(TimeCurrent()-86400, TIME_DATE);
str=str+""+TimeToStr(TimeCurrent()-86400, TIME_SECONDS);
return(str);
}voidis_long_entry(){if(Close[0]<prev_day_average && Close[1]>prev_day_average){// Yes, we enter long.doublebuy_price=prev_day_average-(pips_delta)*Point;
//buy_price=Ask+pips_delta*Point; only good for live// Calc sl and tpdoublestop_loss=buy_price-sl*Point;
doubletake_profit=buy_price+tp*Point;
Print("bp: "+buy_price+" sl: "+stop_loss+" tp: "+take_profit+ " point: "+Point);
ticket=OrderSend(Symbol(),OP_BUYLIMIT,LOT_SIZE,buy_price,3,stop_loss,take_profit,"GoldenFifties order #"+order_id,16984,0,Green);
if(ticket<0){Print("OrderSend failed with error #",GetLastError());
return(0);
}is_in_trade=true;
order_id++;
}}voidis_short_entry(){if(Close[0]>prev_day_average && Close[1]<prev_day_average){// Yes, we enter short.Print("Let's short");
doublesell_price=prev_day_average+(pips_delta)*Point;
// Calc sl and tpdoublestop_loss=sell_price+sl*Point;
doubletake_profit=sell_price-tp*Point;
Print("sp: "+sell_price+" sl: "+stop_loss+" tp: "+take_profit+ " point: "+Point);
intticket=OrderSend(Symbol(),OP_SELLLIMIT,0.1,sell_price,3,stop_loss,take_profit,"GoldenFifties order #"+order_id,16984,0,Green);
if(ticket<0){Print("OrderSend failed with error #",GetLastError());
return(0);
}is_in_trade=true;
order_id++;
}}voidclose_trade(){boolresult;
if(OrdersTotal()!=0){Print("EOD: closing trade");
result=OrderClose(ticket,LOT_SIZE,Ask,3,Red);
if(result==false){Print("OrderClose() error: "+GetLastError());
}}}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Here is the screenshot of my trade:
http://img231.imageshack.us/my.php?image=60364059ls0.png
Here is code for EA: