Before you read further let me be very clear: I do not recommend this type of trading. We all know how dangerous ALR can be if left on a single pair -- imagine what it can do on a basket of pairs.
So, why do I want to share this? This forum is all about collaboration of ideas and code. This solution i am about to share uses OOP concepts to neatly separate the logic in small and comprehensible components.
Briefly, there are three components:
1. A 'normal' basket EA. The idea is here that it uses some indicators (in this case the HULL MA and some stochastics) to initiate a trade -- this can be for any pair the basket EA is looking at.
2. A TradeMan-object. Once a trade is initiated by the basket EA, a TradeMan - object is assigned to this ticket number. It is the TradeMan's responsibility to manage the trade and open alternating BUYs and SELLs (the ALR-way) in order to finish off the ALR-sequence of trades with a non-negative result.
3. A TradeManFactory-object. This is the place where all these TradeMan-objects are working. The factory keeps track of which TradeMan-objects have become inactive (as their trade sequence was finished) and purges (i.e.) removes those from active duty.
As Empty4 is not a multi-threading environment, the normal basket EA needs to give a little bit of CPU-time to the factory in its main loop (in this case, during the OnTimer() event).
This in all is a very simple and clean concept, but here comes the hard part: maintaining state. If someone pulls the plug out of your computer, or if for some other reason the EA loses all its status information (the factory and the TradeMan-objects), this needs to be re-generated and initiated when Empty4 is restarted. I could have chosen to do this with files, but then you must make sure that no-one removes these files and also that old files are removed. Instead I use the OrderComment() field of the trade. A trade that has been opened by a TradeMan object will have an order comment of "ALR<n>:<ticket>" where <n>-denotes the ALR-level and <ticket> is the ticket number of the first trade, that spun-off the sequence of ALR-trades. Just be warned that if your br0ker changes the OrderComment() of your trades (as GP used to do a year or so back), this won't work.
So, this work is intended for other coders to study and hopefully generate their own OOP trading objects (to be shared on this wonderful forum). It is not intended for someone to download and put on their live account in the hope that they will get filthy rich -- as I can not guarantee that this will be the case.
ALR on a basket
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
ALR on a basket
You do not have the required permissions to view the files attached to this post.
-
Radar
- Trader
- Posts: 437
- Joined: Fri Mar 23, 2012 5:39 pm
- Location: Round the bend ;)
ALR on a basket
Hey Renexxxx,
Silly question...
Why not use GlobalVariables?
I've been thinking about basket EA's a lot lately, and the maintaining of state has been the main thing on my mind. with my limited skills and experience, the only options that I can see (aside from using OrderComment() and the inherent risk involved) is to either save any state info (that cannot be regenerated on init, or within the first loop of start/main) to files, or as GV's (one single file, for those that don't know how they're stored).
If you go the route of using GV's, there's some lazy typist's helpers here... http://www.stevehopwoodforex.com/phpBB3 ... 470#p98470
Have fun!
Radar =8^)
Silly question...
Why not use GlobalVariables?
I've been thinking about basket EA's a lot lately, and the maintaining of state has been the main thing on my mind. with my limited skills and experience, the only options that I can see (aside from using OrderComment() and the inherent risk involved) is to either save any state info (that cannot be regenerated on init, or within the first loop of start/main) to files, or as GV's (one single file, for those that don't know how they're stored).
If you go the route of using GV's, there's some lazy typist's helpers here... http://www.stevehopwoodforex.com/phpBB3 ... 470#p98470
Have fun!
Radar =8^)
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
StackManV2
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
ALR on a basket
Hi Radar,
Global Variables can not be used for the type of status information that needs to be stored. The Order Comment field provides the best option.
Cheers ...
Global Variables can not be used for the type of status information that needs to be stored. The Order Comment field provides the best option.
Cheers ...
-
taipan
- Trader
- Posts: 355
- Joined: Sat Feb 16, 2013 11:27 am
ALR on a basket
renexxxx
there is some errors when loading ea to chart, see expert log:
Cannot load C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\54CBDEFC6D4BE584AC2B9D49F33FAD39\MQL4\Libraries\LibOrderReliable4.ex4'
0 21:30:44.644 Expert StochyBasket_ALR EURUSD,M15: loaded successfully
0 21:30:44.644 StochyBasket_ALR EURUSD,M15 inputs: IncludeSymbols=AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY; HMATimeFrame=240; TimeFrame=15; MASlow=240; MinDistPIPs=2.0; OSLevel=20.0; OBLevel=80.0; Slippage=8; MagicNumber=48589; Lotsize=0.01; TradeComment=StoALR; AlertsOn=true; doRestart=false; pairSL=15.0; pairTP=30.0; StopTradingAfterClose=false; screenFont=Consolas;
1 21:30:50.823 Cannot call 'LibOrderReliable4.ex4::O_R_Config_use2step', 'LibOrderReliable4.ex4' is not loaded
1 21:30:50.823 unresolved import function call
3 21:30:50.823 StochyBasket_ALR EURUSD,M15: not initialized
0 21:30:50.823 StochyBasket_ALR EURUSD,M15: uninit reason 8
I have checked that libraries "LibOrderReliable4.mq4" & "LibOrderReliable4.ex4" is loaded in the libraries folder. Include folder was loaded with pre-mentioned files (5 files). for your info, "LibOrderReliable4.ex4" was copied from my other folder and is not compiled from your attached "LibOrderReliable4.mq4" file. May be that is the problem. Could you post your compiled "LibOrderReliable4.ex4" so that I could tried again.
cheers,
taipan
there is some errors when loading ea to chart, see expert log:
Cannot load C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\54CBDEFC6D4BE584AC2B9D49F33FAD39\MQL4\Libraries\LibOrderReliable4.ex4'
0 21:30:44.644 Expert StochyBasket_ALR EURUSD,M15: loaded successfully
0 21:30:44.644 StochyBasket_ALR EURUSD,M15 inputs: IncludeSymbols=AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY; HMATimeFrame=240; TimeFrame=15; MASlow=240; MinDistPIPs=2.0; OSLevel=20.0; OBLevel=80.0; Slippage=8; MagicNumber=48589; Lotsize=0.01; TradeComment=StoALR; AlertsOn=true; doRestart=false; pairSL=15.0; pairTP=30.0; StopTradingAfterClose=false; screenFont=Consolas;
1 21:30:50.823 Cannot call 'LibOrderReliable4.ex4::O_R_Config_use2step', 'LibOrderReliable4.ex4' is not loaded
1 21:30:50.823 unresolved import function call
3 21:30:50.823 StochyBasket_ALR EURUSD,M15: not initialized
0 21:30:50.823 StochyBasket_ALR EURUSD,M15: uninit reason 8
I have checked that libraries "LibOrderReliable4.mq4" & "LibOrderReliable4.ex4" is loaded in the libraries folder. Include folder was loaded with pre-mentioned files (5 files). for your info, "LibOrderReliable4.ex4" was copied from my other folder and is not compiled from your attached "LibOrderReliable4.mq4" file. May be that is the problem. Could you post your compiled "LibOrderReliable4.ex4" so that I could tried again.
cheers,
taipan
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
ALR on a basket
Sure here it is ...taipan » Fri Nov 21, 2014 11:43 pm wrote:Could you post your compiled "LibOrderReliable4.ex4" so that I could tried again.
cheers,
taipan
Or in MetaEditor, right-click on the Libraries\LibOrderReliable4.mq4 file and select 'Compile'
Cheers ...
You do not have the required permissions to view the files attached to this post.
-
PontusLSE
- Trader
- Posts: 14
- Joined: Wed Jun 11, 2014 5:04 pm
ALR on a basket
Hey renexxxx, nice work on this one!
I rewrote the StochyBasket_ALR so I could place the trades manually.
This has been working good, no real issues, except one problem that I don't understand and has not been able to solve, any input that could help me solve this is appreciated.
Look at the example below. ALR1 and ALR 2 is OK, but look at ALR 3, lot size 0.01 and a 15.000 pip TP!
Initial lot size is 0.05, SL ~50 pips and TP ~30 pips.
Is the problem that my SL is bigger than my TP? I know that the TP is supposed to be about 3 times larger then the SL, but in the example below, should not the TP be the same for all ALR trades and the lot size be bigger and bigger?
I rewrote the StochyBasket_ALR so I could place the trades manually.
This has been working good, no real issues, except one problem that I don't understand and has not been able to solve, any input that could help me solve this is appreciated.
Look at the example below. ALR1 and ALR 2 is OK, but look at ALR 3, lot size 0.01 and a 15.000 pip TP!
Initial lot size is 0.05, SL ~50 pips and TP ~30 pips.
Is the problem that my SL is bigger than my TP? I know that the TP is supposed to be about 3 times larger then the SL, but in the example below, should not the TP be the same for all ALR trades and the lot size be bigger and bigger?
Code: Select all
Lots Open SL SL Pips TP TP Pips
Initial trade 0,05 1,59061 1,59565 50,4 1,58778 28,3
ALR1 0,09 1,59565 1,59061 50,4 1,59848 28,3
ALR2 0,27 1,59061 1,59565 50,4 1,58778 28,3
ALR3 0,01 1,59565 1,59061 50,4 3,18626 15906,1
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
ALR on a basket
Yes, you're right. The SL and TPs should be the same for all the BUYs in the ALR-sequence, and similarly all the SELLs in the ALR-Sequence should share the same SL and TP.PontusLSE » Thu Dec 03, 2015 4:51 am wrote:but in the example below, should not the TP be the same for all ALR trades and the lot size be bigger and bigger?
It looks that somehow you've lost the status information of your initial trade (and/or subsequent ALR trades), when the EA was restarted or reinitialized. As with this form of ALR (ALR2), previous level ALR trades are closed and their information should be obtained from the ORDER_HISTORY cursor. For this reason it is important to have "All History" selected in the Account History. The code does this automatically, by a call to the EnableAllHistory() routine, when the TradeManFactory is created.
Without looking at your code, I have no idea what could have caused your status information to get lost and why you are getting these weird trades.
Incidentally, this is old, experimental code. In the meantime, Tommaso has worked on a New ALR Trade Manager that has been debugged and improved over a considerable amount of time. May be you are better of to take his code as a starting point.
-
PontusLSE
- Trader
- Posts: 14
- Joined: Wed Jun 11, 2014 5:04 pm
ALR on a basket
Thanks for your answer, but as far as I know he has not shared his code to the "New ALR Trade Manager".
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
ALR on a basket
I beg your pardon, I wasn't aware of that.PontusLSE » Thu Dec 03, 2015 9:58 pm wrote:Thanks for your answer, but as far as I know he has not shared his code to the "New ALR Trade Manager".