Bar shifting and iLow/iLowest only work on full hours? (10pm, 11pm ...) - page 2

 
The Problem is, I think that I can't code for "the future". Does it work?
 

Hey Guys,

Sorry again... But this time I have no idea... - I want to make a "particial close". How does it works?

This is my solution - Open the Trade:

OrderSend(NULL, OP_BUY, lots, 0, 100, lowestPrice, 0, NULL, 1, 0, clrGreen);

 

Particial close: - DOESN'T WORK!

OrderClose(2, tvk, 0, 100, clrRed);

 

How can I fix it? 

 
FrazeColder: How can I fix it? 
  1. Perhaps you should read the manual. OrderClose - Trade Functions - MQL4 Reference
    Documentation
    Your code
    bool  OrderClose(
       int    ticket,     // ticket
       double lots,       // volume
       double price,      // close price
       int    slippage,   // slippage
       color  arrow_color // color
       );
    OrderClose(
       2,      // Hard coding a ticket number?
       tvk,    // How many lots are those? Is it a multiple of lot step, and between min and max?
       0,      // Is that a good market price? Select the order and use OrderClosePrice()
       100,    // Not adjusting for 4/5 digit brokers.
       clrRed
    );
  2. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
 
FrazeColder: Sorry again... But this time I have no idea... - I want to make a "particial close". How does it works? How can I fix it? 

In Portuguese we have a saying - "Puxa pela cabeça" which loosely translates to "pull on the head (cranium)". It means that one should try to figure things out for ourselves instead of constantly running to someone else for the answers. In this case, you are getting into the habit of posting here every-time you run into some difficulty. You will not be able to learn and understand things if you keep doing that. Coding requires you to apply logic, and in order for you to develop that, you have to practice it - not get the answers from others.

Just like when a weightlifter has to go to the gym and develop his muscles in order to lift those weights; he can't simply ask others to lift it for him, because then he will never develop his muscles. He may get some tips and assistance from others, but ultimately, he is the is one that has to do the lifting. Sometimes, he may hire a couch or mentor (hire, being the operative word), but even then, he is still the one doing the heavy lifting.

The same principle applies here! In order for you to develop your "logic" muscles and your coding skills, you have to do it yourself. So, read the documentation and experiment with the examples they give. Then apply it to your own code and when you run into trouble, print and look at the error codes and do the research. If need be, use the other tools at your disposal, such as the debugger! If you are however unable or unwilling to do that, then I suggest you head on over to the Freelance section and hire someone (either to couch you or to code for you).

Please note that this is my personal opinion and does not in any way reflect a general consensus on what other users here may believe.

 

Thank you for your answer guys! - I already fixed one problem. 
I'm opening a order with the ticket number 1 but was closing it with the ticket number 2 - but I have still the problem!

 

1. Yeah, hard coded ticket number, because this EA is just opening ONE order!
2. "TVK" is the amount of lots I wanna close. For example, I'm opening a Order with lots (e.g. lots = 1.00) and I wanna close the Order with a particial close by 0.7 Lots. Then my TVK is 0.7!
3. I'm going to change that! - Should I also change it for the OrderSend function?
4. What do you mean with "Not adjusting for 4/5 digit brokers"? - I'm ignoring the slippage. If I'm going to open a Order manuell in the MeatTrader 4, I'm also ignoring it/I'm not going to type in the slippage!


@FMIC: Thank you! - I'm sharing your opinon! - The difficult thing for me is just the Order functions... Everything else is just coding like in Java or something else... But I don't even get the MQL Documentation... 

 
FrazeColder: 1. Yeah, hard coded ticket number, because this EA is just opening ONE order!

You must NEVER EVER, hard-code ticket numbers because they are set by the broker and can be ANY number. I don't even know where you got "1" and "2" from (unless you got that in the Strategy Tester).

To use Ticket numbers you either save the one returned by OrderSend() to use later, or you loop through the Order History to get them. Never assume what the Ticket number will be.

 

Ok, I'm getting this error by hard coded ticket numbers: "2016.09.05 17:14:46.313 Tester EURUSDmicro,M5: unknown ticket 1 for OrderClose function".

I know changed it to: - Testing now, if it's working :)

ticketNr = OrderSend(Symbol(), OP_BUY, lots, 0, 100, lowestPrice, 0, NULL, 0, 0, clrGreen);

OrderClose(tickerNr, tvk, 0, 100, clrRed); 

 

And what do you mean with the other questions @WHRoeder? 

 
FrazeColder:
ticketNr = OrderSend(Symbol(), OP_BUY, lots, 0, 100, lowestPrice, 0, NULL, 0, 0, clrGreen);

OrderClose(tickerNr, tvk, 0, 100, clrRed); 

Both your OrderSend() and OrderClose() are suffering from invalid Open/Close prices. You cannot use "0" for and opening price on OrderSend() nor as the closing price of OrderClose().

Please read the documentation again: Requirements and Limitations in Making Trades

  • BUY Orders should open at the Ask price and close at the Bid price.
  • SELL Order should open at the Bid Price and close at the Ask price.

Please note that the Stop-Loss and Take-Price is at the same price conditions as the Close price. Again, please read the documentation thoroughly. Also read the following post: https://www.mql5.com/en/forum/159983

Also important, you are not assigning a proper magic number. "0" is used for manual trades, which will make your EA clash with manual orders. So do it properly, Use a unique magic number, set as an external variable, in your calls to Trade functions.

NB! Do yourself a favour and look at some of the example EA's provided by MetaQuotes, such as "MACD Sample.mq4" and "Moving Average.mq4" as well as the many, many examples of EA's in the CodeBase.

 

So you mean, I should use OrderOpenPrice() for OrderSend() and OrderClosePrice()for OrderClose()?

But why? - Where is the difference?  - e.g.:

ticketNr = OrderSend(Symbol(), OP_BUY, lots, OrderOpenPrice(), 100, lowestPrice, 0, NULL, 0, 0, clrGreen);

OrderClose(tickerNr, tvk, OrderClosePrice(), 100, clrRed); 


Magic Number: So you mean somehting like this? (I nerver understood Magic Numbers... - I already read the documentation 5 times I think... Magic Numbers are so difficult...)

Would that be right? - (But the documentation says: int      magic=0            // magic number - https://docs.mql4.com/trading/ordersend)
So I thought I also can use 0...

static int magicNr = 45634;

ticketNr = OrderSend(Symbol(), OP_BUY, lots, OrderOpenPrice(), 100, lowestPrice, 0, NULL, magicNr, 0, clrGreen);

OrderClose(magicNr, tvk, OrderClosePrice(), 100, clrRed); 

 

And my last question for today is. How can I get the price between Bid and Ask? - Is it "PRICE_MEDIAN"?

 
FrazeColder:

So you mean, I should use OrderOpenPrice() for OrderSend() and OrderClosePrice()for OrderClose()?

Magic Number: So you mean somehting like this? (I nerver understood Magic Numbers... - I already read the documentation 5 times I think... Magic Numbers are so difficult...)

So I thought I also can use 0...

And my last question for today is. How can I get the price between Bid and Ask? - Is it "PRICE_MEDIAN"?

4 completely wrong statements, I think he's a troll.
Reason: