Inserted Code
extern int ma1period=5; extern int ma1method=1; extern int ma1tf=0; extern int ma2period=5; extern int ma2method=1; extern int ma2tf=10080; extern double lots=1; int init(){} int deinit(){} double CMA (int tf,int period, int shift, int method) { double MA=iMA(NULL,tf,period,0,method,0,shift) return(MA) } int start() { int BarsCount=0; if (Bars> BarsCount) { BarsCount=Bars; double ma1.1=CMA(ma1tf,ma1period,1,ma1method); double ma1.2=CMA(ma1tf,ma1period,2,ma1method); double ma2.1=CMA(ma2tf,ma2period,1,ma2method); double ma2.2=CMA(ma2tf,ma2period,2,ma2method); bool ma1upsignal =ma1.2<ma1.1; bool ma1downsignal =ma1.2>ma1.1; bool ma2upsignal =ma2.2<ma2.1; bool ma2downsignal =ma2.2>ma2.1; if (ma1upsignal&&ma2upsignal) { OrderSend(Symbol(),OP_BUY,lots,Ask,3,NULL,NULL,NULL,NULL,0,Green); } if (ma1downsignal&&ma2downsignal) { OrderSend(Symbol(),OP_SELL,lots,Bid,3,NULL,NULL,NULL,NULL,0,Green); } if ((ma1upsignal&&ma2downsignal)||(ma1downsignal&&ma2upsignal)) { int total=OrdersTotal(); //Script to close all open orders. for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); switch(type) { //Close opened long positions case OP_BUY : OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); break; //Close opened short positions case OP_SELL : OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } } } }
This is the piece of code i'm working on. The compiler says "the variable BarsCount is not defined". What do i do? As far as I can see, the variable has been initialized and given a value.
Is it my compiler problem or code problem ?