Anyone interested in MT4 Grid Trading expert adviser?
Roy Meshulam, Customer Delivery Manager at MasterCard
Monday, November 2, 2015
My idea was to create a grid around the current price as a starting point, using buy and sell stop orders around the current price and then moving with the price and the trend. If it goes up the buy stop will kick in and so on the following buy stops, while below it I opened a buy limit order in case the price goes down and up again. Same for the other way around, it has sell stops on the way down. If the price goes down, and there is an open sell trade instead of opening a buy limit below the bid, I will open a sell stop, a code snippet for example:
"else if((Bid-HighestSellStopOrderPrice)>2*GridGap)
{
if(OpenOrdersCounter[OP_SELL]>0)
{
Log("Opening sell stop order as there are open sell orders, DistanceFromHighestSellStop = "+DoubleToStr(DistanceFromHighestSellStop));
OpenSellStopOrder(GridSymbol,GridLotSize,NormalizeDouble(HighestSellStopOrderPrice+GridGap,ProductDigits),StopLossFlag?NormalizeDouble(HighestSellStopOrderPrice+GridGap+SL,ProductDigits):0,TakeProfitFlag?NormalizeDouble(HighestSellStopOrderPrice+GridGap-TP,ProductDigits):0,Slippage,MagicNumber);
}
else if(OpenOrdersCounter[OP_BUYLIMIT]==0)
{
Log("Opening buy limit order, DistanceFromHighestSellStop = "+DoubleToStr(DistanceFromHighestSellStop));
OpenBuyLimitOrder(GridSymbol,GridLotSize,NormalizeDouble(HighestSellStopOrderPrice+GridGap,ProductDigits),StopLossFlag?NormalizeDouble(HighestSellStopOrderPrice-SL+GridGap,ProductDigits):0,TakeProfitFlag?NormalizeDouble(HighestSellStopOrderPrice+GridGap+TP,ProductDigits):0,Slippage,MagicNumber);
}
}
The stop loss is updated whenever the price moves in our favour, there is no take profit:
void UpdateOrdersStopLoss(string argSymbol,int argMagicNumber,int argGapFactor,double argGap)
{
double Difference,NewSL;
for(int Counter=0; CounterargGapFactor*argGap)
{
NewSL=NormalizeDouble(OrderStopLoss()+(MarketInfo(argSymbol,MODE_ASK)-OrderStopLoss()-(argGapFactor*argGap)),(int)MarketInfo(argSymbol,MODE_DIGITS));
Log("Difference = "+DoubleToString(Difference)+", NewSL = "+DoubleToString(NewSL)+", Gap Factor = "+IntegerToString(argGapFactor)+", Gap = "+DoubleToString(argGap));
AddStopProfit(OrderTicket(),NewSL, OrderTakeProfit());
}
break;
}
case OP_SELL:
{
Difference=OrderStopLoss()-MarketInfo(argSymbol,MODE_BID);
if(Difference>argGapFactor*argGap)
{
NewSL=NormalizeDouble(OrderStopLoss()-(OrderStopLoss()-MarketInfo(argSymbol,MODE_BID)-(argGapFactor*argGap)),(int)MarketInfo(argSymbol,MODE_DIGITS));
Log("Difference = "+DoubleToString(Difference)+", NewSL = "+DoubleToString(NewSL)+", Gap Factor = "+IntegerToString(argGapFactor)+", Gap = "+DoubleToString(argGap));
AddStopProfit(OrderTicket(),NewSL,OrderTakeProfit());
}
break;
}
}
}
}
}
I couldn't attach the EA to this post, not even screenshots, but if you want to give it a try, PM me or comment your contact details and I'll e-mail you the EA, I hope to get some constructive feedback to improve it or start a fruitful discussion.