tatankaska: Hello, when testing your expert advisor in strategy tester on GOLD I always obtained prompts Failed to open position - Invalid stops - no positions were opened. What was wrong? It was written to avoid this type of error?
I'm afraid we need some code in order to help you. Most probable thing is that the error does exist in your code. Check that your stops are larger than minimal allowed distance and that you did not, by any chance, misplace buy and sell stops. Also make sure your broker does allow specifing stops at position opening - some of them require to add stops only to existing positions (so called "market execution").
marketeer: I'm afraid we need some code in order to help you. Most probable thing is that the error does exist in your code. Check that your stops are larger than minimal allowed distance and that you did not, by any chance, misplace buy and sell stops. Also make sure your broker does allow specifing stops at position opening - some of them require to add stops only to existing positions (so called "market execution").
Hi I tested only expert advisor attached to the article How to avoid errors when setting/modifying trade level, without any change (Positionpropertiesplus). Instatrader platform by Instaforex. The functions in this advisor are written so, that if i set wrong stops parameters they are set to lowest allowed. So normaly should i obtain no error prompt - that is true by forex pairs. But by GOLD in this platform I obtain by each attempt of positionpropertiesplus EA to open position with stops, the error prompt invalid stops and no position in strategy tester was open. Is that the case you mentioned - problem with instatrader platform and broker? In GOLD symbol properties is written instant execution.
Here is example of function for stoploss calculation from mentioned EA - I used the EA attached to the mentioned article without any change, i only used GOLD instead of forex pairs:
//+------------------------------------------------------------------+//| Calculating the Stop Loss value |//+------------------------------------------------------------------+double CalculateStopLoss(ENUM_ORDER_TYPE order_type)
{
//--- If Stop Loss is requiredif(StopLoss>0)
{
//--- For the calculated Stop Loss valuedouble sl=0.0;
//--- If you need to calculate the value for a BUY positionif(order_type==ORDER_TYPE_BUY)
{
// Calculate the level
sl=NormalizeDouble(sym_ask-CorrectValueBySymbolDigits(StopLoss*sym_point),sym_digits);
//--- Return the calculated value if it is lower than the lower limit of the Stops level// If the value is higher or equal, return the adjusted valuereturn(sl<sym_down_level ? sl : sym_down_level-sym_offset);
}
//--- If you need to calculate the value for a SELL positionif(order_type==ORDER_TYPE_SELL)
{
//--- Calculate the level
sl=NormalizeDouble(sym_bid+CorrectValueBySymbolDigits(StopLoss*sym_point),sym_digits);
//--- Return the calculated value if it is higher that the upper limit of the Stops level// If the value is lower or equal, return the adjusted valuereturn(sl>sym_up_level ? sl : sym_up_level+sym_offset);
}
}
//---return(0.0);
}
Hi I tested only expert advisor attached to the article How to avoid errors when setting/modifying trade level, without any change (Positionpropertiesplus). Instatrader platform by Instaforex. The functions in this advisor are written so, that if i set wrong stops parameters they are set to lowest allowed. So normaly should i obtain no error prompt - that is true by forex pairs. But by GOLD in this platform I obtain by each attempt of positionpropertiesplus EA to open position with stops, the error prompt invalid stops and no position in strategy tester was open. Is that the case you mentioned - problem with instatrader platform and broker? In GOLD symbol properties is written instant execution.
Here is example of function for stoploss calculation from mentioned EA - I used the EA attached to the mentioned article without any change, i only used GOLD instead of forex pairs:
Yes, that was the case. By GOLD in Instatrader the stops could be placed only after the opening of position. When position opened without stops and after opening modified, everything was OK. Thanks guys.
Once more to the calculation of stops (SL/TP) in attached EA - they are calculated correctly only by instruments where symbol point = symbol tick size. That is not the case by GOLD.
Stops must be in this case (by GOLD) corrected to valid symbol ticksize, otherwise you obtain error prompt - invalid stops .
So the error prompts by GOLD are not result of market execution. EA needs a bit correction in calculation of SL/TP, if you want to use it with GOLD.
What about closing a position? If there are conditions (signal) for closing positions in the Expert Advisor, how to do it, where can I see such examples?
Nauris: What about closing a position? If there are conditions (signal) for closing positions in the Expert Advisor, how to do it, where can I see such examples?
The CTrade class of the standard library is used in the article. It has the PositionClose method. You can use it.
//+------------------------------------------------------------------+//| Setting the info panel |//|------------------------------------------------------------------+void SetInfoPanel()
{
//--- Visualization or real time modesif(ShowInfoPanel && (IsVisualMode() || IsRealtime()))
{
// The remaining code of the SetInfoPanel() function// ...
}
}
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.
Hello, when testing your expert advisor in strategy tester on GOLD I always obtained prompts Failed to open position - Invalid stops - no positions were opened. What was wrong? It was written to avoid this type of error?
I'm afraid we need some code in order to help you. Most probable thing is that the error does exist in your code. Check that your stops are larger than minimal allowed distance and that you did not, by any chance, misplace buy and sell stops. Also make sure your broker does allow specifing stops at position opening - some of them require to add stops only to existing positions (so called "market execution").
Hi I tested only expert advisor attached to the article How to avoid errors when setting/modifying trade level, without any change (Positionpropertiesplus). Instatrader platform by Instaforex. The functions in this advisor are written so, that if i set wrong stops parameters they are set to lowest allowed. So normaly should i obtain no error prompt - that is true by forex pairs. But by GOLD in this platform I obtain by each attempt of positionpropertiesplus EA to open position with stops, the error prompt invalid stops and no position in strategy tester was open. Is that the case you mentioned - problem with instatrader platform and broker? In GOLD symbol properties is written instant execution.
Here is example of function for stoploss calculation from mentioned EA - I used the EA attached to the mentioned article without any change, i only used GOLD instead of forex pairs:
...
Forum on trading, automated trading systems and testing trading strategies
Hello,
Please use the SRC button when you post code. Thank you.
This time, I edited it for you.
Hi I tested only expert advisor attached to the article How to avoid errors when setting/modifying trade level, without any change (Positionpropertiesplus). Instatrader platform by Instaforex. The functions in this advisor are written so, that if i set wrong stops parameters they are set to lowest allowed. So normaly should i obtain no error prompt - that is true by forex pairs. But by GOLD in this platform I obtain by each attempt of positionpropertiesplus EA to open position with stops, the error prompt invalid stops and no position in strategy tester was open. Is that the case you mentioned - problem with instatrader platform and broker? In GOLD symbol properties is written instant execution.
Here is example of function for stoploss calculation from mentioned EA - I used the EA attached to the mentioned article without any change, i only used GOLD instead of forex pairs:
Once more to the calculation of stops (SL/TP) in attached EA - they are calculated correctly only by instruments where symbol point = symbol tick size. That is not the case by GOLD.
Stops must be in this case (by GOLD) corrected to valid symbol ticksize, otherwise you obtain error prompt - invalid stops .
So the error prompts by GOLD are not result of market execution. EA needs a bit correction in calculation of SL/TP, if you want to use it with GOLD.
What about closing a position? If there are conditions (signal) for closing positions in the Expert Advisor, how to do it, where can I see such examples?