I am sharing a raw grid code I used on the DAX m1 timeframe during the last bullish leg.
The logic is stupidly simple: It buys 1 contract every time price drops by 20 points from the last trade price. It closes everything when the total profit reaches a fixed target (Global Target).
I know grids are dangerous, but if you run this only during US market hours and cut it before the close, it acts as a liquidity provider.
Be careful with the leverage, on the DAX it can go fast. I set the max positions to 10 to avoid blowing the account.
// --------------------------------------------------------
// Strategy: Simple Accumulation Grid (Long Only)
// Asset: DAX / Indices
// Risk: HIGH - No Stop Loss per trade
// --------------------------------------------------------
DEFPARAM CumulateOrders = True // Essential for Grid
// Settings
GridStep = 20 // Distance between buys
TakeProfitPoints = 50 // Target in points (Global)
MaxPositions = 10 // Safety limit
// Entry Logic
IF Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
LastEntryPrice = Close
ENDIF
// Add to Grid (Averaging Down)
IF LongOnMarket AND CountOfPosition < MaxPositions THEN
IF Close <= LastEntryPrice - GridStep THEN
BUY 1 CONTRACT AT MARKET
LastEntryPrice = Close // Update reference price
ENDIF
ENDIF
// Exit Logic (Global Profit Target)
// We calculate the average entry price of the whole stack
AvgPrice = PositionPrice
CurrentProfit = (Close - AvgPrice) * CountOfPosition
IF CurrentProfit >= (TakeProfitPoints * PointValue) THEN
SELL AT MARKET
ENDIF
It’s not too bad that the trend is clear (long only on indices)… Of course, be wary of Trump as soon as the US wakes up!
This is below another version, tested for recent NASDAQ data 5-minutes, 0.5 contracts, 1 point spread.
Added a trend filter (simple couple of long term SMA comparison) plus another exit when in profit / breakeven in grid situation.
There is a whole range of things to explore for this kind of strategies! Lots of maths and headaches, but hey we like this so much! š
// --------------------------------------------------------
// Strategy: Simple Accumulation Grid (Long Only)
// Risk: HIGH - No Stop Loss per trade
// --------------------------------------------------------
DEFPARAM CumulateOrders = True // Essential for Grid
// Settings
GridStep = 20 // Distance between buys
TakeProfitPoints = 50 // Target in points (Global)
MaxPositions = 10 // Safety limit
sma1=average[200]
sma2=average[400]
uptrend = sma1>sma2
// Entry Logic
IF Not OnMarket and uptrend THEN
BUY 1 CONTRACT AT MARKET
LastEntryPrice = Close
ENDIF
// Add to Grid (Averaging Down)
IF LongOnMarket AND CountOfPosition < MaxPositions and not uptrend THEN
IF Close <= LastEntryPrice - GridStep THEN
BUY 0.5 CONTRACT AT MARKET
LastEntryPrice = Close // Update reference price
ENDIF
ENDIF
// Exit Logic (Global Profit Target)
// We calculate the average entry price of the whole stack
AvgPrice = PositionPrice
CurrentProfit = (Close - AvgPrice) * CountOfPosition
IF (CurrentProfit >= (TakeProfitPoints * PointValue)) OR (CurrentProfit>0 and countofposition>1) THEN
SELL AT MARKET
ENDIF