Can't find error in logic
Why you complicate it in this way and you don't use a simple code like this?
void OnTick() { double MACD[]; ArraySetAsSeries(MACD,true); int MacDDefinition = iMACD(_Symbol,_Period,15,26,1,PRICE_CLOSE); CopyBuffer(MacDDefinition,0,0,3,MACD); double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); MqlRates PriceInfo[]; ArraySetAsSeries(PriceInfo,true); double MA1[], MA2[],MA3[]; ArraySetAsSeries (MA1, true); ArraySetAsSeries (MA2, true); ArraySetAsSeries (MA3, true); int MA1_Handle = iMA (_Symbol,_Period, 05,0,MODE_EMA,PRICE_CLOSE); int MA2_Handle = iMA (_Symbol,_Period, 75,0,MODE_EMA,PRICE_CLOSE); int MA3_Handle = iMA (_Symbol,_Period, 85,0,MODE_EMA,PRICE_CLOSE); CopyBuffer(MA1_Handle,0,0,3,MA1); CopyBuffer(MA2_Handle,0,0,3,MA2); CopyBuffer(MA3_Handle,0,0,3,MA3); //COMPRA------------------------------------------------------ if( PositionsTotal()==0 && MA1[0]>MA2[0] && MA1[0]>MA3[0] && MA1[1]<=MA2[1] && MA1[1]<=MA3[1] && MACD[1]>0 && MACD[2]<=0 ) { trade.Buy(1,NULL,Ask,Ask-300*_Point,Ask+300*_Point,NULL); } }
Seriously I can't understand people that use 20+ chars of variable's names...
Anyway the code, as is, is made for buying when there is a MA crossover on current candle and MACD changed from negative to positive on last 2 closed candles.
Really? You do the handle of indicator in ontick instead of oninit?
amando:
Really? You do the handle of indicator in ontick instead of oninit?
I didn't realized that...... He need to change also this part
Really? You do the handle of indicator in ontick instead of oninit?
Thank You very much!