Grid System

 

Hi guys,


I'm looking for someone to point me in the right direction for developing a grid system as I cannot seem to find the info I am looking for...


Basically I want the system to open a buy and sell position every 1R (X pips), with 0 stop loss and 1R Take Profit.


I have managed to write the code to enter the trades every X pips:

input int GridPips = 50;

void OnTick()
   {
    int Grid = 500; //Grid Points
   
    static double NextBuy = 0;
    static double NextSell = 0;
    
    if(OrdersTotal() == 0){
    OrderSend(_Symbol,OP_BUY,0.10,Ask,3,0,0,NULL,0,0,clrSteelBlue);
    OrderSend(_Symbol,OP_SELL,0.10,Bid,3,0,0,NULL,0,0,clrCrimson);
    NextBuy = Ask + Grid*_Point;
    NextSell = Bid - Grid*_Point;}
    
    if(Ask==NextBuy){
    OrderSend(_Symbol,OP_BUY,0.10,Ask,3,0,0,NULL,0,0,clrSteelBlue);
    OrderSend(_Symbol,OP_SELL,0.10,Bid,3,0,0,NULL,0,0,clrCrimson);
    NextBuy = Ask + Grid*_Point;
    NextSell = Bid - Grid*_Point;}
    
    if(Ask==NextSell){
    OrderSend(_Symbol,OP_BUY,0.10,Ask,3,0,0,NULL,0,0,clrSteelBlue);
    OrderSend(_Symbol,OP_SELL,0.10,Bid,3,0,0,NULL,0,0,clrCrimson);
    NextBuy = Ask + Grid*_Point;
    NextSell = Bid - Grid*_Point;}
   }


But when I try and include the take profit the ea stops regularly opening positions every 1R when TPs have been hit:


input int GridPips = 50;

void OnTick()
   {
    int Grid = 500; //Grid Points
   
    static double NextBuy = 0;
    static double NextSell = 0;
    
    if(OrdersTotal() == 0){
    OrderSend(_Symbol,OP_BUY,0.10,Ask,3,0,Ask+Grid*_Point,NULL,0,0,clrSteelBlue);
    OrderSend(_Symbol,OP_SELL,0.10,Bid,3,0,Bid-Grid*_Point,NULL,0,0,clrCrimson);
    NextBuy = Ask + Grid*_Point;
    NextSell = Bid - Grid*_Point;}
    
    if(Ask==NextBuy){
    OrderSend(_Symbol,OP_BUY,0.10,Ask,3,0,Ask+Grid*_Point,NULL,0,0,clrSteelBlue);
    OrderSend(_Symbol,OP_SELL,0.10,Bid,3,0,Bid-Grid*_Point,NULL,0,0,clrCrimson);
    NextBuy = Ask + Grid*_Point;
    NextSell = Bid - Grid*_Point;}
    
    if(Ask==NextSell){
    OrderSend(_Symbol,OP_BUY,0.10,Ask,3,0,Ask+Grid*_Point,NULL,0,0,clrSteelBlue);
    OrderSend(_Symbol,OP_SELL,0.10,Bid,3,0,Bid-Grid*_Point,NULL,0,0,clrCrimson);
    NextBuy = Ask + Grid*_Point;
    NextSell = Bid - Grid*_Point;}

   }



How can I get around this problem?


Thanks in advance

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.

 
Benjamin David Hardman:

Hi guys,


I'm looking for someone to point me in the right direction for developing a grid system as I cannot seem to find the info I am looking for...


Basically I want the system to open a buy and sell position every 1R (X pips), with 0 stop loss and 1R Take Profit.


I have managed to write the code to enter the trades every X pips:


But when I try and include the take profit the ea stops regularly opening positions every 1R when TPs have been hit:




How can I get around this problem?


Thanks in advance

I would suggest to use STOP / LIMIT orders for your grid.
Whenever any position is closed, you can place new one replacing it.

Just an idea, YMMV.

 
  1.     if(Ask==NextBuy){

    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

    Ask does not move only by a point.

  2. Hedging, grid trading, same as Martingale.
              Martingale, Hedging and Grid : MHG - General - MQL5 programming forum 2016.12.20

    Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum 2015.02.11

    Why it won't work:
              Calculate Loss from Lot Pips - MQL5 programming forum 2017.07.11
              THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube

 
William Roeder:
  1. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

    Ask does not move only by a point.

  2. Hedging, grid trading, same as Martingale.
              Martingale, Hedging and Grid : MHG - General - MQL5 programming forum 2016.12.20

    Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum 2015.02.11

    Why it won't work:
              Calculate Loss from Lot Pips - MQL5 programming forum 2017.07.11
              THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube

Thanks, changing the doubles approached seemed to help!


Re. MHG methods, I plan to grid with a trailing stop and proper risk management; not at all like a martingale system!

Reason: