First decide how much you want to trade in the grid.
In my case:
Funding = accountfreemargin()/21; where 21 is the number of pairs I am trading right now. you might add a calculation to limit it to a maximum like $2000 for example.
Then determine how the Range in which you want to define your grid. In my case:
historicmax = GetTheHighestHigh(200); // over 200 days
historicmin = GetTheLowestLow(200); // over 200 days
centerline = historicmax+historicmin/2;
Now calculate the GAP between trades in points using an arithmetic progression:
Gap = CalcGapSize(pricerange,funding,tolerance);
pricerange and tolerance are unimplemented right now, funding is from above where you decided how much to use across the grid.
Now decide your Entry strategy. For mine, slightly simplified, if the price is above centerline, and below the current ParabolicSAR I sell. If it is below the centerline but above the parabolicSAR buy. In either case the price has to be further than the GAP in either direction from the last or any trade.
Using this I generally trade 0.01 lots with $3000-$5000 available per pair.
There are lots of things in this code that are hard to understand, but it works.
This a link to a demo account using this type of grid trading:
double CalcGapSize(double pricerange, double funding, int tolerance) { int i, j; double l, asubn, n, d; //Print(pricerange, " / ", funding, " / ", tolerance); //Print("max, min: ", historicmax," / ",historicmin); //Print("Total Points: ", ((historicmax-historicmin)/2)/MarketInfo(Symbol(),MODE_TICKSIZE)); //Print("Above Points: ", (historicmax-Ask)/MarketInfo(Symbol(),MODE_TICKSIZE)); //Print("Below Points: ", (Bid-historicmin)/MarketInfo(Symbol(),MODE_TICKSIZE)); asubn = ((historicmax-historicmin)/2)/MarketInfo(Symbol(),MODE_TICKSIZE); //Print(" A sub n: ",asubn); d=0; n = 99999; while(n > 5 ) // will be our gap { d=d+1; n=asubn/d; // l = (((n*(2*(1)+(n-1)*d))/2) / (MarketInfo(Symbol(),MODE_TICKSIZE))) * (MarketInfo(Symbol(),MODE_TICKVALUE)) / (MarketInfo(Symbol(),MODE_LOTSIZE)) * 0.01; l = ( (n*(2*(1)+(n-1)*d))/2) * (MarketInfo(Symbol(),MODE_TICKVALUE)) * _LotSize; // Print("n: ", n," d: ", d," l: ", l); if (l < funding) { n = 0; } } //Print("n: ", n," j: ", j," l: l"); return(d); }
Thank you serpentsnoir. Very helpful
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am looking for a formula or ready-made application that will tell me what the grid spacing needs to be for a given range, so I don't blow up my account. Any ideas?