//+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { int handle = FileOpen("file.csv", FILE_CSV|FILE_WRITE, ";"); if(handle>0) { // table column headers recording FileWrite(handle, "Time;Open;High;Low;Close;Volume"); // data recording for(int i=0; i<Bars; i++) FileWrite(handle, Time[i], Open[i], High[i], Low[i], Close[i], Volume[i]); FileClose(handle); } double ma; int res; //--- go trading only for first tiks of new bar if(Volume[0]>1) return; //--- get Moving Average ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0); //--- //pips double a = MathAbs(Close[0]-Open[0]); string b = DoubleToStr( NormalizeDouble( ( a/( 1*Point ) ),3 ),3 ); double p = StrToDouble(b); printf(DoubleToStr(a)); //average double rosoku = 0; double sum_rosoku =0; double count =0; double average =0; for(int j=1;j<=21;j++) { double a1 = MathAbs(Close[j]-Open[j]); string b1 = DoubleToStr( NormalizeDouble( a1/ (1*Point ),3 ),3 ); double e1 = StrToDouble(b1); rosoku = e1; sum_rosoku += rosoku; count++; } if(count == 21 ) { average = sum_rosoku/count; } //--- sell conditions if(Open[1]>ma && Close[0]<ma && a*2.0>average) { res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); return; } //--- buy conditions if(Open[1]<ma && Close[0]>ma && a*2.0>average) { res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue); return; } //--- }
double a = MathAbs(Close[0]-Open[0]);
I tried it but it's not effect. ↑ a=0
How many times must we explain to you ... https://www.mql5.com/en/forum/429285, that when a new bar is formed (i.e. first tick of a bar), that open and close are the same and that, "Close[0] - Open[0]" will be zero.
There is no way around that. It is a fact of trading. You should not be comparing Close[0] to Close[1], but instead Close[1] to Close[2].
- 2022.07.23
- www.mql5.com
How many times must we explain to you ... https://www.mql5.com/en/forum/429285, that when a new bar is formed (i.e. first tick of a bar), that open and close are the same and that, "Close[0] - Open[0]" will be zero.
There is no way around that. It is a fact of trading. You should not be comparing Close[0] to Close[1], but instead Close[1] to Close[2].
I want to write a code that I want to entry possition when current bar is X times the average Pips in the past, is that impossible?
I did that when I created the arrow indicator before, But when it comes to EA, I can't do that
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Close [0] is not working in the Expert Advisor void CheckForOpen (). The value of Close [0] is the opening price. How can I get Close [0]? Close [1] can get the correct value.