[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 163

 
polsvv ,that's what magic is for.
 
vnn:

Hi all...

Could you please tell me how to build path to MetaTrader 4 history files? Like "c:\program files\metatrader 4\history\alpari-classic\"?

https://docs.mql4.com/ru/files/FileOpenHistory
 

Thank you very much, sergeev, I think I've found it...

Print("Terminal path: ", TerminalPath() + "\\history\\" + AccountServer() + "\\");

this line outputs the correct path even though the editor is wrong in the colours... You should probably write the code in notepad. Just kidding.

 

Good evening everyone!

In Sergey Kovalev's tutorial I found an expert - trailing stop. I copied it into MetaEditor, compiled it, but the program does not work. Please advise what is the reason. Maybe I am doing something wrong.

 

is it written in mql?)

just give me the code.

 
Guys, explain to me how to use iCustom
I am writing
double BBUP =iCustom(NULL, 0, "Bands", "BandsPeriod", "BandsShift", "BandsDeviations",1,0);
double BBDW =iCustom(NULL, 0, "Bands", "BandsPeriod", "BandsShift", "BandsDeviations",2,0);
I can't get it right ...
I have a task to get signals from Bands indicator upper and lower line...... Exactly Bands.....
 
//-------------------------------------------------------------------- // modifystoploss.mq4 // Designed to be used as an example in the MQL4 tutorial. //-------------------------------------------------------------------- extern int Tral_Stop=10; // Dist. pursuit //--------------------------------------------------------------- 1 -- int start() // Special function start { string Symb=Symbol(); // Fin. tool //--------------------------------------------------------------- 2 -- for(int i=1; i<=OrdersTotal(); i++) // Order loop { if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is a next { // Order analysis: int Tip=OrderType(); // Order type if(OrderSymbol()!=Symb||Tip>1)continue;// Not our order double SL=OrderStopLoss(); // SL of the selected order //------------------------------------------------------ 3 -- while(true) // Modification loop { double TS=Tral_Stop; // Initial value int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);// Minimal dist. if (TS<Min_Dist) // If there is less than the allowed value, then the order will be deleted.
               TS=Min_Dist; // New value of TS //--------------------------------------------------- 4 -- bool Modify=false; // Not assigned to modify switch(Tip) // By order type { case 0 : // Buy order if (NormalizeDouble(SL,Digits)< // If lower desired.
                     NormalizeDouble(Bid-TS*Point,Digits)) { SL=Bid-TS*Point; // then modify it string Text="Buy "; // text for Buy Modify=true; // assigned to modify } break; // exit if case 1 : // Sell order if (NormalizeDouble(SL,Digits)> // if above requested.
                     NormalizeDouble(Ask+TS*Point,Digits)|| NormalizeDouble(SL,Digits)==0)//or equal to zero { SL=Ask+TS*Point; // then modify it Text="Sell "; // Modify=true; // assigned to modify } } // end switch if (Modify==false) // if not modified break; // exit while //--------------------------------------------------- 5 -- double TP =OrderTakeProfit(); // TP of selected order.
            double Price =OrderOpenPrice(); // Price of the selected order. int Ticket=OrderTicket(); // Number of the selected order. Alert ("Modify ",Text,Ticket,". Waiting for reply..."); bool Ans=OrderModify(Ticket,Price,SL,TP,0);//Modify it!
            //--------------------------------------------------- 6 -- if (Ans==true) // It worked :) { Alert ("Order ",Text,Ticket," modified:)"); break; // From the loop modify.
              } //--------------------------------------------------- 7 -- int Error=GetLastError(); // failed :( switch(Error) // Overcome errors { case 130:Alert("Wrong stops. Try again."); RefreshRates(); // Refresh data continue; // Next iteration. iteration case 136:Alert("No price. Waiting for a new tick..."); while(RefreshRates()==false) // Till the new tick Sleep(1); // Delay in loop continue; // Next iteration case 146:Alert("The trading subsystem is busy.Try again"); Sleep(500); // Simple solution RefreshRates(); // Refresh data continue; // Next iteration // Critical errors case 2 : Alert("General error."); break; // Exit switch case 5 : Alert("Old client terminal version."); break; // Exit switch case 64 : Alert("Account blocked."); break; // Exit switch case 133:Alert("Trading prohibited"); break; // Exit switch default: Alert("Error ",Error);//Error } break; // End of modify loop } // End of modify loop //------------------------------------------------------ 8 -- } // End of order analysis //--------------------------------------------------------------- 9 -- return; // Exit start() } //-------------------------------------------------------------- 10 --
 
VOLDEMAR:
Guys, explain to me how to use iCustom
I am writing
double BBUP =iCustom(NULL, 0, "Bands", "BandsPeriod", "BandsShift", "BandsDeviations",1,0);
double BBDW =iCustom(NULL, 0, "Bands", "BandsPeriod", "BandsShift", "BandsDeviations",2,0);
I can't get it right ...
I have a task to get signals from Bands indicator upper and lower line...... Exactly Bands.....
https://docs.mql4.com/ru/indicators/iBands
 
FelixFX:

Good evening everyone!

In Sergey Kovalev's tutorial I found an expert - trailing stop. I copied it into MetaEditor, compiled it, but the program does not work. Please advise what is the reason. Maybe I am doing something wrong.


Use this:

In user variables we write:

extern string   с9="------ Трейлингстоп ------";
extern int      TrailingStop=20; //Трейлинг-Стоп рыночного ордера. Если = 0 или то тарла нет
extern int      TrailingStep=5; //Шаг трала рыночного ордера
extern bool     WaitProfit = true; // Если true, то ждать профит = значению TrailingStop и только потом начинать тралить
                                    //Иначе, трейлинговать не дожидаясь положительного профита

extern string   с10=" -------- Прочие параметры -------------";
extern int      MAGIC=123456;//У ордеров открытых вручную MAGIC=0
extern int      Proskalz=10;//Проскальзывание

In EA Start write:

// ----------------------------- Тралим ордера ------------------------------------
TrailingRyn_b(TrailingStop,TrailingStep,Proskalz,MAGIC,WaitProfit,false);

After start in custom subprograms write:

// =================================================================================================
// ************************* Трейлинг рыночных ордеров *********************************************
// =================================================================================================


// =================  TrailingRyn() =============================================================
// функция осуществляет трейлинг рыночных ордеров 
// ----------------------------------------------
void TrailingRyn_b(int ryn_TrStop, int ryn_TrStep, int Proskalz, int MAGIC, bool WaitProfit,  bool UseTrailingSound) {
  string SMB=Symbol(); 
  int i;
  int MinLevel=MarketInfo(SMB,MODE_STOPLEVEL);//Минимально допустимый уровень стоп-лосса/тейк-профита в пунктах   
  int SchBuy=SchBuy(MAGIC);
  int SchSell=SchSell(MAGIC);
  if(ryn_TrStop>=MinLevel && ryn_TrStep>0 && (SchBuy>0 || SchSell>0)){    
    for (i=OrdersTotal()-1;i>=0;i--){
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {WriteError(i);}
      else {
        if (OrderSymbol()==SMB && OrderMagicNumber()==MAGIC){
          TrailingPositions_b(ryn_TrStop,ryn_TrStep,Proskalz,WaitProfit,UseTrailingSound);
        }
      }
    }
  }
 if(ryn_TrStop>=MinLevel && ryn_TrStep==0)
 Alert("Трейлинг невозможен - ryn_TrStep==0");
} 
// =================================================================================================

//+------------------------------------------------------------------+
//| Сопровождение позиции простым тралом                             |
//+------------------------------------------------------------------+
void TrailingPositions_b(int ryn_TrStop, int ryn_TrStep, int Proskalz, bool WaitProfit, bool UseTrailingSound){
  if(OrderType()==OP_BUY){
    if(!WaitProfit || (Bid-OrderOpenPrice())>ryn_TrStop*Point){
      if (OrderStopLoss()<Bid-(ryn_TrStop+ryn_TrStep-1)*Point){
        ModifyStopLoss_b(Bid-ryn_TrStop*Point,UseTrailingSound);
      }
    }
  }
  if(OrderType()==OP_SELL){
    if(!WaitProfit || OrderOpenPrice()-Ask>ryn_TrStop*Point) {
      if(OrderStopLoss()>Ask+(ryn_TrStop+ryn_TrStep-1)*Point || OrderStopLoss()==0){
        ModifyStopLoss_b(Ask+ryn_TrStop*Point,UseTrailingSound);
      }
    }
  }
}

//+------------------------------------------------------------------+
//| Перенос уровня StopLoss                                          |
//| Параметры:                                                       |
//|   ldStopLoss - уровень StopLoss                                  |
//+------------------------------------------------------------------+
void ModifyStopLoss_b(double ldStopLoss, bool UseTrailingSound){
  bool fm=false;
  string NameTrallingSound  = "ok.wav";// Наименование звукового файла для трейлинга
  fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
  if(fm!=0 && fm!=-1){
    if(UseTrailingSound) { PlaySound(NameTrallingSound);}
  }   
  if(fm==0 || fm==-1) { ModifError();}
}
//+------------------------------------------------------------------+

Functions like ModifError() are my custom functions - they just display an error message. Write your own messages instead.

 
Thank you .... If it had helped me I wouldn't be asking this question .............
Reason: