DNC

 

Hello all,

I'm writing my first EA with no background experience, just learning it as I go and its coming on quite nicely- but im struggling on one area.

I want to take only long positions when price has broken above the high of the preceeding 120 bars and go short when it has broken below the low of the preceeding 120 bars.

I cant think of a way to code this. I've done this so far but I know it work:

int DNCPeriod = 120

DNCLow = Low[iLowest("EURUSD",PERIOD_H4,MODE_LOW,DNCPeriod,0)];

DNCHigh = High[iHighest("EURUSD",PERIOD_H4,MODE_LOW,DNCPeriod,0)];

And then as part of my if statement for my going long criteria I include ...&& Ask > DNCHigh.

But I know this won't work. Any suggestions??

Thanks

 

Search this site for "Donchian Channel" EA or google it and you will get many. Study them or modify them as per your requirement...

 

I've noticed iCustom. Going to use this for my Donchian Channel. I was wondering whether it takes the period from the donchian installed on the chart as it doesnt have an area to include it under iCustom?

Also I am using MACD but not the standard one on MT4 but another that shows both the MACD and Signal Line, which was downloaded. Will iMACD work with this or would I need to use iCustom? Thanks.

 

Also when im compiling it gives me this error: 'extern' - comma or semicolon expected

When I double click it it highlights this field: extern double SlowSMAPeriod = 200; // Slow SMA period on daily chart

I have other externs written in the same way but its only flagged a problem with this one.

 
It works correctly. DNCLow, DNCHigh must be type double
CHRI1111:

Hello all,

I'm writing my first EA with no background experience, just learning it as I go and its coming on quite nicely- but im struggling on one area.

I want to take only long positions when price has broken above the high of the preceeding 120 bars and go short when it has broken below the low of the preceeding 120 bars.

I cant think of a way to code this. I've done this so far but I know it work:

int DNCPeriod = 120

DNCLow = Low[iLowest("EURUSD",PERIOD_H4,MODE_LOW,DNCPeriod,0)];

DNCHigh = High[iHighest("EURUSD",PERIOD_H4,MODE_LOW,DNCPeriod,0)];

And then as part of my if statement for my going long criteria I include ...&& Ask > DNCHigh.

But I know this won't work. Any suggestions??

Thanks

 
CHRI1111:

int DNCPeriod = 120

DNCLow = Low[iLowest("EURUSD",PERIOD_H4,MODE_LOW,DNCPeriod,0)];

DNCHigh = High[iHighest("EURUSD",PERIOD_H4,MODE_LOW,DNCPeriod,0)];


  1. "'extern' - comma or semicolon expected." Look at the statement ABOVE the error. Missing semicolon after the 120
  2. Don't write long hard to read lines. Break it down so you can understand it
    int iLL =  iLowest("EURUSD", PERIOD_H4, MODE_LOW, DNCPeriod, 0),
        iHH = iHighest("EURUSD", PERIOD_H4, MODE_LOW, DNCPeriod, 0);
    double DNCLow  =  Low[iLL];
    double DNCHigh = High[iHH]; 
    Note now you can see that the iHighest should not be using MODE_LOW.
  3. By hard coding the EURUSD and H4, your code can not run on any other pair or TF and may not run on other brokers (if they use EUR.USD, EUR/USD, EURUSDm, or some other naming convention.) Don't hard code:
    iHH = iHighest(Symbol(),0, MODE_HIGH, DNCPeriod, 0)

  4. " Ask > DNCHigh." will always be false because your iLowest/iHighest includes the current bar. Change to 1.
 

Thanks WHRoeder. I really appreciate your help.

 

I have the following code:

double Donchian_Low = Low[iLowest(Symbol(), PERIOD_H4, MODE_LOW, DNCPeriod, 1)];
double Donchian_High = High[iHighest(Symbol(), PERIOD_H4, MODE_HIGH, DNCPeriod, 1)];

Where int DNCPeriod = 120;

Than further down as my entry criteria I have

if (Ask > Donchian_High &&... and it continues... )

What happens if the Ask price than falls back below the high of the preceeding 120 periods? In such a scenario I still want it to take long positions, only when it falls below the low of the preceeding 120 periods do I not want it to go long. Would this coding work?

 
CHRI1111:

What happens if the Ask price than falls back below the high of the preceeding 120 periods? In such a scenario I still want it to take long positions, only when it falls below the low of the preceeding 120 periods do I not want it to go long. Would this coding work?

  1. When the ask goes above the previous high, you open an order. So what if ask falls back, the order is already open.
  2. Why did you ask this question? Why didn't you run it in visual mode in the tester to find out the answer?
 

Hello WHRoeder. No the purpose of my Donchian Channel in this instance is not to open an order, but to use it as a strategy to search for long positions. Only when it breaks the lower band will it stop searching for long positions.

I didn't run it in visual mode as I am unable to compile; still working my way through the errors in my coding.

Reason: