Discussing the article: "Expert Advisor based on the universal MLP approximator" - page 2

 
Eric Ruvalcaba #:

Thank you so much for sharing this article, and the insight. Great idea. I Implemented some independent position handling and got it working on hedging account (my broker)

You are the best.

Super!

 

Dear author, I reread the TargetFunction() code several times and it seems you made some mistakes.

1. When calculating profit on a position, you make a double summation of the profit.

        if (!truTradeTime [h]) {
            if (posType != 0) { // If there is an open position
                posClPrice = rates [h].open; // Close at the bar opening price
                profit = (posClPrice - posOpPrice) * signal - 0.00003; // Commission

                if (profit > 0.0) allProfit += profit;
                else              allLoss   += -profit;

                if (posType == 1) buys++;
                else              sells++;

                allProfit += profit;
                posType = 0; // Reset position
            }
            continue; // Skip non-trading time
        }

        if ((posType == 1 && signal == -1) || (posType == -1 && signal == 1)) {
            posClPrice = rates [h].open; // Close at the opening price of the current bar
            profit = (posClPrice - posOpPrice) * signal - 0.00003; // Calculation of profit

            // Profit/loss accounting
            if (profit > 0.0) allProfit += profit;
            else              allLoss   += -profit;

            // Statistics on transactions
            if (posType == 1) buys++;
            else              sells++;

            allProfit += profit;
            posType = 0; // Position closed
        }


2. The ko coefficient is not used when calculating the adaptability index.
double ko = 1.0;
  if (sells == 0 || buys == 0) return -DBL_MAX;
  if (sells / buys > 1.5 || buys / sells > 1.5) ko = 0.001;

  return (allProfit / (allLoss + DBL_EPSILON)) * dealsNumb;
 
John_Freeman #:

Dear author, I reread the TargetFunction() code several times and it seems you made some mistakes.

1. When calculating profit on a position, you make a double summation of the profit.


2. You do not use the ko coefficient when calculating the adaptability index.

1. Yes, you are right, remove the lines at the end of both code blocks
allProfit += profit;

to make it look like this:

f (!truTradeTime [h]) {
            if (posType != 0) { // If there is an open position
                posClPrice = rates [h].open; // Close at the bar opening price
                profit = (posClPrice - posOpPrice) * signal - 0.00003; // Commission

                if (profit > 0.0) allProfit += profit;
                else              allLoss   += -profit;

                if (posType == 1) buys++;
                else              sells++;

                //allProfit += profit;
                posType = 0; // Reset position
            }
            continue; // Skip non-trading time
        }

        if ((posType == 1 && signal == -1) || (posType == -1 && signal == 1)) {
            posClPrice = rates [h].open; // Close at the opening price of the current bar
            profit = (posClPrice - posOpPrice) * signal - 0.00003; // Calculation of profit

            // Profit/loss accounting
            if (profit > 0.0) allProfit += profit;
            else              allLoss   += -profit;

            // Statistics on transactions
            if (posType == 1) buys++;
            else              sells++;

            //allProfit += profit;
            posType = 0; // Position closed
        }


2. Yes, ko is not used.