can anyody point me where is my code wrong? since it doesn't want to entry order by itself - page 2
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Also . . .
int tipe=OrderType();
You can only get OrderType for an existing order and only after you have used orderSelect . . see: https://docs.mql4.com/trading/OrderSelect and https://docs.mql4.com/trading/OrderType
Example: if OrdersTotal()==0 then OrderSend(). <--- Very bad example but allot for coding use this.
thanks ubzen, but for the example you've say, i still don't really get it, may i know why it can't be used? since my logic is i check first wether there is an open position or not using OrdersTotal(), if 0, then i'll open the position.
The reason it's a bad coding example is because there might be other EA's or Manual orders placed by you. The OrdersTotal() could be >0 even when this EA didn't place any order yet. So this EA will miss an opportunity to open an order because it thinks it already created an order. To solve this issue, you'll usually do a OrderSelect() Loop and Filter by Magic#.
You can send me a private message with your idea. I'll let you know if it's a basic idea or not. Unfortunately, I have a few projects on the top of my priority list right now. Therefore, I wouldn't be able to provide tutor level support nor code it out for you at this time.
thanks ubzen, i'm thinking if i've try to attach the EA, i won't make any manual orders. but seems like now i figured another problem of the OrdersTotal(), because if the EA open position today and still haven't hit any TP or SL until tommorow, the EA will not open any order tommorow which is not as what i want.
anyway, i've private message you, ubzen. take your time. inform me when you have some suggestion.
thanks
i see, if i add OrderSelect command above with index 0, to choose the first position, can it?
Please use this to post code . . . it makes it easier to read.
You don't seem to be adjusting your TP, SL or Slippage depending on your Broker being 4 or 5 digit, why not ?
You don't seem to be checking if your order was placed correctly and you don't seem to be looking at any errors generated if it wasn't, why not ?
You can't place a Market order (OP_BUY, OP_SELL) at a price above/below Ask and Bid
I agree
Also where is the OP_BUY, OP_SELL (Bid or Ask Price). Seems hargaskrg should be Bid,3,..... unless the Close[0] assumes Bid prices ?
OrderSend(NULL,OP_SELL,0.1,hargaskrg,3,hargaopen-60*Point,hargaopen+100*Point,"My order #2",16384,0,Green)
And NO SelectOrder for tipe = OrderType();
Note: order must be selected by OrderSelect() function
Just my 2 cents, but hey I'm NOOB, hope this helps
Yes, but does it make sense to do that ? look at your code . . . why select an order and on the basis of what type that order is place yet another order ? is that what you are trying to do ? if you do that I suspect that you will have many, many orders very quickly . . .
hi raptor, i see
actually i select an order to define weather it is a buy position or sell position. because my EA actually will only open one type of order each day. If first position is buy position opened, then the next order that will possibly be opened is only buy position (if fulfilled the condition). and vice versa for the sell position
oh, i forget another information, i'll limit to maks only 3 position per day.
this is the modification. please have a look if you're not busy.
I agree
Also where is the OP_BUY, OP_SELL (Bid or Ask Price). Seems hargaskrg should be Bid,3,..... unless the Close[0] assumes Bid prices ?
OrderSend(NULL,OP_SELL,0.1,hargaskrg,3,hargaopen-60*Point,hargaopen+100*Point,"My order #2",16384,0,Green)
And NO SelectOrder for tipe = OrderType();
Note: order must be selected by OrderSelect() function
Just my 2 cents, but hey I'm NOOB, hope this helps
hi agent86, thanks for your time. i'm still also a noob here. so, please feel free to comment.
i use Close[0] because from what i found out is if we use Close[0], it will return us the close price of the current bar. if the bar not yet close, it will return us the current price that is still moving. do i get it correct ?
from your comment, seems like i realize, i haven't figure out what price will Close[0] will return me, but i guess it will be Bid Price.
So, if i just change (for sell position)
OrderSend(NULL,OP_SELL,0.1,Bid,3,Bid-80*Point,Bid+80*Point,"My order #2",16384,0,Green)
and for buy position
OrderSend(NULL,OP_SELL,0.1,Ask,3,Ask+80*Point,Ask-80*Point,"My order #2",16384,0,Green)
how was it?
i've just add OrderSelect function at my EA, please have a look and i'm looking to hear from you
If it is earlier than 1200 then the nearest candle is bar zero. Code fails.
if it is Sunday 2200, (market just opened) nearest candle is still bar zero. Code fails.
if it is Sunday 2300, nearest candle is 2200 not 1200. Is this what you want.