[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 447

 
T-G >>:

а почему как функция не работает а в старте работает?

In fact, this is a function only it depends on what it is if(Close_){ - apply inside the start, if void Close_() { as a function that works outside the start.


void Close_() {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect( trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip, Blue);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip, Red);
}
Sleep(1000);
}
}
}
 
sergeev >>:


алгоритм у вас верный. сделайте распринтовку возможных ошибок и вообще ухзнать куда доходит эксперт при выполнении этого кода.

+ выведите расчитанные значения рси.

)))) I think the guy has a mistake in the code.....though I'm a newbie, I could be wrong.

 
There seems to be no error, just a small bug, and Sleep is unnecessary here :)
 
gince >>:

//во внешние перменные
extern bool Close_ =true; //использовать закрытие по РСИ вкл выкл. 
// в старт закиньте
if ( Close_){
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect( trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if ((OrderType() == OP_BUY)&&( rsi_1 > Level_2 && rsi_0 < Level_2)) OrderClose(OrderTicket(), OrderLots(), Bid, slip, Blue);
if ((OrderType() == OP_SELL)&&( rsi_1 < Level_1 && rsi_0 > Level_1)) OrderClose(OrderTicket(), OrderLots(), Ask, slip, Red);
}
Sleep(1000);
}
}
}
 

It's a standard Matsimple. I'm just trying to figure out why it's not closing correctly. I'm trying the logic for closing trades. One part consists of RSI-- that's why it's not working.


//if(Open[1]>ma_2 && Close[1]<ma_2) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         if( rsi_1 > Level_2 && rsi_0 < Level_2) {OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         Print( rsi_0,"     ", rsi_1);}
         break;
        }
      if(OrderType()==OP_SELL)
        {
         //if(Open[1]<ma_2 && Close[1]>ma_2) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         if( rsi_1 < Level_1 && rsi_0 > Level_1){OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
          Print( rsi_0,"     ", rsi_1);}
         break;

Changed the shifft after the printout.

rsi_0=iRSI( NULL,0,4, PRICE_CLOSE, 1 ); 
rsi_1=iRSI( NULL,0, 4, PRICE_CLOSE, 2 ) ;
 
Respected gurus!
Please don't let it go unnoticed.

I bought a HP laptop with Windows Vista preinstalledwith 64 bit OS.
Started having problems with the work of the EA. At the beginning my deals were opened somehow. But in a week my Expert Advisor stopped opening some deals completely. We tried and twisted it and finally decided that the problem was caused by 64 bits. We reinstalled the Expert Advisor and installed it on 32 bits and 7 Windows .It worked fine for one day and then failed again. Maybe i got some kind of update to windows that is affecting it?

On other computers (colleagues), the EA works without any interruptions at all. My old laptop is gone and I can't buy anything at the moment.

I am, by the way, working on Instatrader platform.

Please, if anyone has encountered or have any suggestions on how this can be fixed, please advise.

 

Help me re-do a simple EA, I've been struggling for a week!!!! Or write it again, all EAs are too complicated and I can't tweak it for me!

I want to add to this EA an MACD indicator, which sends its BUY and SELL signals and the EA has to do both at the same time. There should be not more than three open BUY and three open SELL orders. All orders should be closed by stoploss and takeprofit only, and not by force of the Expert Advisor.

//--------------------------------------------------------------------
extern int     period_EMA           = 28,
               period_WMA           = 8 ,
               stoploss             = 50,
               takeprofit           = 50,
               risk                 = 10;
double  LOT;
//--------------------------------------------------------------------
double SL, TP;
int TimeBar; //глобальная переменная
//--------------------------------------------------------------------
int start()
{
   if ( TimeBar==Time[0]) return(0);
   if ( TimeBar==0) { TimeBar=Time[0];return(0);}//первый запуск программы
   double EMA0 = iMA(NULL,0, period_EMA,0,MODE_EMA, PRICE_OPEN,0);
   double WMA0 = iMA(NULL,0, period_WMA,0,MODE_LWMA,PRICE_OPEN,0);
   double EMA1 = iMA(NULL,0, period_EMA,0,MODE_EMA, PRICE_OPEN,1);
   double WMA1 = iMA(NULL,0, period_WMA,0,MODE_LWMA,PRICE_OPEN,1);
   if ( EMA0< WMA0&& EMA1> WMA1) //Buy
   {
      TimeBar=Time[0];                            
      TP  = Ask + takeprofit*Point;
      SL  = Ask - stoploss*Point;     
      LOT = LOT( risk,1);
      CLOSEORDER("Sell");
      OPENORDER ("Buy");
   }
   if ( EMA0> WMA0&& EMA1< WMA1) //Sell
   {
      TimeBar=Time[0];                            
      TP = Bid - takeprofit*Point;
      SL = Bid + stoploss*Point;            
      LOT = LOT( risk,1);
      CLOSEORDER("Buy");
      OPENORDER ("Sell");
   }
return(0);
}
//--------------------------------------------------------------------
void CLOSEORDER(string ord)
{
   for (int i=OrdersTotal()-1; i>=0; i--)
   {                                               
      if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)==true)
      {
         if (OrderSymbol()!=Symbol()) continue;
         if (OrderType()==OP_BUY && ord=="Buy")
            OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);// Close Buy
         if (OrderType()==OP_SELL && ord=="Sell")
            OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);// Close Sell
      }   
   }
}
//--------------------------------------------------------------------
void OPENORDER(string ord)
{
   int error;
   if ( ord=="Buy" ) error=OrderSend(Symbol(),OP_BUY, LOT,Ask,2, SL, TP,"", 1,3);
   if ( ord=="Sell") error=OrderSend(Symbol(),OP_SELL, LOT,Bid,2, SL, TP,"",-1,3);
   if ( error==-1) //неудачная покупка OK
   {  
      ShowERROR( error,0,0);
   }
return;
}                  
//--------------------------------------------------------------------
void ShowERROR(int Ticket,double SL,double TP)
{
   int err=GetLastError();
   switch ( err )
   {                  
      case 1:                                                                               return;
      case 2:   Alert("Нет связи с торговым сервером   "              , Ticket," ",Symbol());return;
      case 3:   Alert("Error  неправильные параметры   Ticket ",       Ticket," ",Symbol());return;
      case 130: Alert("Error близкие стопы   Ticket ",                 Ticket," ",Symbol());return;
      case 134: Alert("Недостаточно денег   ",                         Ticket," ",Symbol());return;
      case 146: Alert("Error Подсистема торговли занята ",             Ticket," ",Symbol());return;
      case 129: Alert("Error Неправильная цена ",                      Ticket," ",Symbol());return;
      case 131: Alert("Error Неправильный объем ",                     Ticket," ",Symbol());return;
      case 4051:Alert("Error Недопустимое значение параметра функции ", Ticket," ",Symbol());return;
      case 4105:Alert("Error Ни один ордер не выбран ",                Ticket," ",Symbol());return;
      case 4063:Alert("Error Ожидается параметр типа integer ",        Ticket," ",Symbol());return;
      case 4200:Alert("Error Объект уже существует ",                  Ticket," ",Symbol());return;
      default:  Alert("Error  " , err,"   Ticket ",                     Ticket," ",Symbol());return;
   }
}
//--------------------------------------------------------------------
double LOT(int risk,int ord)
{
   double MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
   LOT = AccountFreeMargin()* risk/100/MarketInfo(Symbol(),MODE_MARGINREQUIRED)/ ord;
   if ( LOT>MarketInfo(Symbol(),MODE_MAXLOT)) LOT = MarketInfo(Symbol(),MODE_MAXLOT);
   if ( LOT< MINLOT) LOT = MINLOT;
   if ( MINLOT<0.1) LOT = NormalizeDouble( LOT,2); else LOT = NormalizeDouble( LOT,1);
   return( LOT);
}
//--------------------------------------------------------------------

 
Serg-s-n >>:

Помогите переделать простой советник, бьюсь неделю!!!! Или написать снова, а то все советники слишком сложные и я их не могу под себя подстроить!!

Суть такая: Хочу добавить в этот советник( торгующий на пересечении) ещё индикатор MACD, который подает свой сигнал на продажу и покупку и советник должен параллельно выполнять их. Открытых ордеров BUY не больше трех и SELL тоже трех. Все ордера должны закрываться только по stoploss и takeprofit, а не принудительно советником.

 double MacdMain0 = iMACD(NULL,0, period_fast, period_slow, period_signal,0,MODE_MAIN, PRICE_OPEN,0);
double MacdSignal0 = iMACD(NULL,0, period_fast, period_slow, period_signal,0,MODE_SIGNAL, PRICE_OPEN,0)
double MacdMain1 = iMACD(NULL,0, period_fast, period_slow, period_signal,0,MODE_MAIN, PRICE_OPEN,1)
double MacdSignal1 = iMACD(NULL,0, period_fast, period_slow, period_signal,0,MODE_SIGNAL, PRICE_OPEN,1);
if (EMA0< WMA0&& EMA1> WMA1 && MacdMain0 >MacdSignal0 && MacdMain1 <MacdSignal1)

well this will add macd like muwings

 
Everything is clear with this, but how do I set orders? In the original version, for example, we set Buy, and when a Sell signal is received, Buy is closed and Sell is set! And I do not need to close, the Expert Advisor should set orders with stops and that's it!
 

I have a question, or rather a request, on the same EA EMA_WMA.mq4 and also regarding closing. Is it possible instead of closing by Take Profit or in addition to that to add the possibility of closing an order by max/min value of MA. It seems to me that this would be the best way to exit the market, (although I may be wrong of course). Please add this feature to this EA.

Another small question, I get a message like this: "Error. Stops close", although my stop loss is set to 50 pips (MasterForex). What does it mean?

Reason: