My issue is that my lotsize should be dynamic:
but when backtesting -- ALL Trades are istartlots, not istartlots2. Why not? i am confused!
There are always several trades open, all sell trades, so s5 variable is above 1 -- VERY OFTEN, so i do not understand why the line above is not making new lotsize to be "totalsel * istartlots2!
NOTE that i think i included all the code and highlighted the count of open sell trades and code how i count them. I hope someone can tell me what i have done wrong.
============
I am willing to post all files for the ea, however, i have not done so in this post due to there being 5 attached files -- besides the ea file.
You need to reference PositionsTotal().
Forum on trading, automated trading systems and testing trading strategies
Miguel Angel Vico Alba, 2017.03.07 08:51
You have never had a doubt? That lucky...
By the way...issue resolved.
for(int i=PositionsTotal()-1; i>=0; i--)
{
string CounterSymbol=PositionGetSymbol(i);
if(Symbol()==CounterSymbol && m_position.Magic()==MagicNumber)
{
PosCounter+=1;
i changed the line below
to
lotsize of all trades in backtest are still same size of iStartLots.
Thanks for the advice tho. Keep em comin.
The following code is a bit of a blunt instrument from my complex GBPJPY bot that uses GlobalVariables to communicate with external files but it works. Just replace the GV's with your own standard variables─the math is the same (minus denotes a lot reduction).
if(PositionsTotal() > 0) { tradeSize = NormalizeDouble(GlobalVariableGet("Last Traded Lot Size") - GlobalVariableGet("Last Traded Lot Size") * PercentLotDecrease * 0.01, 2); } else { tradeSize = NormalizeDouble(LotSize, 2); }
And to get the previous lot size, something like:
Forum on trading, automated trading systems and testing trading strategies
How to use PositionGetDouble(POSITION_VOLUME) correctly?
nicholish en, 2020.04.15 22:46
This is good but you shouldn't compare the strings, and instead you should get the actual position's symbol using PositionInfoString. Better yet, use CPositionInfo...
#include <trade/trade.mqh> double netPosition(string symbol) { CPositionInfo pos; double net_volume = 0.0; for (int i=PositionsTotal()-1; i>=0; --i) if (pos.SelectByIndex(i) && pos.Symbol() == symbol) net_volume += pos.PositionType() == POSITION_TYPE_BUY ? pos.Volume() : -pos.Volume(); return net_volume; }
You should get your sell lot volume following your:
if(otyp == POSITION_TYPE_SELL)
Apparently, the condition if(auto.ltv >= iStartLots) only occurs on the first trade. Try updating s5 before this condition:
auto.s5 = auto.s5 + 1; if(auto.ltv >= iStartLots) { if(position.PriceOpen() > auto.selMxg) auto.selMxg = position.PriceOpen(); if(position.PriceOpen() < auto.selMng) auto.selMng = position.PriceOpen(); }
The following code is a bit of a blunt instrument from my complex GBPJPY bot that uses GlobalVariables to communicate with external files but it works. Just replace the GV's with your own standard variables─the math is the same (minus denotes a lot reduction).
And to get the previous lot size, something like:
You should get your sell lot volume following your:
please check the use of my struct. thanks. ie the file attachment on the op message.
my dual lotsize(s) work when i put my variables and bools on global enviro, but breaks when i add them to the struct.
please check the use of my struct. thanks. ie the file attachment on the op message.
my dual lotsize(s) work when i put my variables and bools on global enviro, but breaks when i add them to the struct.
I've never used structs in that way. At a mere guess, maybe you can't equate auto.s5 to itself plus one. I would try storing auto.s5 to a "placeholder" variable, and then equating auto.s5 to that "placeholder" variable plus one.
didnt work either, but thansks for your suggestion. I have now removed the class.
I was clearly abusing the use of class. its been so many years since i did real coding that i have clearly forgotten something!
thanks again.
didnt work either, but thansks for your suggestion. I have now removed the class.
I was clearly abusing the use of class. its been so many years since i did real coding that i have clearly forgotten something!
thanks again.
You're most welcome.
On a related note, former Moderator Fernando posted elsewhere that he always prefers to use standard code elements instead of OOP code elements wherever possible.
You're most welcome.
On a related note, former Moderator Fernando posted elsewhere that he always prefers to use standard code elements instead of OOP code elements wherever possible.
Yeah i did think of that. maybe the libraries arent updated after mt5 was, but coding with em is still working otherwise...AND is faster to code with the shortened commands, so that is why i chose to simply remove the full class and go back to global enviro use, as opposed to coding via the "long winded method".
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
My issue is that my lotsize should be dynamic:
LastLot[sel] = totalSel<1? iStartLots : totalSel * iStartLots2;but when backtesting -- ALL Trades are istartlots, not istartlots2. Why not? i am confused!
There are always several trades open, all sell trades, so s5 variable is above 1 -- VERY OFTEN, so i do not understand why the line above is not making new lotsize to be "totalsel * istartlots2!
NOTE that i think i included all the code and highlighted the count of open sell trades and code how i count them. I hope someone can tell me what i have done wrong.
============
I am willing to post all files for the ea, however, i have not done so in this post due to there being 5 attached files -- besides the ea file.