//+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma_cur; double ma_prev1; double ma_prev2; //---- go trading only for first tiks of new bar if(Volume[0] > 1){ return; } //---- get Moving Average ma_cur = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 0); ma_prev1 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 1); ma_prev2 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 2); //---- buy conditions if(touch_bottom(ma_cur, ma_prev1, ma_prev2)) { OrderSend(Symbol(), OP_SELL, NormalizeDouble(AccountFreeMargin()*0.1/1000.0,1), Bid, 3, 0, 0, "", MAGICMA, 0, Blue); return; } //---- sell conditions if(touch_top(ma_cur, ma_prev1, ma_prev2)) { OrderSend(Symbol(), OP_BUY, NormalizeDouble(AccountFreeMargin()*0.1/1000.0,1), Ask, 3, 0, 0, "", MAGICMA, 0, Red); return; } //---- }
//+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma; //--- 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); //--- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //--- check order type if(OrderType()==OP_BUY) { if(Open[1]>ma && Close[1]<ma) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White)) Print("OrderClose error ",GetLastError()); } break; } if(OrderType()==OP_SELL) { if(Open[1]<ma && Close[1]>ma) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White)) Print("OrderClose error ",GetLastError()); } break; } } //--- }
//+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma_cur; double ma_prev1; double ma_prev2; //---- go trading only for first tiks of new bar if(Volume[0] > 1) { return; } //---- get Moving Average ma_cur = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 0); ma_prev1 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 1); ma_prev2 = iMA(NULL, 0, MA_PERIOD, 0, MODE_SMA, PRICE_CLOSE, 2); //---- for(int i = 0;i < OrdersTotal();i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false){ break; } if(OrderMagicNumber() != MAGICMA || OrderSymbol() != Symbol()){ continue; } //---- check order type if(OrderType() == OP_BUY) { if(cross_below(ma_cur, ma_prev1) || touch_bottom(ma_cur, ma_prev1, ma_prev2) || OrderProfit() > AccountFreeMargin()*(-0.07)){ OrderClose(OrderTicket(), OrderLots(), Bid, 3, White); } break; } if(OrderType() == OP_SELL) { if(cross_above(ma_cur, ma_prev1) || touch_top(ma_cur, ma_prev1, ma_prev2)|| OrderProfit() > AccountFreeMargin()*(-0.07)){ OrderClose(OrderTicket(), OrderLots(), Ask, 3, White); } break; } } //---- }
//+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { 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); //--- sell conditions if(Open[1]>ma && Close[1]<ma) { res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); return; } //--- buy conditions if(Open[1]<ma && Close[1]>ma) { res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue); return; } //--- }
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Get handle for ADX indicator adxHandle=iADX(NULL,0,ADX_Period); //--- Get the handle for Moving Average indicator maHandle=iMA(_Symbol,_Period,MA_Period,0,MODE_EMA,PRICE_CLOSE); //--- What if handle returns Invalid Handle if(adxHandle<0 || maHandle<0) { Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!"); return(-1); } //--- Let us handle currency pairs with 5 or 3 digit prices instead of 4 STP = StopLoss; TKP = TakeProfit; if(_Digits==5 || _Digits==3) { STP = STP*10; TKP = TKP*10; } return(0); }
double calcularIndicador(string symbol, int timeframe, int indicNum, int shift) { // calcula el indicador indicnum con sus params y retorna su valor. if (indicNum==0) return(iAC(symbol, timeframe, shift)); else if (indicNum==1) return(iAD(symbol, timeframe, shift)); else if (indicNum==2) return(iAlligator(symbol, timeframe, 13, 8, 8, 5, 5, 3, MODE_EMA, PRICE_MEDIAN, MODE_GATORJAW, shift)); else if (indicNum==3) return(iADX(symbol,timeframe,14,PRICE_HIGH,MODE_PLUSDI,shift)); else if (indicNum==4) return(iATR(symbol,timeframe, 12, shift)); else if (indicNum==5) return(iAO(symbol, timeframe, shift)); else if (indicNum==6) return(iBearsPower(symbol, timeframe, 13,PRICE_CLOSE,shift)); else if (indicNum==7) return(iBands(symbol,timeframe,20,2,0,PRICE_LOW,MODE_LOWER,shift)); else if (indicNum==8) return(iBullsPower(symbol,timeframe, 13,PRICE_CLOSE,shift)); else if (indicNum==9) return(iCCI(symbol,timeframe,20,PRICE_TYPICAL,shift)); else if (indicNum==10) return(iDeMarker(symbol,timeframe, 13, shift)); else if (indicNum==11) return(iEnvelopes(symbol,timeframe, 13,MODE_EMA,10,PRICE_CLOSE,0.2,MODE_UPPER,shift)); else if (indicNum==12) return(iForce(symbol, timeframe, 13,MODE_EMA,PRICE_CLOSE,shift)); else if (indicNum==13) return(iFractals(symbol,timeframe, MODE_UPPER, shift)); else if (indicNum==14) return(iGator(symbol,timeframe, 13, 8, 8, 5, 5, 3, MODE_EMA, PRICE_MEDIAN, MODE_UPPER, shift)); else if (indicNum==15) return(iIchimoku(symbol,timeframe, 9, 26, 52, MODE_TENKANSEN, shift)); else if (indicNum==16) return(iBWMFI(symbol,timeframe,shift)); else if (indicNum==17) return(iMomentum(symbol,timeframe,20,PRICE_CLOSE,shift)); else if (indicNum==18) return(iMFI(symbol,timeframe,14,shift)); else if (indicNum==19) return(iMA(symbol,timeframe,13,8,MODE_EMA,PRICE_MEDIAN,shift)); else if (indicNum==20) return(iOsMA(symbol,timeframe,12,26,9,PRICE_MEDIAN,shift)); else if (indicNum==21) return(iMACD(symbol,timeframe,12,26,9,PRICE_CLOSE,MODE_MAIN,shift)); else if (indicNum==22) return(iOBV(symbol, timeframe, PRICE_CLOSE, shift)); else if (indicNum==23) return(iSAR(symbol,timeframe,0.02,0.2,shift)); else if (indicNum==24) return(iRSI(symbol,timeframe,14,PRICE_CLOSE,shift)); else if (indicNum==25) return(iRVI(symbol, timeframe, 10,MODE_MAIN,shift)); else if (indicNum==26) return(iStdDev(symbol,timeframe,10,0,MODE_EMA,PRICE_CLOSE,shift)); else if (indicNum==27) return(iStochastic(symbol,timeframe,5,3,3,MODE_EMA,0,MODE_SIGNAL,shift)); else if (indicNum==28) return(iWPR(symbol,timeframe,14,shift)); else if (indicNum==29) return(iClose(symbol,timeframe,shift)); else if (indicNum==30) //Tamaño de candlestick return(iHigh(symbol,timeframe,shift)-iLow(symbol,timeframe,shift)); else if (indicNum==31) //Color y tamaño de cuerpo return(iClose(symbol,timeframe,shift)-iOpen(symbol,timeframe,shift)); else { Print("Error en calcularIndicador() indice no encontrado"); return(0); } }