Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Grid system based on optimization and statistics

author EAcpu | 4 reads | 0 comments |
Hello everyone,
I would like to share a simple EA based on non-martingale grid systems, and I will be very grateful to people who help me understand the logical implications of these systems.
1. Sorry for my bad English, but I don't speak English.
2. Please note that the code is very bad and does not pass magic filtering nor pairing... it's just playing with the settings

This idea was taken from other grid systems on the web, also in this forum:

  1. - Place n buystop and n sellstop orders, increasing lot size when you move away from the current price
  2. - The distance for each order is fixed
  3. - Enter the same take profit for all orders


inserted code
 for(int ciclo=1;ciclo<=ncicli;ciclo++)
          {

         OrderSend(Symbol(), OP_BUYSTOP, lotti, NormalizeDouble(Ask+distanza,Digits), 0, 0,NormalizeDouble(Ask+distanza+tp,Digits), "eva", 0, scadenza, Green);
         OrderSend(Symbol(), OP_SELLSTOP, loti, NormalizeDouble(Bid-distanza,Digits), 0, 0,NormalizeDouble(Bid-distanza-tp,Digits), "eva", 0, scadenza, Green);
        if (ciclo==ncicli)
        {
        distance=d;
        Lottie = a lot;
        }
        otherwise{
        distance=distance+d;
        Lottie = Lottie + Luo;
        }

          }

Then I put some conditions:

  1. All orders are closed when the profit of the current basket is reached or the total loss is reached
  2. When only one order is open and there are no other pending orders, close all orders and restart
  3. When there is only sellstop or only buystop order, all positions are closed

The purpose is to avoid an order being in a state far away from the original price for a long time, pending orders still exist and the current price is far away from the original price... So I accept a little loss and just restart with a full grid and take profit with the first order.

Now, when I discovered the power of optimization, I tried to find settings that would allow me to make a profit; since I don't use martingale, only statistics and optimization settings seemed to stop me.
The best result I got was with 1 year optimization using eurusd:

inserted code
 275 1743.69 1629 1.21 1.07 715.78 78.69% 0.00000000 Profit=26 Distance=3 Total_loss=-90 ncicli=8 attiva_scadenza=0 Lot=0.01 moltipl=1 Loss=0 My_Money_Profit_Target=100 perdita_massima=-999 expire=0 attiva_exp=0 minutes=0


I started with a balance of 100 euros and made a profit of 1629 euros, with a maximum drawdown of 78.69% in one year.
Of course, repeating the backtesting over another year didn't give me the same good results.

So my question is: is this a purely random system? Do you think there is enough optimization time so that I can make a reasonable profit in the future based on the theory of large numbers?
I thought a year was a long time for testing, but it's not...

I hope I explained it, if anyone is willing to reason with me I will share the while code and answer your question.

Thank you all!

📦 Summary of post attachments (2)

Below are all the files (2) shared in the reply.

Verification code Refresh