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(); }
- 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.