Could it be that you calc. the buy-price from Bid while for buy you have to use Ask and therefore the order-price is too close or even smaller than Ask?:
if (BuyOrSell == buy) PriceOrPointsValue = Bid+PriceOrPointsValue*Point; ...
ionone: error 130 extern int StopLossPoints = 0; extern int TakeProfitPoints = 0; : OpenBuy = OrderSend(Symbol(), OP_BUYSTOP, Lots, p1, 3, PriceOrPointsValue - StopLossPoints * Point * 2 + spread, PriceOrPointsValue + TakeProfitPoints * Point + spread, "woohoo", 8675309, time + 3600 * 1, Green); OpenSell = OrderSend(Symbol(), OP_SELLSTOP, Lots, p2, 3, PriceOrPointsValue + StopLossPoints * Point - spread, PriceOrPointsValue - TakeProfitPoints * Point - spread, "woohooooo", 8675309, time + 3600 * 1, Green); |
|
HI
i'm trying to programm an EA that places orders at a certain time of the day and close it at another.
The EA works but i have error messages (OrderSend error 130 which means wrong stopLoss) but i cannot find where the error is.
Test for errors and report them and any associated variables . . . track down your error methodically.
What are Function return values ? How do I use them ?
wow thanks for your answers!
@gooly:
hmm that's good (i'm a real noobie so i didn't noticed that error), i tried that and i've got a new error. Now it doesn't close the buy. here is the log:
2014.10.27 18:25:48.026 EURUSD,H1: 306921 tick events (1145 bars, 307921 bar states) processed within 234 ms (total time 4618 ms) 2014.10.27 18:25:47.798 2014.10.17 01:00 Tester: #1 deleted due expiration 2014.10.27 18:25:47.797 2014.10.17 00:00 maxima88x_1 EURUSD,H1: open #1 buy stop 0.01 EURUSD at 1.28110 sl: 1.23117 tp: 1.33117 ok 2014.10.27 18:25:47.796 maxima88x_1 inputs: GMTOffset=-1; PriceOrPoints=0; PriceOrPointsValue=8; BuyOrSell=0; StopLossPoints=5000; TakeProfitPoints=5000; Lots=0.01; AutoLot=0; EquityRiskPercentage=0.0
@RaptorUK:
i already did that i was printing on the screen the sl values and trying to understand why some values were passing through and others wouldn't. And i couldn't find a pattern in these errors.
As i'm buying at a determined time, i suppose i don't need to use pending orders? i can use OP_BUY instead of OP_BUYSTOP? And when i do that, i end up with a "138" error that i get rid by augmenting the slippage from 3 to 10 (as i'm not scalping it's okay).
and everything works without errors.
Is it the right way to go?
thanks again.
Jeff.
"Is it the right way to go?"
It depends on your code and your strategy - I can't tell you anything so far.
But - it might be better not to continue trying and but look for an existing EA and open source code and copy its order management - google for trade management?
yes i still have a lot to learn.
The code i've got so far has parts from other people, i didn't code a lot (though i'm originally a C++/Java programmer)
so i finally updated the code and it's final, had to fix some bugs and there you go!
enum buysell { buy, sell }; enum pointsprice { points, price }; extern string g = "+++ Enter your CHART GMT offset +++"; extern string h = "+++ Will calculate GMT hour as ChartHour+GMTOffset +++"; extern int GMTOffset = 1; extern string q = "+++ Set points or price +++"; extern pointsprice PriceOrPoints = points; extern double PriceOrPointsValue = 10; extern buysell BuyOrSell = buy; extern string d = "+++ Set stop loss/take profit in points +++"; extern int StopLossPoints = 5000; extern int TakeProfitPoints = 5000; extern string j = "+++ Number of lots to open +++"; extern double Lots = 0.1; extern string z = "+++ Use automatic risk percentage lot adjustment +++"; extern bool AutoLot = false; extern double EquityRiskPercentage = 0.01; extern string w = "+++ Time Order/stop +++"; extern string OpenTime = "10:00:00"; extern string CloseTime = "23:30:00"; datetime prevTime; bool dayPassed = true; int OpenSell = -1; int OpenBuy = -1; int init() { //---- // //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { IndicatorDigits(Digits+2); datetime time = iTime(NULL,PERIOD_M1,0); int heuresOpen = StrToInteger(StringSubstr(OpenTime, 0, 2))+GMTOffset; int minutesOpen = StrToInteger(StringSubstr(OpenTime, 3, 2)); int secondesOpen = StrToInteger(StringSubstr(OpenTime, 6, 2)); if (heuresOpen < 0) heuresOpen = heuresOpen + 24; if (heuresOpen >= 24) heuresOpen = heuresOpen - 24; if (TimeDay(prevTime)< TimeDay(time)) { dayPassed = true; } if (dayPassed == true && OpenSell == -1 && OpenBuy == -1 && TimeHour(time) >= heuresOpen && TimeMinute(time) >= minutesOpen && TimeSeconds(time) >= secondesOpen) { RefreshRates(); if (PriceOrPoints == points) { if (BuyOrSell == buy) PriceOrPointsValue = Ask+PriceOrPointsValue*Point; else PriceOrPointsValue = Bid+PriceOrPointsValue*Point; } //calculate lots double spread = Ask-Bid; if (AutoLot && EquityRiskPercentage < 1 && EquityRiskPercentage > 0) { Lots = (AccountEquity()*EquityRiskPercentage)/StopLossPoints; } if (BuyOrSell == buy) { double p1 = PriceOrPointsValue+spread; p1 = int(p1 * 10000)/10000.; OpenBuy = OrderSend(Symbol(), OP_BUY, Lots, p1, 10, PriceOrPointsValue-StopLossPoints*Point+spread, PriceOrPointsValue+TakeProfitPoints*Point+spread, "woohoo", 8675309, time+3600*1, Green); } else { double p2 = PriceOrPointsValue-spread; p2 = int(p2 * 10000)/10000.; OpenSell = OrderSend(Symbol(), OP_SELL, Lots, p2, 10, PriceOrPointsValue+StopLossPoints*Point-spread, PriceOrPointsValue-TakeProfitPoints*Point-spread, "woohooooo", 8675309, time+3600*1, Green); } } int heuresClose = StrToInteger(StringSubstr(CloseTime, 0, 2))+GMTOffset; int minutesClose = StrToInteger(StringSubstr(CloseTime, 3, 2)); int secondesClose = StrToInteger(StringSubstr(CloseTime, 6, 2)); if (heuresClose < 0) heuresClose = heuresClose + 24; if (heuresClose >= 24) heuresClose = heuresClose - 24; int maxDuration = (heuresClose-heuresOpen)*3600 + (minutesClose - minutesOpen) * 60 + (secondesClose - secondesOpen); for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == 8675309 // my magic number && OrderSymbol() == Symbol() ){ // and period and symbol int duration = TimeCurrent() - OrderOpenTime(); if (duration >= maxDuration) { OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3*1); OpenSell = -1; OpenBuy = -1; dayPassed = false; } } prevTime = time; return(0); } //+------------------------------------------------------------------+
and i didn't find any already made code that would do what i need
the two i found are:
CAP Pending Order at Time
https://www.mql5.com/en/market/product/3095
and
Expert Pending Orders
https://www.mql5.com/en/market/product/4591
but i couldn't make it work with MT4 Alpari UK, and i'm not looking for pending orders anyway.
Jeff
@RaptorUK:
i already did that i was printing on the screen the sl values and trying to understand why some values were passing through and others wouldn't. And i couldn't find a pattern in these errors.
@deysmacro:
yes i could hire someoie dto do the job but it wouldn't be as customizable as doing it yourself, plus i'm a programmer so i might as well learn how to do it myself
@RaptorUK:
do i have to check for all these requirements each time i want to put a new order? in other EA i've watched, there wasn't these tests...
Jeff
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i'm trying to programm an EA that places orders at a certain time of the day and close it at another.
The EA works but i have error messages (OrderSend error 130 which means wrong stopLoss) but i cannot find where the error is. I've tried several stopLoss points to see if it came from that, but i couldn't make the error messages go away.
the weird thing is, apart from these error messages, the code works ok. But i'd rather like the code without errors.
I'm backtesting the code with Alapri UK.
thanks for any help
Jeff
and here is a typical log: