Search
× Search
Monday, December 23, 2024

Archived Discussions

Recent member discussions

The Algorithmic Traders' Association prides itself on providing a forum for the publication and dissemination of its members' white papers, research, reflections, works in progress, and other contributions. Please Note that archive searches and some of our members' publications are reserved for members only, so please log in or sign up to gain the most from our members' contributions.

Anyone interested in MT4 Grid Trading expert adviser?

photo

 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.


Print

16 comments on article "Anyone interested in MT4 Grid Trading expert adviser?"

photo

 Oleksandr Medviediev, Portfolio Analyst – FIBI

 Monday, November 2, 2015



@ Roy, are you a trader and mql-coding programmer (head-cook and bottle-washer) at the same time?

Not such a good idea to get desired result, unless you do it for fun ))


photo

 Roy Meshulam, Customer Delivery Manager at MasterCard

 Monday, November 2, 2015



Appreciate your concern even though you don't know me in person, I can assure you it's alright at my end, thanks.


photo

 Michael U., Senior Consultant at AWK Group

 Thursday, November 5, 2015



Hi Roy,

I have implemented a custom backtesting- and execution-engine for alto-trading based on tick-data for renko and candle-stick data.

Will implement you proposed strategy and share the results with you.

Regards

Michael


photo

 Roy Meshulam, Customer Delivery Manager at MasterCard

 Thursday, November 5, 2015



Hi Michael,

Excellent, I can send you the relevant MQL4 files per email if you'd like to have a starting point, feel free to PM me.

Roy


photo

 Johann Christian L., CEO

 Friday, November 6, 2015



@Oleksandr - I would not go as far as to disqualify traders as bottle-washers. In your restaurant scenario, at least a few traders can certainly be used as busboys. ;)


photo

 Tumiran T., Sumatra Onshore Gas Operations Field Manager at ConocoPhillips Indonesia

 Saturday, November 7, 2015



Roy, can I have a look at your EA?


photo

 Dmytro S., Snr Software Engineer, Freelancer

 Saturday, November 7, 2015



The Grid works fine. Every second trader wrote a grid system. The problem is that to survive at least 10-W turns, trader needs about 3000 per each 0.01 lot. Otherwise multiplication factor will ruin it. On the other hand, without pyramiding at stop loss price, the Grid is not profitable. Pyramiding is ok in this particular case, as multiplication happens in the same direction to a new trend


photo

 Roy Meshulam, Customer Delivery Manager at MasterCard

 Saturday, November 7, 2015



Sure Tumiran, please PM me your details and I'll send you the files.


photo

 eric P., gerant chez azs

 Saturday, November 7, 2015



(int)... thank's, you just allow me to clear all the compiler "Warning". ;-)


photo

 eric P., gerant chez azs

 Saturday, November 7, 2015



Not sure if it is "highly fruitful" but i found that :

NewSL=NormalizeDouble(OrderStopLoss()+(MarketInfo(argSymbol,MODE_ASK)-OrderStopLoss()-(argGapFactor*argGap)),(int)MarketInfo(argSymbol,MODE_DIGITS));

OrderStopLoss()-OrderStopLoss() = 0 => Useless

(int)MarketInfo(argSymbol,MODE_DIGITS) => Does not change on the fly, might be calculated one for all, at startup in Init() function in a tab... to save server requests.

The loop in "UpdateOrdersStopLoss" scann all open orders to treat one specifique case, number of open orders may be high. so it might be faster to scann all open orders one by one once, and call the "UpdateOrdersStopLoss" from the main MoneyManagement loop

Prior reading ASK or BID => RefreshRates();

if distance ... => if distance... && ( Distance > MinDistance ) cf MODE_STOPLEVEL / MODE_FREEZLEVEL.

Why PM ? some ideas make new ideas... ;-)


photo

 Roy Meshulam, Customer Delivery Manager at MasterCard

 Sunday, November 8, 2015



I actually use dynamic stop loss to limit the downside risk of each order the grid opens, starting with a distance of 3*grid gap to avoid early closure. The problem I face is noise and how to reduce to avoid it, I was thinking to add another indicator to confirm the grid direction like 50 days moving average position relative to the 200 days, any other suggestion?


photo

 Roy Meshulam, Customer Delivery Manager at MasterCard

 Sunday, November 8, 2015



Dmytro, what do you mean by 3000?


photo

 Corvin Codirla, Fund Manager of CCFX at Partner Capital

 Sunday, November 8, 2015



Here is a way to get out of trouble on grids: get out of the way of kurtosis. The thing about grid systems is that the PL is directly proportional to the realized volatility in the market. What gets you is when you have a spike in vol, which means a fat tail, and that kills you. Great example: the last two weeks on EURUSD or GBPUSD. So how do you avoid this? Price action is not sufficient. You can look at events that will knock the currency off its feet. A good starter is to halt trading during central bank announcement. Makes a hell of a difference.


photo

 Oleksandr Medviediev, Portfolio Analyst – FIBI

 Sunday, November 8, 2015



@Dmytro, I would agree with your approach to have $3,000 available equity per 0.01 lot, which translates to 0.3 initial lot-size on ~90K deposit for grid system. In principle Grid, as one of the methods that work for automated trading - is very popular indeed, approx 10-15% of all traders enjoy grids for obvious reason - core idea is very straightforward. Works well for manual trades too when using supplemental tools (http://bit.ly/1MQUM4W).


Few years ago I myself used to run grid system on 100K real-account using 1.0 lot-size. When DD hit 25% treshold - system was deactivated. Lesson learned:


(1) Always leave extra room for long trends (in my case 0.1-0.3 lot).


(2) Consider dynamically hedged or directional grids (http://bit.ly/1PwwDiN).


(3) Make sure your have (i) reliable internet connection, and (ii) EA that detects lost connection with broker-server (could happen for various reasons) and keeps re-connecting every 2-3 seconds until it connects. Because if for whatever reason next trade in series is not opened where it should - sometimes the entire strategy collapses.


@Roy, item 3(ii) is for you, to make sure it's included in the code. This is just a tiny sample of all possible traps//glitches that you have yet to figure out.


photo

 Roy Meshulam, Customer Delivery Manager at MasterCard

 Sunday, November 8, 2015



Thanks Oleksandr, can you please share a piece of MQL4 code which does reconnection? I know the function IsConnected() only return true/false for the status but I did not find a function call to connect. Are you using some Dll?


photo

 Oleksandr Medviediev, Portfolio Analyst – FIBI

 Monday, November 9, 2015



None Dll in my league. This particular "reconnecting" function is included in (MQL4/Include folder - see sample in PM).

Please login or register to post comments.

TRADING FUTURES AND OPTIONS INVOLVES SUBSTANTIAL RISK OF LOSS AND IS NOT SUITABLE FOR ALL INVESTORS
Terms Of UsePrivacy StatementCopyright 2018 Algorithmic Traders Association