Task: Store "AllTrades" - Quantity. Then pass the data to my "private double _sizeDoubler" so I can increase the my lot size if the last trade was a loss.
I have wrote many different configurations. I'll leave what I feel should definitely be working below:
The following code is written below "OnExecutionUpdate".
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
private void MartingaleManagment(Order order)
{
double _sizeDoubler = 0;
var lossInPips = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPips;
var lossInPoints = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPoints;
var sizeLastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Quantity;
if (lossInPips <= 0 || lossInPoints < 0)
{
_sizeDoubler = (int) lastTradeQty;
if (MyMarketType == MarketType.Forex)
{
_posSize = _(int) _sizeDoubler * 8;
}
else if (MyMarketType == MarketType.Other)
_posSize = (int) _sizeDoubler * 8;
}
else
{
_posSize = InitialLotSize;
}
}
if (SystemPerformance.AllTrades.Count > 0)
{
// Check to make sure there is at least one trade in the collection
Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
lastTradeQty = lastTrade.Quantity;
Print("The last trade's quantity " + (lastTradeQty));
}
{
var lossInPips = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPips;
var lossInPoints = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPoints;
if (lossInPips <= 0 || lossInPoints < 0)
if (MyMarketType == MarketType.Forex)
{
_posSize = (int) lastTradeQty* 8;
}
else if (MyMarketType == MarketType.Other)
_posSize = (int) lastTradeQty * 8;
}
else
{
_posSize = InitialLotSize;
}
}
Any thoughts?
Comment