[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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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\"?
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.
//-------------------------------------------------------------------- // 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 --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:
In EA Start write:
// ----------------------------- Тралим ордера ------------------------------------ TrailingRyn_b(TrailingStop,TrailingStep,Proskalz,MAGIC,WaitProfit,false);After start in custom subprograms write:
Functions like ModifError() are my custom functions - they just display an error message. Write your own messages instead.
https://docs.mql4.com/ru/indicators/iBands