Download MetaTrader 5

Momentum Trading EA Help

To add comments, please log in or register
Have you just installed MetaTrader 5? Learn it in details!
C0mput3r
168
C0mput3r 2016.11.17 17:15 

Hi Guys,

I have been trading on OANDA for years but am new to Autotrading platforms. I want to write an EA that will do the following but I have no idea where to start:

  • After 5 consecutive positive ticks (5 green 1-second candles), It should enter a long trade with the maximum units available (based on my current balance). With a TP of 3% (of current balance) and SL of -10% (of current balance).  
  • After 5 consecutive negative ticks (5 red 1-second candles), It should enter a short trade with the maximum units available (based on my current balance). With a TP of 3% (of current balance) and SL of -10% (of current balance).
There are a couple of things I want to mention/ask.

  • Yes I know 3% TP and -10% SL sounds crazy and is a massive negative risk-reward ratio, but I have run backtesting on millions of lines of historical 1 second data through VBA coding and the strategy is very profitable, as on a micro time-frame after a small trend is established the probability of reaching 3% TP is exponentially higher than hitting -10%, provided you use a leverage of no more than 50 and enter the maximum available units on every trade. 
  • As I have always used OANDA, I am used to trading custom amount of units and not standard lots, mini lots etc. I have been playing around with MT4 and seen that you can't customise the exact amount of units (for example 4351 units, if that's what is available with your current balance in your account.) This is a serious drawback to my strategy and the only way to counter this is have the EA calculate what the maximum amount of micro lots can be traded with the current account balance and calculate where to place TP and SL levels so that combined the trades make up either 3% or -10%. Unless ofcourse there is any possible way to write the EA to use the available lots?? If not, then once a buy/sell entry parameter is reached, the EA should trade as many of the smallest lots (I'm assuming micro lots) as possible at the same time.
  • If the maximum available units (or as close to as possible) are not used, then to reach a target of 3%, the TP would have to be placed too far away from the entry point, cancelling out the effect of the short term trend.
  • As the idea would be to use (almost) all available units per trade, it should not be possible to enter short trade while a long trade is still open.
  • I want to trade EUR/USD primarily as it is the most liquid, but wish to later diversify across currencies, commodities and indices.  
  • I know that MT4 does not provide 1-second charts but have found some that people have created for MT4 online but cannot get them to work.
  • The maximum available units are calculated as (Current Balance in your account Current price of EUR/USD) x Leverage - 1 
I would really appreciate any help on this as to where to start or even maybe a template from which to work from as I am proficient in coding R and VBA so I'll pick it up relatively easy.

Thanks in advance and happy trading!

Kind regards,

Anton. 

rajasmasala
66
rajasmasala 2016.11.17 19:30  

Hi, maybe I can suggest a small update to your basic idea.

 (This is still an extremely optimistic approach).

Use Kelly sizing to find the best bet size for your account so you don't risk ruin:

K = (B*W-L)/B 

 

B=Average Win/Average loss=3%/10% =0.3

W=Win rate = Approaching 100% = 0.99

L=Loss rate = Approaching 0 = 0.01

Optimal bet size K = (0.3*0.99-0.01)/0.3 = 95.67%

This trade size would be viewed as the utter cliff-edge of aggressize lotsizing.

A more normal approach assuming what you have said would be the half-kelly, or 95.67%/2 = 47.83% 

C0mput3r
168
C0mput3r 2016.11.18 09:28  
rajasmasala:

Hi, maybe I can suggest a small update to your basic idea.

 (This is still an extremely optimistic approach).

Use Kelly sizing to find the best bet size for your account so you don't risk ruin:

K = (B*W-L)/B 

 

B=Average Win/Average loss=3%/10% =0.3

W=Win rate = Approaching 100% = 0.99

L=Loss rate = Approaching 0 = 0.01

Optimal bet size K = (0.3*0.99-0.01)/0.3 = 95.67%

This trade size would be viewed as the utter cliff-edge of aggressize lotsizing.

A more normal approach assuming what you have said would be the half-kelly, or 95.67%/2 = 47.83% 

Hi,

Thanks for replying. I have never heard of the kelly sizing approach. I makes a lot of sense and I will definitely incorporate it into my model once I get it up and running!

Could you possibly give me any guidelines or an template of how to write my code for the EA? I'm completely new to MT4 programming and not sure where to start?

I just need a template that would execute a trade after 5 consecutive green ticks/ red ticks and get out after reaching a TP or SL. If I could just find that somewhere then I could optimize it to fulfill all my parameters.

Thanks again,

 Anton 

To add comments, please log in or register