Where are the doubles?

 

Another time that I cannot write an EA without coming to this forum for aid. ;(

At least you all can see how well I have progressed! ;)

Compiling the tops and bottoms over a set amount of bars is failing me :(

See:

Code:

#property copyright "Copyright 2012, bmel_12.25.81"
#property link      "http://www.metaquotes.net"
#include <IBFX - Quick Scripts.mqh>
extern string    BAR="Set bars from current bar";
extern int           BARS=2;
extern string    EA_="Set EA parameters accordingly";
extern double        LOT=0.1;
extern int           TF=30, TP=15, SL=30;
extern string    EA_LIVE="Set EA forward testing parameters";
extern int           retries=3, slippage=3;
int barz, MN=5;
string signal="N/A", OC;
//+------------------------------------------------------------------+
int init(){
  OC="TF:"+TF+",TP:"+TP+",SL:"+SL;
  Comment("::EA_Comments::");
return(0);}
//+------------------------------------------------------------------+
int start(){
  //INDICATOR VALUES
  double tops, bottoms;
  for(barz = 0; barz == BARS; barz++){
    tops = tops + High[barz]-Close[barz];
    bottoms = bottoms + Open[barz]-Low[barz];
    }
    //SIGNAL TO TRADE = BUY
    if(bottoms > tops && (signal == "Sell" || signal == "N/A") ){
      signal = "Buy";
      //CLOSE EXISTING ORDER BEFORE OPENING A NEW ORDER
      if(OrdersTotal() > 0){ CloseAll(Symbol(),MN,OP_SELL,retries,slippage,OC); }
      //BUY ORDER
      EnterLong(Symbol(),LOT,OC,SL,TP,MN,retries,slippage);
      }
    //SIGNAL TO TRADE = SELL
    if(tops > bottoms && (signal == "Buy" || signal == "N/A") ){
      signal = "Sell";
      //CLOSE EXISTING ORDER BEFORE OPENING A NEW ORDER
      if(OrdersTotal() > 0){ CloseAll(Symbol(),MN,OP_BUY,retries,slippage,OC); }
      //SELL ORDER
      EnterShrt(Symbol(),LOT,OC,SL,TP,MN,retries,slippage);
      }
  //EA_COMMENT
  Comment("::EA_Comments::" +
  "\n" + "Tops = " + DoubleToStr(tops,5) + 
  "\n" + "Bottoms = " + DoubleToStr(bottoms,5) +
  "\n" + "Trade Signal: " + signal);
return(0);}
//+------------------------------------------------------------------+
int deinit(){
return(0);}
 
for(barz = 0; barz <= BARS; barz++){
 
qjol:
for(barz = 0; barz <= BARS; barz++){

I totally get it..I was just missing the point! Now lets see if it blows up my account!

 
Dont color your code, its difficult to understand. Post the error you are getting...
 
dineshydv:
Dont color your code, its difficult to understand. Post the error you are getting...

Yep, I blew it up. I added an iBar now it trades less maniacly.

dineshydv; What do you mean color my code?

To give you an answer there the error was that, as you could see from the EA_Comments, the "tops" & "bottoms" had no values.

All is better now - now that I tried qjol suggestion.

The Code:

#property copyright "Copyright 2012, bmel_12.25.81"
#property link      "http://www.metaquotes.net"
#include <IBFX - Quick Scripts.mqh>
extern string    BAR="Set bars from current bar";
extern int           BARS=2;
extern string    EA_="Set EA parameters accordingly";
extern double        LOT=0.1;
extern int           TF=30, TP=15, SL=30;
extern string    EA_LIVE="Set EA forward testing parameters";
extern int           retries=3, slippage=3, magicnumber=5;
int iBar, barz, k;
string signal="N/A", OC, candletime;
//+------------------------------------------------------------------+
int init(){
  iBar=iTime(Symbol(),Period(),0); 
  OC="TF:"+TF+",TP:"+TP+",SL:"+SL;
return(0);}
//+------------------------------------------------------------------+
int start(){
  //INDICATOR VALUES
  double tops, bottoms;
  for(barz = 0; barz <= BARS; barz++){
    tops = tops + (High[barz]-Close[barz]);
    bottoms = bottoms + (Open[barz]-Low[barz]);
    }
  //CHECK EVERY BAR
  if(iBar!=iTime(Symbol(),Period(),0)){
    //SIGNAL TO TRADE = BUY
    if(bottoms > tops && (signal == "Sell" || signal == "N/A") ){
      signal = "Buy";
      //CLOSE EXISTING ORDER BEFORE OPENING A NEW ORDER
      if(OrdersTotal() > 0){ CloseAll(Symbol(),magicnumber,OP_SELL,retries,slippage,OC); }
      //BUY ORDER
      EnterLong(Symbol(),LOT,OC,SL,TP,magicnumber,retries,slippage);
      }
    //SIGNAL TO TRADE = SELL
    if(tops > bottoms && (signal == "Buy" || signal == "N/A") ){
      signal = "Sell";
      //CLOSE EXISTING ORDER BEFORE OPENING A NEW ORDER
      if(OrdersTotal() > 0){ CloseAll(Symbol(),magicnumber,OP_BUY,retries,slippage,OC); }
      //SELL ORDER
      EnterShrt(Symbol(),LOT,OC,SL,TP,magicnumber,retries,slippage);
      }
  iBar=iTime(Symbol(),Period(),0); k=k+1;
  }
  //Candle Time
  int m=Time[0]+Period()*60-CurTime();
  double i=m/60.0;
  int s=m%60;
  m=(m-m%60)/60;
  candletime = m + " minutes " + s + " seconds";
  //EA_COMMENT
  if(k >=1){
  Comment("::EA_Comments::" +
  "\n" + "Tops = " + DoubleToStr(tops,5) + 
  "\n" + "Bottoms = " + DoubleToStr(bottoms,5) +
  "\n" + "Trade Signal: " + signal + 
  "\n" +
  "\n" + "Candle Time Left = " + candletime +
  "\n" + "Magic Number = " + magicnumber + 
  "\n" + "Timeframe = " + TF +
  "\n" + "Lot Size = " + LOT + 
  "\n" + "Takeprofit = " + TP +
  "\n" + "Stoploss = " + SL +
  "\n" + "Retries = " + retries +
  "\n" + "Slippage = " + slippage); 
  }
  else{Comment("#m30_candles.mq4 will begin trading in " + candletime );}
//colored lines
for( int n=ObjectsTotal()-1; n>=0; n-- ){
  string str= ObjectName(n);
  if( ObjectType(str) != OBJ_TREND ){continue;}
    if( StringGetChar(str,0) != '#' ){continue;}
  ObjectSet(str,OBJPROP_COLOR,White);
  }
return(0);}
//+------------------------------------------------------------------+
int deinit(){
  Comment("");
return(0);}
 
dineshydv:
Dont color your code, its difficult to understand. Post the error you are getting...

okay obviously you mean don't just paste the SRC but instead post the files such as the MQL4 file.


It's attached..Could you, or anybody, test it?
Files:
 
Subgenius:

okay obviously you mean don't just paste the SRC but instead post the files such as the MQL4 file.

I think he meant this . . .

Please use this to post code . . . it makes it easier to read.