Hi, I'm playing with simple Martingale strategy, no indicators, nothing.
- remember current account state
- set MarketOrder with StopLoss
- if StopLoss was hit in previous trade, increase number of contracts to trade and revert the direction of the next order
- if profit in currently open position is greater than last account state, close position with profit, repeat actions
StopLoss woks as expected, but when I close open position with profit my account continues going down because my function, that calculates current account balance, is missing something, maybe some fee. How to get resulting value of all open positions + closed positions + fees?
protected decimal GetBalance()
{
return iBalance + // static value = 10000
Portfolio.TotalUnrealizedProfit +
Portfolio.TotalProfit -
Portfolio.TotalFees;
}
The main idea is that open position can be closed only by StopLoss, or when total account equity is greater than it was after last succesful trade.
Example.
- initial balance = 10000, save it as succesful state
- place MarketOrder, StopLoss triggered, so I lost $1 commission + $1 by stop order, balance = 10000 - 2 = 9998
- increase next lot by 2 and place new MarketOrder, this time profit is $4, so it covers previous loss + commission, balance = 9998 + 4 = 10002
- at this point 10002 > 10000, so we save it as a new succesful balance, decrease lot size back to 1 and repeat
In the attached back test switch to 3m or 6m chart and see that in some reason last profitable trade doesn'r cover all previous losses. Can't understand why...
Artemiusgreat
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!