//+------------------------------------------------------------------+ //| Gorez002.mq4 |MACD 0以下売り シグナル0以上クローズ //| EA | //| alohafx | //+------------------------------------------------------------------+ #property copyright "alohafx" extern int MagicNumber = 2008112901; extern double TakeProfit = 0; extern double StopLoss = 0; extern int Slippage = 3; int POS_n_total = 0; int ticket, i; double Lots = 3; int start() { if(Bars<100 || IsTradeAllowed() != true) return(0); count_position(); if(POS_n_total > 0) { Close_MACD(); return(0); } else { Call_MACD(); Call_Bid(); Call_Trade(); } return(0); } int POS_n_BUY, POS_n_SELL; void count_position() { POS_n_BUY = 0; POS_n_SELL = 0; for( int i = 0 ; i < OrdersTotal() ; i++ ){ if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ){ break; } if( OrderMagicNumber() != MagicNumber ){ continue; } if( OrderSymbol() != Symbol() ){ continue; } if( OrderType() == OP_BUY ){ POS_n_BUY++; } else if( OrderType() == OP_SELL ){ POS_n_SELL++; } } POS_n_total = POS_n_BUY + POS_n_SELL; return(0); } extern int TF =5; extern int fMAperiod =5; extern int sMAperiod =21; extern int SIGperiod =20; extern int SHIFTs =0; extern int SHIFTm =0; int TimeFrame; double MACDm0, MACDm1, MACDs0, MACDs1; bool MACD_sell; void Close_MACD() { if(TF==0)TimeFrame=0; if(TF==1)TimeFrame=1; if(TF==2)TimeFrame=5; if(TF==3)TimeFrame=15; if(TF==4)TimeFrame=30; if(TF==5)TimeFrame=60; if(TF==6)TimeFrame=240; if(TF==7)TimeFrame=1440; if(TF==8)TimeFrame=10080; if(TF==9)TimeFrame=43200; MACDs0=iMACD(NULL,TimeFrame,fMAperiod,sMAperiod,SIGperiod,PRICE_CLOSE,MODE_SIGNAL,0+SHIFTs); MACDs1=iMACD(NULL,TimeFrame,fMAperiod,sMAperiod,SIGperiod,PRICE_CLOSE,MODE_SIGNAL,1+SHIFTs); if(MACDs0>0 && MACDs1<0) OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); return(0); } void Call_MACD() { MACDm0=iMACD(NULL,TimeFrame,fMAperiod,sMAperiod,SIGperiod,PRICE_CLOSE,MODE_MAIN,0+SHIFTm); MACDm1=iMACD(NULL,TimeFrame,fMAperiod,sMAperiod,SIGperiod,PRICE_CLOSE,MODE_MAIN,1+SHIFTm); if(MACDm1>0 && MACDm0<0) MACD_sell=true; else MACD_sell=false; return(0); } bool BID_sell; void Call_Bid() { double Pbid=iLow(NULL,PERIOD_H1,1); if(Pbid>Bid) BID_sell=true; else BID_sell=false; return(0); } double TakeP, StopL; void Call_Trade() { if(Volume[0]>1) return(0); if (BID_sell && MACD_sell) { if(TakeProfit>0) TakeP=Bid-TakeProfit *Point; else TakeP=0; if(StopLoss>0) StopL=Bid+StopLoss *Point; else StopL=0; ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,StopL,TakeP,"Sell",MagicNumber,0,Red); if (ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("Sell order opened : ",OrderOpenPrice()," Free Margin = ", AccountFreeMargin()," TakeProfit:",TakeP," StopLoss:",StopL); } else { Print("Error opening Sell order : ",GetLastError()); } } return(0); }