| / | Forum |
|
pasmat
2008.08.18 18:35
Hi you all, My EA works best when I increment the lots by 0.1 after each order. I want to send it to the Championship, so I came up with a formula to stop the lots at 5. I am new to Mql4, there may be a better way, but this is all I can think off. The following code works fine with the strategy tester, but I have noticed that when I start the EA on the demo account, the lots does not increment and each order open with 0.4 lots. input parameters extern double Lots=0.3; .................. { I have modified the above code with the code below. Now it works fine on demo, but when I use the strategy tester, it works fine the first time but the other times, it starts the lots where it left off ( example:it starts with 0.4, 0.5, etc.. but if it stops at 3.6, the next time I start the tester my lots will starts at 3.7). input parameters extern double Lots=0.3; .................. { Can anybody help? Thank you |
|
Thomas Bopp is the Jury Member representing the TRADERS' magazine. In his interview, he tells where and how he studied technical analysis, as well as about his work at Der Zyklus-Analyst. Thomas has also revealed some details of his own Expert Advisor and his estimation of the Automated Trading Championship 2006. |
|
TheEconomist
2008.08.18 19:46
1. You could use a variable to retain the last lots SaveLots=Lots; // this comes after OrderSend; and Lots=SaveLots+0.1; //before ordersend 2. You could do similar, with a global variable Lots=GlobalVariableGet("SaveLots")+0.1; ... GlobalVariableSet("SaveLots",Lots) ; // after ordersend however, you have to make sure SaveLots is being set at 0, if not already existing (check with GlobalVariableCheck()) 3. Most complicated and safe, use a function that works for sure double GetLastOrderLots() { double lotsize=0.00; int maxtime=-1; int ntrades=OrdersTotal(); if (ntrades!=0) { for (int i=ntrades-1;i>=0;i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==True) { if (OrderOpenTime()>maxtime) { maxtime=OrderOpenTime(); lotsize=OrderLots(); } } } } return(lotsize); } |
|
pasmat
2008.08.18 20:43
TheEconomist wrote >>
1. You could use a variable to retain the last lots SaveLots=Lots; // this comes after OrderSend; and Lots=SaveLots+0.1; //before ordersend 2. You could do similar, with a global variable Lots=GlobalVariableGet("SaveLots")+0.1; ... GlobalVariableSet("SaveLots",Lots) ; // after ordersend however, you have to make sure SaveLots is being set at 0, if not already existing (check with GlobalVariableCheck()) 3. Most complicated and safe, use a function that works for sure double GetLastOrderLots() { double lotsize=0.00; int maxtime=-1; int ntrades=OrdersTotal(); if (ntrades!=0) { for (int i=ntrades-1;i>=0;i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==True) { if (OrderOpenTime()>maxtime) { maxtime=OrderOpenTime(); lotsize=OrderLots(); } } } } return(lotsize); } Thank you very much. It seems complicated to me but I will try and I sure I will get it eventually. |