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
Good afternoon.
I'm still new to programming, if anyone can give me a hint.
Question. We have one or more open orders. We know that they will close at a profit of $20.
We need to know at what price the orders will close at $20 profit.
We calculate the total volume of open lots, and then!
Please, advise how to do it.
Perhaps there is a ready function?
Thanks in advance.
Examples of the use of DistMarketAndPos().
Why would one need a function that determines how far the market is from the closest position? I see at least four basic options:
If you want a specific implementation of any of these options, write your requests here. I will fulfill all requests within the framework of what I have listed above.
ZZY-ZY. Attached is a template for experimenting with DistMarketAndPos() function.
HelloKimIV, the function is very good, it works, I flip it, it works too, but I can't connect the two halves.
int start()
{
if (DistMarketAndPos()>150)
{
OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,Ask+150*Point);
}
return(0);
}
int DistMarketAndPos(string sy="", int op=OP_BUY, int mn=-1) {
double d, p;
int i, k=OrdersTotal(), r=1000000;
if (sy=="" || sy=="0") sy=Symbol();
p=MarketInfo(sy, MODE_POINT);
if (p==0) if (StringFind(sy, "")<0) p=0.00001; else p=0.01;
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if ((OrderSymbol()==sy) && (op<0 || OrderType()==op)) {
if (mn<0 || OrderMagicNumber()==mn) {
if (OrderType()==OP_BUY) {
d=MathAbs(MarketInfo(sy, MODE_ASK)-OrderOpenPrice())/p;
if (r>d) r=NormalizeDouble(d, 0);
}
if (OrderType()==OP_SELL) {
d=MathAbs(OrderOpenPrice()-MarketInfo(sy, MODE_BID))/p;
if (r>d) r=NormalizeDouble(d, 0);
}
}
}
}
}
return (r);
}
New version of the Message() function.
About Alert and Print output directions (spaces 1 and 3) it should be noted, that they are able to output the message line by line. In other words, if there is a line break in the message text - control character "\n" then each line will be printed independently. Try the test script in the attachment, I think you will like it :-)
New version of the Message() function.
About Alert and Print output directions (spaces 1 and 3) it should be noted, that they are able to output the message line by line. That is, if there is a line break in the message text - control character "\n", then each line will be printed independently. Try the test script in the attachment, I think you will like it :-)
Have you added a check for stop levelling to your OpenPosition function?
No... what kind of check are you referring to? Well, let's say the stop and take failed the check, what to do? There are options:
no... what kind of check are you referring to? Well, let's say the stop and take didn't pass the check, what do you do? There are options:
New version of theOpenPosition() functionin the test script.
What's new?
1. When the error 130 Invalid Stops and the value of the NumberOfTry>1 variable is set, the function will try to adjust the StopLoss and TakeProfit price levels to the values of MODE_STOPLEVEL+MODE_SPREAD relative to Bid for OP_SELL and Ask for OP_BUY.
Note:
TheNumberOfTry global variable mustbe greater than 1 to trigger the correction of price levels. This is due to thefact that the first attempt to open a position reveals error 130 and corrects price levels, while the second and subsequent attempts to open a position with corrected levels.
Good afternoon.
Is it possible to complement the library of useful functions from KimIV with some simple functions like :
1.open price, selected by some criteria position (symbol, type, lot size, magic number). This price can be stored in global variables and used as a certain price level, from which the algorithm of the Expert Advisor can be built.
Returns a ticket selected according to some criteria of a position or an order (symbol, type, lot size, magic number). The ticket is an important identifier, it can be used everywhere and even as an existence flag.
The more such simple functions there are, the easier it will be to pick the best ones for you, without having to worry about making mistakes when modifying existing ones.
Thank you for your functions.