Is there noboby who can help me? I don't understand why this code doesn't work:
double TrendUp[], TrendDown[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; int start() {int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //---- for (i = Bars; i >= 0; i--) { TrendUp[i] = EMPTY_VALUE; TrendDown[i] = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); medianPrice = (High[i]+Low[i])/2; up[i]=medianPrice+(Multiplier*atr); dn[i]=medianPrice-(Multiplier*atr); trend[i]=1; if (Close[i]>up[i+1]) { trend[i]=1; if (trend[i+1] == -1) changeOfTrend = 1; } else if (Close[i]<dn[i+1]) { trend[i]=-1; if (trend[i+1] == 1) changeOfTrend = 1; } else if (trend[i+1]==1) { trend[i]=1; changeOfTrend = 0; } else if (trend[i+1]==-1) { trend[i]=-1; changeOfTrend = 0; } if (trend[i]<0 && trend[i+1]>0) { flag=1; } else { flag=0; } if (trend[i]>0 && trend[i+1]<0) { flagh=1; } else { flagh=0; } if (trend[i]>0 && dn[i]<dn[i+1]) dn[i]=dn[i+1]; if (trend[i]<0 && up[i]>up[i+1]) up[i]=up[i+1]; if (flag==1) up[i]=medianPrice+(Multiplier*atr); if (flagh==1) dn[i]=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend[i]==1) { TrendUp[i]=dn[i]; if (changeOfTrend == 1) { TrendUp[i+1] = TrendDown[i+1]; changeOfTrend = 0; OrderSend(Symbol(),OP_BUY,1,Ask,3,Bid-40*Point,Ask+15*Point); } } else if (trend[i]==-1) { TrendDown[i]=up[i]; if (changeOfTrend == 1) { TrendDown[i+1] = TrendUp[i+1]; changeOfTrend = 0; OrderSend(Symbol(),OP_SELL,1,Bid,3,Ask+40*Point,Bid-15*Point); } } } return(0); }
Maier
Is there noboby who can help me? I don't understand why this code doesn't work:
Maier
i suggest that you debug it by printing messages at some stages to see how the program is actually running.
Your EA is not stable, to make it work fine with you, you must add a new bar open flag .
then it will work fine.
Another solution is to use iCustom function to write your EA without any problems .
The code you posted was of an indicator (auto arrays) but indicators can't open orders and EAs don't have auto arrays.
Ask+40*Point,Bid-15*Point
and that won't work on a 5 digit broker.
Hello
I found this indicator, too, and I think it's very interesting...
What dou you mean by "add a new bar open flag"? I am not a native speak and I have problems to understand that...but if I just use a short combination with iCustom it will work without big problems??
leMai
int start() { static datetime Time0; bool newBar = (CurTime() > Time0); if (newBar) { Time0 = Time[0]; // Reset static // Open new trades here - only at the start of the current bar. } return(0); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello
I want to write an EA for the indicator i attached and I've already tried it(second attachment). I just don't know why the EA doesn't go in the loop where the OrderSend-function is, but why it does in the indicator.
Is there anybody who can help me? Thank you...
Maier