Using OrderProfit in lot size calculation

 

Hello

I am trying to keep track of and use the most recent OrderProfit in a calculation for Lot Size and I'm not sure if I'm going about it correctly. Here is what I'm doing:



double LotSize(int takeProfit, int gam, int stopLoss) {
    cap = AccountBalance() / (stopLoss * 0.01);
    les = profit * x;
    ...
}
 
 
int start() {
    int j,hstTotal=OrdersHistoryTotal();
    double []     
 
    for(j=0;j<hstTotal;j++)
    {
     OrderSelect(j,SELECT_BY_POS,MODE_HISTORY);
     double profit = OrderProfit();
    }
 ...
 
   if (buyLevel > 0.0) {
      calculatedLots = LotSize(TakeProfit, GAM, StopLoss);

I have a LotSize function that I want to use the most recent "Closed" profit in, which I am trying to store and get from the for-loop in start(). I then use the Lots in my buyLevel trigger.

Is this the proper way to keep track of the profit? It seems like I don't need to check this after each tick, rather only when the Ticket changes? Should this be in start()?

Thanks for any help

Reason: