Counting trading cycles

 

Hello good afternoon,

I need help in the programming of an Expert Advisor (EA) for MetaTrader4.

In principle this EA I did with a builder (EABuilder), and from there I have been adding / modifying things (calculation of lot size, closing all open positions, start at a specific time or immediately, etc.).

In this EA, a position is opened, and depending on how the price goes, it will open another position(s).

Finally, when a TakeProfit or a StopLoss is reached, all positions will be closed. To all this, I call it a "Cycle" (first open positions and then close all).

The EA will open a new position, immediately after or at a scheduled time. Then we will have a new "Cycle" that finally will also close. And we will be counting the "Cycles".

I'm stuck with the "Cycles" counter.

I have set a global variable: int Cycles = 0;

When I put the "Cycles" counter (Cycles = Cycles + 1, or Cycles ++) in the short positions closing function, for example:


// Close Short Positions

   RefreshRates ();

   if (Ask> = FirstOpenTradePrice () + StopLoss * myPoint

   )

     {   

      if (IsTradeAllowed ())

        {

        myOrderClose (OP_SELL, 100, "");

        myOrderClose (OP_BUY, 100, "");

        Cycles = Cycles + 1; Print ("Cycles =   ", Cycles);      // Here is the "Cycles" counter

        }

      else // not autotrading => only send alert

         myAlert ("order", "");

     }


Then when I do the Backtesting with the MetaTrader 4 Strategy Tester, in the tab "Registration" below there are many lines with a very high total number of Cycles (tens of thousands, hundreds of thousands or millions, depending on the Backtesting period used).

I would appreciate any idea or suggestion to be able to count the "Cycles" one by one, and not by thousands or millions.

Thank you very much
 

Please use the </> button to insert your above code.


 
Eleni Anna Branou :

Please use the </> button to insert your above code.


Next time that I will put a code in the forum, I Will use the button </>. I already have seen it, but finally I didn't use it.


Thanks for trying to help, but doing tests I have already solved it.

I have set the "Cycles" counter (Cycles = Cycles + 1) in the part where the first order opens, at the end of an "if" conditional. And the cycles are already counted correctly.

Regards

Reason: