I believe an absolutely essential feature we need when exporting our stategies to run in MT4 and MT5 is a parameter that sets a max spread and max slippage for opening a trade. If this limit is exceeded, the EA should not open a trade.
I feel very exposed not having this as part of exported EAs because broker spreads can suddenly widen a lot very rapidly during events (as per screenshot attached with 2 brokers compared side by side).
I really don't want to have trades open at 53.6 pips on AUD CAD for example!
I will have to add this myself to exported code in the mean time, which will be time consuming, but absolutely ESSENTIAL for managing my risk and would love to see this as part of SQX!
Anyone currently trading gold or incides will be getting murdered out there with current spreads without this failsafe!
int sqMaxEntrySlippage = 5; //Max tolerated entry slippage in pips. Zero means unlimited slippage
int sqMaxCloseSlippage = 0; //Max tolerated close slippage in pips. Zero means unlimited slippage
bool autoCorrectMaxSlippage = true; //If set to true, it will automatically adjust max slippage according to symbol digits (*10 for 3 and 5 digit symbols)
this is original settings in the MQL4 code, but its without extern, so you need to set it manually by editing the MQL code itself or template in the SQX
As a workaround: Instead of manually updating these values consider updating the MQL code generation template(s) \extend\Code\MetaTrader{4,5}\Main.tpl. (until next update overwriting it)
In any case check error handling logic for generated EA..
But I agree there should be a way to configure such parameters externally.
Also you may "try" with template which has a spread filter....
Long term, there is an internally risk class filters that need to be enabled by SQX developers.. No idea why it stay dormant code..
Attachment Capture1.png added
Attachment Capture2.png added
A new maximum spread trading option is ready. I will publish it during next week.
Just thinking. Is it good idea to export trade option's value automatically from strategy's config ?
and for me its nonsense to implement it to the SQX itself- because SQX is only a backtester, he cant see the future, not the real tick data from brokers we are getting
so for me SQX is finished by my needs - i have some major spread and slippage setting, where i put some everage value i can see on real account and thats it
spread and slippage control must be solved in the MQL code only
makes sense. spread filter (slippage will be additional trading option) is in place in both mql4/5 and effective in SQX itself (has to be there for consistency or 0=off).
Option 1)
so does it make sense to export spread size filter value as EA parameter or just set it to 0=off (manually adjust).
or..
Option 2)
spread size > 0 .. export this value with EA (as EA parameter)
spread size = 0 .. export this value with EA (0=off) (as EA parameter)
spread size < 0 .. export this value from test strategy spread size (as EA parameter). Tick data testing here is issue as spread is variable.
I know none of these is optimal...
suggestions welcome.
but what for slippage? - because slippage happen after open trade, not before and you can compute the slippage only if you are already in the trade - you can do only 1 or 2 things - close open trade immediately or move SL and TP values and correct their values to keep strategy logic untouched
but what to do with pending orders? because you will put pending order to the place and you know only the spread - what now? pending order will be placed when spread will have normal value, than widening occurs, what now? delete the pending and prevent the possible future trade? because final enter to the trade could be on times with normal spread
this taks has many answers and i am seeing it very easy - widening spread and slippages will be with us, we cant do anything about it...so i am trading no matter what spread is or what slippage i get...and i am counting on real account, that my results will be 50% of what i see in the backtest
This should not be hard to implement as the code runs on each and every tick.
As far as slippage goes, there's not much we can do beyond using a broker that allows slippage thresholds or renting a VPS or dedi as close as possible to the broker's servers and using a reputable broker.
It would still be good to include the slippage option with SQX MQL exports as this function does exist, but a warning message with a caveat should pop-up when exporting this code to MQL4 or MQL5 warning the user that not all brokers will honor this setting and this is NOT the responsibility of SQ devs.
could devteam describe what slippage control right now do in the code exactly?
(I am not from dev team :) In terms of exported EA (only MT).
MT4 - It's managed by good old OrderReliabler.There is little done than passing slippage to MT API and reporting. A little extra logic from library.
MT5 - Just a simple passthrough to MT API.. huh.
That'it
Attachment TO.png added
Attachment TO2.png added
Attachment SQExtension-TO-MaximumSpreadSlippage.sxp added
** USE THIS CODE IN COPY OF DEVELOPMENT ENVIRONMENT **
** PREVIEW **
** You have been warned ** Extension below is adding a new global trading options and new/retested strategies will require the supporting classes. will not open on SQX installation without this package. ** You have been warned **
How to test..
Make a copy of your SQX folder so you can delete it after.. Pls.
Import SXP file : Code editor -> Import/Export -> Import Extension
What does it do.
Spread filter is the maximum market spread in pips allowing to open a position. Filter in SQX simulation and exported to EA. Specify 0 for unlimited
if current spread > MaxSpread do not submit order..
Already sumitted orders are not affected. Already under platfrom control.
Maximum slippage -> Does nothing in SQX simulation (intentionally). Allows easy way to override EA internal variables sqMaxEntrySlippage and sqMaxCloseSlippage. SQX defaults assumed.
//+------------------------------------------------------------------+
// -- SQ Variables
// - add word "input" in front of the variable you want
// to make configurable
//+------------------------------------------------------------------+
int sqMaxEntrySlippage = 5; //zero means unlimited slippage
int sqMaxCloseSlippage = 0; //zero means unlimited slippage
-----------
^^^^
^^^ Override variable above without template changes
^^^
extern string smslpd = "----------- Maximum Slippage -----------";
extern int MaxEntrySlippage = 5; // Maximum entry slippage in pips
extern int MaxCloseSlippage = 0; // Maximum close slippage in pips
@keinc301: I had a rough journey as for my docs are thin but you can probably start from here (may not be exhaustive):
1) Some examples here: https://strategyquant.com/codebase
2) In built-in code editor in Snippets sub-dir are the java the implementation for all blocks/trade options/MM/colums/etc used in simulation engine. So look around in the examples. Code editor has auto-complete (might help). Some SQX API https://strategyquant.com/qa_api/ Not sure how accurate is this one
Export templates are in "code" sub-directory. For the record .tpl files are apache Freemaker .
3) I personally use Java IDE with debugger. it's doable but it's complete dark magic. But if you are skilled enough you should be able to setup a project and attach to java VM so you can debug public code. It's possible to debug internals (i do that) but even do not ask me on this..
4) For real plug-ins (like Builder,Retested,Custom workflow blocks).. Oh, do not even start. Square of difficulty of item 3). I have piloted my plugin, works fine but you should be paid to get through this pain.. seriously.
5) Persistence, do not give up. I could not get help for SQX team. Asked for that..
Once you get used to this complete mess is OK :)
Attachment SQExtension-TO-MaximumSpreadSlippage_v2.sxp added
@Insanity82007:
Slippage does nothing in SQX simulation. it's about MT export
Spread is simple filter. If on bar update current spread > MaxSpread do not allow creating new orders. Filters both SQX sim and MT EA
You can always update login in code edit, it's that simple. Check content of sxp file (it's zip)
Java Code:
@Override
public boolean OnBarUpdate(StrategyBase strategy) throws Exception {
if (MaximumSpread <= 0) return true;
String symbol = strategy.Symbol;
// Get current spread in pips
double spread = strategy.convertRealPriceToPips(
symbol,
Math.abs(strategy.MarketData.Chart(symbol).Ask() - strategy.MarketData.Chart(symbol).Bid())
);
// Allow trades only if spread is less or equal to maximum permitted
return (spread <= SQUtils.round(MaximumSpread, 1));
}
MQL Code:
virtual bool onBarUpdate() {
if(MaximumSpread <= 0) return true;
// Resolve main chart symbol
string symbol = correctSymbol("${doc.StrategyFile.Strategy.Datas.data[0].symbol}");
// Get current spread in pips
double spread = sqConvertToPips(symbol, sqGetAsk(symbol) - sqGetBid(symbol));
// Allow trades only if spread is less or equal to maximum permitted
if(spread > NormalizeDouble(MaximumSpread, 1)) return false;
return true;
}
Status changed from New to Refused
This is something out of its scope, you can hire a programmer to create a snippet for you to put to your strategies.
I purchased SQX to further diversify my strategies, as well as for the advanced strategy portfolio management features that SQX offers, and I look forward to exploring the software further over the coming months and years. It's my bad for not looking closer and finding this feature missing before I pulled the trigger. I plan on using the "Limit Time Range" feature as a work around to disallow trades during the swap, however, I'm in agreement with the other voters in this thread that adding spread control is not just a "nice to have", it's a "must have" for Forex. To me this seems like an easy feature to include in a software that aims (among other things) to keep it's users from having to "program things" or "hire a programmer".
I set spread < 1.5 pips on opening and closing every trade. It works well.
I also adjust the code to max slippage 0.3 pips and haven't noticed any issues with it.
I note the code includes adding the trade spread to the comments, but it doesn't work. This would be really useful to have working properly.