I checked it in real life, put it on the chart, it opened a position, then changed the time so that it would go beyond the expiration of the current symbol, the robot closed the position and opened it already on another address.
Everything is fine... but there is a disadvantage, it closes opens, but the chart on which the robot stands remains old, it would be good that with the opening of a position on a new futures and the instrument itself changed, so that it would not be necessary to move the robot to a new futures manually.
I added a line
//+------------------------------------------------------------------+ void CheckPos(string sym, string & TradeFutures, double lot) { if(SymbolInfoInteger(TradeFutures,SYMBOL_EXPIRATION_TIME)-TimeCurrent()<hours_before_expiration*60*60) { trade.PositionClose(TradeFutures); Sleep(3000); SymbolSelect(TradeFutures,false); TradeFutures=NextFutures(sym); } if(!PositionSelect(TradeFutures)) { if(lot>0) trade.Buy(lot,TradeFutures); if(lot<0) trade.Sell(-lot,TradeFutures); ChartSetSymbolPeriod(0,TradeFutures,PERIOD_CURRENT); Sleep(3000); } } //+------------------------------------------------------------------+
Everything is switching fine.
Thanks for the example.
I added a line
Everything switches fine.
Thanks for the example.
If the Expert Advisor trades several instruments, I think there is no point in switching the chart. You can put it on a glue.
This is just an example, it's up to the owner.
For real trading, I would throw out Sleeps and make a normal check of order execution. But I didn't want to overload the essence of the example, that's another topic.
If the Expert Advisor trades several instruments, I think there is no point in switching the chart. It is possible to put it on a glue.
This is just an example, it's up to the owner.
For real trading, I would throw out Sleeps and make a normal check of order execution. But I didn't want to overload the essence of the example, it's another topic.
I completely agree with you, but I need an algorithm that would close a position during the day, remove all limiters, the robot switched to another futures with a change of trading schedule and started a new trade with a clean sheet on the new futures.
As if I had done all this, but there was a problem that I can not figure out how to get around it
For example by adding
ChartSetSymbolPeriod(0,TradeFutures,PERIOD_CURRENT);
The chart changes, but if I try to click timeframes after the transition, for example M5 M30 etc. the robot returns on the next tick the TF on which it changed the futures chart.
I also planned to make a forced choice of the traded instrument in the settings, for example, we put oil, (according to your choice), but the robot is thrown to rts, when initialising the chart changes to oil.... I have done all this, but when switching to another futures at expiry there is a looping, the robot initialised when set to BR-5.18, then there is a change to 6.18 with a chart change and here on each tick starts changing from 6.18 to 5.18 and back....
I am not strong in this issue, I have not found examples of such work in the database, perhaps it is done by any checks, flags, etc. but I have not yet figured out how to do it. I would be grateful for a kick in the right direction, I think I'm not the only one... It would be great to see an extended example of V2, I think everyone will agree with me that this algorithm of transition and change of trading schedule should be embedded by default in every robot trading on FORTS, maybe the developers themselves would add it to their library.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Futures Portfolio Control Expiration:
A portfolio EA for the MOEX FORTS market.
The Expert Advisor demonstrates the use of functions from the Current Next Futures script, which enables automatic switch to a new futures before expiration. The EA opens a position of the appropriate volume on three instruments, which are specified in input parameters. Negative volume values are used for sell positions, positive ones are for buy positions. A few hours before the expiration of the futures (specified in hours_before_expiration), the EA closes the position and opens a new one on the new futures symbol.
Author: Sergey Chalyshev