[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 10
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
Can you advise whether it is possible to determine programmatically the possibility of setting a stop loss/stake profit immediately at opening a position/pending order or afterwards?
Check the stop and profit levels beforehand.
The request identifiers used in the MarketInfo() function. Can be one of the following values:
I am just learning how to write an EA, like many of my first EAs on standard indicators, I have just written a new one, but now I have complicated my task. In general, how to make, that in the emergence of conditions opened a position and at its closure, let's take the same conditions when you save the new one did not open, and opened only when the opposite conditions, etc. Thanks!!!
there is a ready-made example in the help
Pre-check stop and profit setting levels .
There is no check in this list for certain account types. Here is a paragraph from the Trading Operations Regulations for NDD accounts:
3.3 If a position is opened through the Client Terminal using an Expert Advisor, the Client cannot designate Stop Loss and/or Take Profit Orders. If the Client wishes to place these orders, the Client may do so by modifying an existing position in accordance with clauses 5.16 - 5.22 and 9.13 - 9.16.
I am interested in whether this can be checked programmatically. As I understand it, no. You have to originally write into a program a function for opening positions / setting pending orders, taking into account the conditions that are set by the broker.There is no check in this list for certain account types. Here is a paragraph from the Trading Operations Regulations for NDD accounts:
I don't really understand the rules for setting orders, try to play with the demo and see what you can and can't do. As far as I understand nothing prevents you to programmatically set an order and then modify it. Right it's strange, unless you cut off the connection after opening a position leaving no stop .
I am interested in whether this can be checked programmatically. As I understand it, no. You have to initially write into the program a function to open positions/set pending orders, taking into account the conditions set by the broker.There is no check in this list for certain account types. Here is a paragraph from the Trading Operations Regulations for NDD accounts:
There is no problem at all. Even (if not for personal use, because you know on which accounts (trading conditions and with whom) to use it), but if you send the EA to order and the client has not yet decided on what accounts and where it will be used, even on account types with the possibility to set a take and stop immediately, then by default produce the EA with zero values of these levels when setting all types of orders, then with their modification (will work there and there), while, of course, nobody has canceled the check requirements and restrictions at p.
I do not quite understand the rules for setting orders, try to play with the demo, what you can and what you cannot. As far as I understand nothing prevents you to programmatically set an order and then modify it. Right it seems strange, unless you cut off the connection after opening a position leaving no stop .
))) No. You misunderstand me completely. I didn't write about "programmatically set", I wrote about programmatically defining. On some account types you can't immediately open a position and set stops/stops, which would be preferable/safe for me. On mql5, if I'm not mistaken, it seems to be possible to determine this. I would like to be able to determine this and, depending on the definition, choose which function to use.
There is no problem at all. Even (if not for personal use, because you know on which accounts (trading conditions and with whom) to use it), but if you make an EA to order and the client has not yet decided on what accounts and where he will use it, even on account types with the possibility to set a take and stop immediately, then you still make an EA with zero values of these levels by default when setting all types of orders, then with their modification (will work there and there), while, of course, nobody cancelled the check requirements and restrictions at p
Yes, there is no problem when there is a solution. You just need to use what you have and use it correctly.)
Roman. and ivandurak thank you so much for your replies, but for me it is still hard to figure out. I found a suggestion on another forum on how to do this, but so far I cannot apply it to my usual code
int BuyTrue, SellTrue;// define variables that will serve as these flags
....
//--- Condition for Buy
if (BuyTrue==0 && ... plus your other conditions) //open position condition
{
....
OrderSend(....); //function for opening an order
BuyTrue=1; // If BuyTrue=1, condition for position opening will not be fully satisfied
// consequently, at a repeated buy signal a trade will not be opened
SellTrue=0; // At SellTrue=0 the condition of the position opening will be fully satisfied
// hence the next trade will be Sell only
....
}
//--- Condition for Sell
if (SellTrue==0 && ... plus your other conditions) //open position condition
{
....
OrderSend(....); //function for opening an order
SellTrue=1; // If SellTrue=1, the condition for order opening will not be fully satisfied
// hence, at a second Sell signal a position will not be opened
BuyTrue=0; // At BuyTrue=0 the condition of position opening will be fully satisfied
// consequently, the next trade will be Buy only
....
}
My code for opening a position
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin();
return(0);
}
// check for long position (BUY)
if(MACD1<0 && MACD2<MACD1 && MACD2>MACD3 && MathAbs(MACD1)>(MACDOpenLevel*Point))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point, "macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL)
if(MACD1>0 && MACD2>MACD1 && MACD1>(MACDOpenLevel*Point))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point, "macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice())
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
Roman. and ivandurak thank you so much for your replies, but for me it is still hard to figure out. I found a suggestion on another forum on how to do this, but so far I cannot apply it to my usual code
int BuyTrue, SellTrue;// define variables which will serve as flags described above
....
//--- Condition for Buy
if (BuyTrue==0 && ... plus your other conditions) //open position condition
{
....
OrderSend(....); //function for opening an order
BuyTrue=1; // If BuyTrue=1, condition for position opening will not be fully satisfied
// consequently, at a repeated buy signal a trade will not be opened
SellTrue=0; // At SellTrue=0 the condition of the position opening will be fully satisfied
// hence the next trade will be Sell only
....
}
//--- Condition for Sell
if (SellTrue==0 && ... plus your other conditions) //open position condition
{
....
OrderSend(....); //function for opening an order
SellTrue=1; // If SellTrue=1, the condition for order opening will not be fully satisfied
// hence, at a second Sell signal a position will not be opened
BuyTrue=0; // At BuyTrue=0 the condition of position opening will be fully satisfied
// consequently, the next trade will be Buy only
....
}
My code for opening a deal.
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin();
return(0);
}
// check for long position (BUY)
if(MACD1<0 && MACD2<MACD1 && MACD2>MACD3 && MathAbs(MACD1)>(MACDOpenLevel*Point))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point, "macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL)
if(MACD1>0 && MACD2>MACD1 && MACD1>(MACDOpenLevel*Point))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point, "macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice())
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
Firstly, paste your code in the editor via Ctrl+Alt+M (or press SRC at the top of the menu), otherwise it's bad, what's clear - everything blends under one...:-))
Secondly, read the tutorial, in particular the information on the link that I recommended, below the code is its description and at the very end of the description is precisely described - how to once report a price above/below the MA (you will have an analogy with a single entry at a given trading condition - the use of flags and all), before you WORK your Wizard ... :-)))
P.S. or google search: How to properly insert code site:mql4.com