// Grid trader (needs hedging - non-US accounts only)
// find all trades at a grid line
bool findTrade(var Price,var Grid,bool IsShort)
{
for(open_trades)
if((TradeIsShort == IsShort)
and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2))
return true;
return false;
}
int run()
{
set(TICKS); // Test using 1 minute Bars
StartDate = 2012; // Start trading from 2012
BarPeriod = 240; // Trade the 4 Hour chart
Hedge = 2; // allow long & short trades at the same time
EntryTime = ExitTime = 500; // close trades that have been opened for 3 months
asset("EUR/CHF");
var Price;
var Grid = 25*PIP; // set grid siz to 25 pips
var Close = priceClose(); // Use the price close of bars
// place pending trades at 5 grid lines
// above and below the current price
for(Price = 0; Price < Close+5*Grid; Price += Grid)
{
// find the lowest grid line
if(Price < Close-5*Grid) continue;
// place not more than 200 trades
if(NumOpenTotal + NumPendingTotal > 200) break;
// place short trades below the current price
if(Price < Close and !findTrade(Price,Grid,true))
enterShort(1,Price,20*Grid,Grid);
// place long trades above the current price
else if(Price > Close and !findTrade(Price,Grid,false))
enterLong(1,Price,20*Grid,Grid);
}
}