tol64: 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:
Constant .
Value
Description
MODE_LOW
1
Minimum daily price
MODE_HIGH
2
Maximum daily price
MODE_TIME
5
Time of last quote
MODE_BID
9
Last bid price received. For the current instrument it is stored in the predefined variable Bid
MODE_ASK
10
Last Ask price received. Stored in the predefined variable Ask for the current symbol
MODE_POINT
11
Point size in the Quote currency. Stored in the predefined variable Point for the current symbol
MODE_DIGITS
12
Number of digits after the decimal point in the instrument price. Stored in the predefined variable Digits for the current symbol
MODE_SPREAD
13
Spread in pips
MODE_STOPLEVEL
14
Minimum allowable level of Stop Loss/Stake Profit in pips
MODE_LOTSIZE
15
Contract size in the base currency of the instrument
MODE_TICKVALUE
16
Minimal change size of instrument price in the deposit currency
MODE_TICKSIZE
17
Minimum step of instrument price change in the quote currency
MODE_SWAPLONG
18
Swap size for long positions
MODE_SWAPSHORT
19
Swap size for short positions
MODE_STARTING
20
Calendar start date (usually used for futures)
MODE_EXPIRATION
21
Expiration date (normally used for futures)
MODE_TRADEALLOWED
22
Permission to trade the specified instrument
MODE_MINLOT
23
Minimum lot size
MODE_LOTSTEP
24
Step of lot size change
MODE_MAXLOT
25
Maximum lot size
MODE_SWAPTYPE
26
Swaps calculation method. 0 - in points; 1 - in instrument base currency; 2 - in percents; 3 - in margin currency.
Mode of margin calculation. 0 - Forex; 1 - CFD; 2 - Futures; 3 - Indices CFD
MODE_MARGININIT
29
Initial margin requirement for 1 lot
MODE_MARGINMAINTENANCE
30
Amount of margin requirement to support open positions per 1 lot
MODE_MARGINHEDGED
31
Margin charged on overlapped positions per 1 lot
MODE_MARGINREQUIRED
32
Amount of free funds, required to open 1 lot for buying
MODE_FREEZELEVEL
33
Level of freezing of orders in points. If the execution price is within the limits defined by the freeze level, the order cannot be modified, cancelled or closed.
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
int i,accTotal=OrdersHistoryTotal(); for(i=0;i<accTotal;i++) { //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error accessing historical database (",GetLastError(),")); break;
} We need to remember the time of order closing, compare the time of order closing with the time of closing in the previous iteration, if (the closing time is higher and the trade operation type is Buy or Sell), then we should remember the time of the current order and trade operation type // as a result, at the end of the cycle we know the order type that closed last } Something like this .
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 wondering if it is possible to check this programmatically. As I understand it, no. You have to initially write into the programme a function for opening positions/setting 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:
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.
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 .
There is no check in this list for certain account types. Here is a paragraph from the Trading Operations Regulations for NDD accounts:
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 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 immediatelyopen 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
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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
int i,accTotal=OrdersHistoryTotal(); for(i=0;i<accTotal;i++) { //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error accessing historical database (",GetLastError(),")); break; } We need to remember the time of order closing, compare the time of order closing with the time of closing in the previous iteration, if (the closing time is higher and the trade operation type is Buy or Sell), then we should remember the time of the current order and trade operation type // as a result, at the end of the cycle we know the order type that closed last } Something like this .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