In the code below I am attempting to access the number of contracts used in my previous trade and increment them by 1:
Here is what I have tried:
int Test = Positions[0].Quantity: This does nothing. It won't increment at all, it just stays at 1. I have tried moving the index to 1, -1, etc, but nothing seems to work here.
int Test2 = lastTrade.Quantity; This just takes the last executed part of the trade, as I mentioned it works fine until there are splits then it only looks at the last executed quantity in the sequence.
int Test3 = lastTrade.Entry.Quantity; This one takes the first entry quantity, which reduces the number of splits since most of the splits occur on the exit, but again, when I splits on the entry, it takes the first part and not the whole thing.
Here is the working code below. Please let me know how to accomplish accessing the full number of contracts from my previous trade. I appologize if this has been fielded somewhere else on the board, but I have looked for hours and could not find anything.
if (Performance.RealtimeTrades.Count > 0)
{
Trade lastTrade = Performance.RealtimeTrades[Performance.RealtimeTrades.Count - 1];
double lastProfit = lastTrade.ProfitCurrency * lastTrade.Quantity;
Print("The last trade's profit is " + lastProfit);
int Test = Positions[0].Quantity ;
int Test2 = lastTrade.Quantity;
int Test3 = lastTrade.Entry.Quantity;
// Condition set 1
if (Close[0] > Open[0]
&& Close[1] > Open[1]
&& Close[2] < Open[2]
&& Position.MarketPosition == MarketPosition.Flat
)
{
EnterLong(Test +1,"");
}
}
Thanks,
Ian
Comment