Hello,
Hope you are doing well during the pandemic.
Suppose I have an account with $100,000 capital and the broker provides a 1:100 leverage. In each trade I want to risk 1% of capital ($1000). I searched in the forum about size of positions in the forex market but I still couldn't find what I am exactly looking for. I would appreciate it if could help me with the following question:
When I want to define the volume which I should buy, first I calculate the difference between the entry point and stop-loss (based on points in MT5). Then, I divide the amount I am going to invest or put in risk ($1000) by the difference. For example, in the below pic I want to entre at 0.94390 and put my stop-loss at 0.94096. So, the volume (position size) should be $1000 / 294 points = 3.40 (with two decimals).
Note: I know that it is not an exact definition to find the volume and it depends and the point value and commission but here I assumed that the point value is $10 (in other words, if I trade one lot ($100,000) from AUDCAD and the price changes one pip (TickSize = 0.0001), it worths $10 (PointValue = 10).
Now, if I buy 3.40 lot of AUDCAD at 0.94390 and then the price goes down to the 0.94096, I will lose $1000.
Based on the below link, I defined a trailing stop loss which is 20 pips lower than the low of the candle:
http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/
SetOption("InitialEquity", 100000 );
settradedelays( 0, 0, 0, 0 );
//PointValue = 10; // determines the amount of profit generated by one contractfor a one point increase in price.
// represents value of profit/loss by 1 full point price movement.
//MarginDeposit = 1000; // in most cases should be set to 1000 (1% margin from $100’000)
TickSize = 0.0001; // This setting controls the minimum price move of given symbol.
RoundLotSize = 0; // If default size is set also to zero it meansthat fractional number of shares/contracts are allowed.
PositionSize = 1000 / ( ( (C - L - 0.002) / TickSize ) * 10);
//SetPositionSize(PctSize, spsShares);
//=============================================================================================================================
Buy = Cross( C, MA( C, 20 ) );
Sell = 0;
trailARRAY = Null;
trailstop = 0;
//StopLevel = 1 - Param("trailing stop %", 3, 0.1, 10, 0.1)/100;
StopLevel = 0.002;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
//trailstop = High[ i ] * stoplevel;
trailstop = Low[i] - StopLevel;
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 )
{
//trailstop = Max( High[ i ] * stoplevel, trailstop );
trailstop = Max( Low[i] - StopLevel, trailstop );
trailARRAY[ i ] = trailstop;
}
}
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -10);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -20);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0, L, Offset = -15);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 10);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 20);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0, H, Offset = -15);
Plot( Close,"Price",colorBlack,styleBar);
Plot( trailARRAY,"trailing stop level", colorRed );
I applied the above-mentioned code on my chart and based on the formulation I expect to find a 3.4 lot for size of position on 2020-09-28 entry and a profit of around 3% but I cannot get that result.
This is the setting of my backtest:
and here you can find the report of the backtest:
I also tried the following sample codes in the following link but I cannot find the 3.40 in the shares and profit of around 3% for long entry on 2020-09-28. I don't understand what is wrong?
http://www.amibroker.com/kb/2014/10/12/position-sizing-based-on-risk/
I would deeply appreciate if you could help me. Thanks a million in advance.
Best regards,