[Archive!] Writing an advisor for free - page 65

 
Antton86:
Please help, I need an EA with ability to change SL and TP and indicator parameters (Stochastic) and filter (MA) - signal to BUY crossing the fast line slow up, to SELL down. The trades are made in the direction of the MA! I understand that the EA is not complicated and not very interesting, but reviewing all of the Advisor in the database has not found a similar! I tried to write it myself - 3 days were wasted (((.
https://www.mql5.com/ru/job
 
tigra-max:
Good afternoon, I would like to ask the coders to remove trading methods in the adviser (there are 5 pieces).Also remove take profit, he puts them just cuts profits!(Thanks in advance!
Post removed. Decompiled code.
 
come on!)
 
tigra-max:
come on!)
What are you talking about?
 

Good afternoon. Can anyone run a software algorithm like the one shown in the picture? I'm trying it out with my hands. But it is tedious to sit in front of the monitor. I would like to automate a little. I would like to automate the opening of positions. I would like to close them with another program for profit.

I am asking for your help, I have not succeeded, it opens a whole bunch in one direction, or even skips. I have to study MQL for a long time, and I have to understand what's what. That is why I am asking for your help.

It seems to be clear here. If the sell stop at 1.4125 is opened, put buy stop at 1.4135, multiply the lot by the LotUp and so on, until the other program closes everything.

Regards Sergey.

 
fortrader.ru:
I will write an advisor free of charge but one at a time, email whoever needs it http://forum.fortrader.ru/index.php?board=3.0
 

privet ya ne programist svyazal nekotorie idei vmesto zakinul sovetnik na reale stal zakrivat vse sdelki drugix sovetnikov vrode bi prisvoil i svoyu magik number . privoju kod chtobi postobli v chem prichna i eshe dorobotali vzyali nailuchie svyazki indikatorov


#property copyright "Armen Alaverdyan"
#property link "bravolc@mail.ru"

extern double PercentProfit = 0.15; // Процент профита
extern double PercentLoss = 100; // Процент убытка
extern bool DeleteOrders = False; // Удалять ордера
extern bool CloseTerminal = False; // Закрывать терминал
extern bool ShowComment = True; // Показывать комментарий
extern int NumberAccount = 0; // Номер торгового счёта
extern bool UseSound = False; // Использовать звуковой сигнал
extern string NameFileSound = "expert.wav"; // Наименование звукового файла
extern int Slippage = 3; // Проскальзывание цены
extern int NumberOfTry = 5; // Количество попыток
extern int PauseAfterError = 75; // Пауза после ошибки в секундах

extern double maxsimum_Lots=0.3;
extern int rsi_period=22;
extern double MATrendPeriod=26;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;

//---- input parameters
extern double Lots=0.1;
extern int StLoss=200;
extern int TPrfit=100;
extern string Times="H1";
extern int TrailingStop=11;
extern int MagicNumber = 15031963;


//------- Глобальные переменные советника --------------------------------------
bool gbDisabled = False; // Флаг блокировки советника
color clCloseBuy = Blue; // Цвет значка закрытия покупки
color clCloseSell = Red; // Цвет значка закрытия продажи
color clDelete = Yellow; // Цвет значка удаления ордеров

//------- Поключение внешних модулей -------------------------------------------
#include <stdlib.mqh>
#include <WinUser32.mqh>

//===================================================================================================
extern int MaxOrders=100;

extern int n=5;//minuta starta
double lava_aper;
double LotsOptimized() {
lava_aper = NormalizeDouble(AccountFreeMargin() * Lots / 10000.0, 1);

if (lava_aper < Lots) lava_aper = Lots;
if (lava_aper > maxsimum_Lots) lava_aper = Lots;{
return (lava_aper);
}
}

Print("Свободная маржа счета = ",AccountFreeMargin());
Print("Баланс счета = ",AccountBalance());
Print(" Средства = ",AccountEquity());




int Tick;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{


for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{


if(TrailingStop>0 && Bid-OrderOpenPrice()>Point*TrailingStop && (OrderStopLoss()<Bid-Point*TrailingStop|| OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),
Bid-Point*TrailingStop,OrderTakeProfit(),0);
}
}
if(OrderType()==OP_SELL)
{ 
if(TrailingStop>0 && OrderOpenPrice()-Ask>Point*TrailingStop && (OrderStopLoss()>Ask+Point*TrailingStop || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),
Ask+Point*TrailingStop,OrderTakeProfit(),0);
}
}
}
}
Comment("lava_aper= ",lava_aper,
"TrailingStop= ",TrailingStop,"StopLoss= ",StLoss,
"TakeProfit= ",TPrfit,
" Средства = ",AccountEquity(),
"AccountBalance()= ",AccountBalance(),
"AccountFreeMargin()= ",AccountFreeMargin() );
double bull=0,bear=0; 
bull = iBullsPower(NULL,0,5,PRICE_CLOSE,1);
bear = iBearsPower(NULL,0,5,PRICE_CLOSE,1);
// Comment("bull+bear= ",bull + bear,"\n I Blue "); 
double SignalPrevious, MaCurrent, MaPrevious;
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1); 
double MacdCurrent, MacdPrevious, SignalCurrent;
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);



double rsi17_0 = NormalizeDouble(iRSI(Symbol(),PERIOD_H1, rsi_period, 0, 0), Digits);
double rsi17_1 = NormalizeDouble(iRSI(Symbol(),PERIOD_H1, rsi_period, 3, 3), Digits);

if (Minute() == n 
&& (iDeMarker(NULL,0,14,2)<0.49)
&&(iDeMarker(NULL,0,14,0)>0.49)
//&& rsi17_1<rsi17_0
//&& Open[1] < Close[1] 
&& Tick == 0 
//&& (bull + bear > 0)
&& MacdCurrent<0 
//&& MacdCurrent>SignalCurrent 
//&& MacdPrevious<SignalPrevious 
//&& MathAbs(MacdCurrent)>(MACDOpenLevel*Point)


//&& MaCurrent>MaPrevious
)
{

OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,0,Ask - StLoss*Point,Ask + TPrfit*Point,"",MagicNumber,0,CLR_NONE);
Tick++;
return(0);
}

if (Minute() == n 
&& (iDeMarker(NULL,0,14,2)>0.51) 
&&(iDeMarker(NULL,0,14,0)<0.51)
//&& (bull + bear < 0) 
//&& rsi17_1>rsi17_0
//&& Open[1] > Close[1] 
&& Tick == 0 
&& MacdCurrent>0 
//&& MacdCurrent<SignalCurrent 
//&& MacdPrevious>SignalPrevious 
//&& MathAbs(MacdCurrent)>(MACDOpenLevel*Point)

//&& MaCurrent<MaPrevious

)
{
OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,0,Bid + StLoss*Point,Bid - TPrfit*Point,"",MagicNumber,0,CLR_NONE);
Tick++;






return(0);
}



if (OrdersTotal() <= MaxOrders) { //1
//----
if (Minute() == 59)
{
Tick = 0;
}

}





if (AccountEquity()>=AccountBalance()*(1+PercentProfit/100)
|| AccountEquity()<=AccountBalance()*(1-PercentLoss /100)) {
ClosePosFirstProfit();
DeleteOrders();
}
}


//+----------------------------------------------------------------------------+
//| |
//| ПОЛЬЗОВАТЕЛЬСКИЕ ФУНКЦИИ |
//| |
//+----------------------------------------------------------------------------+
//| Закрытие одной предварительно выбранной позиции |
//+----------------------------------------------------------------------------+
void ClosePosBySelect() {
bool fc;
color clClose;
double ll, pAsk, pBid, pp;
int err, it;

if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
for (it=1; it<=NumberOfTry; it++) {
if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
while (!IsTradeAllowed()) Sleep(5000);
RefreshRates();
pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
pBid=MarketInfo(OrderSymbol(), MODE_BID);
if (OrderType()==OP_BUY) {
pp=pBid; clClose=clCloseBuy;
} else {
pp=pAsk; clClose=clCloseSell;
}
ll=OrderLots();
fc=OrderClose(OrderTicket(), ll, pp, Slippage, clClose);
if (fc) {
if (UseSound) PlaySound(NameFileSound); break;
} else {
err=GetLastError();
if (err==146) while (IsTradeContextBusy()) Sleep(1000*PauseAfterError);
Print("Error(",err,") Close ",GetNameOP(OrderType())," ",
ErrorDescription(err),", try ",it);
Print(OrderTicket()," Ask=",pAsk," Bid=",pBid," pp=",pp);
Print("sy=",OrderSymbol()," ll=",ll," sl=",OrderStopLoss(),
" tp=",OrderTakeProfit()," mn=",OrderMagicNumber());
Sleep(1000*PauseAfterError);
}
}
} else Print("Некорректная торговая операция. Close ",GetNameOP(OrderType()));
}

//+----------------------------------------------------------------------------+
//| Закрытие позиций по рыночной цене сначала прибыльных |
//+----------------------------------------------------------------------------+
void ClosePosFirstProfit() {
int i, k=OrdersTotal();

// Сначала закрываем прибыльные позиции
for (i=k-1; i>=0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (OrderProfit()+OrderSwap()>0) ClosePosBySelect();
}
}
}
// Потом все остальные
k=OrdersTotal();
for (i=k-1; i>=0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) ClosePosBySelect();
}
}
if (CloseTerminal && !ExistPositions()) CloseTerminal();
}

//+----------------------------------------------------------------------------+
//| Закрывает торговый терминал. |
//+----------------------------------------------------------------------------+
void CloseTerminal() {
Print("Сработала функция CloseTerminal()");
int hwnd=WindowHandle(Symbol(), Period());
int hwnd_parent=0;

while(!IsStopped()) {
// hwnd=GetParent(hwnd);
if (hwnd==0) break;
hwnd_parent=hwnd;
}
if (hwnd_parent!=0) PostMessageA(hwnd_parent, WM_CLOSE, 0, 0);
}

//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 28.11.2006 |
//| Описание : Удаление ордеров |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента ("" - любой символ, |
//| NULL - текущий символ) |
//| op - операция (-1 - любой ордер) |
//| mn - MagicNumber (-1 - любой магик) |
//+----------------------------------------------------------------------------+
void DeleteOrders(string sy="", int op=-1, int mn=-1) {
bool fd;
int err, i, it, k=OrdersTotal(), ot;

if (sy=="0") sy=Symbol();
for (i=k-1; i>=0; i--) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
ot=OrderType();
if (ot>1 && ot<6) {
if ((OrderSymbol()==sy || sy=="") && (op<0 || ot==op)) {
if (mn<0 || OrderMagicNumber()==mn) {
for (it=1; it<=NumberOfTry; it++) {
if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
while (!IsTradeAllowed()) Sleep(5000);
fd=OrderDelete(OrderTicket(), clDelete);
if (fd) {
if (UseSound) PlaySound(NameFileSound); break;
} else {
err=GetLastError();
Print("Error(",err,") delete order ",GetNameOP(ot),": ",ErrorDescription(err),", try ",it);
Sleep(1000*5);
}
}
}
}
}
}
}
}

//+----------------------------------------------------------------------------+
//| Возвращает флаг существования позиций |
//| Параметры: |
//| sy - наименование инструмента ("" - любой символ, |
//| NULL - текущий символ) |
//| op - операция (-1 - любая позиция) |
//| mn - MagicNumber (-1 - любой магик) |
//+----------------------------------------------------------------------------+
bool ExistPositions(string sy="", int op=-1, int mn=-1) {
int i, k=OrdersTotal();

if (StringLen(sy)==1 && StringGetChar(sy, 0)==48) sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sy || sy=="") {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) return(True);
}
}
}
}
}
return(False);
}
//+----------------------------------------------------------------------------+
//| Возвращает наименование операции |
//+----------------------------------------------------------------------------+
string GetNameOP(int op) {
switch (op) {
case OP_BUY : return("Buy");
case OP_SELL : return("Sell");
case OP_BUYLIMIT : return("Buy Limit");
case OP_SELLLIMIT: return("Sell Limit");
case OP_BUYSTOP : return("Buy Stop");
case OP_SELLSTOP : return("Sell Stop");
default : return("Unknown Operation");
}
//}
//+----------------------------------------------------------------------------+
//| Вывод сообщения в коммент и в журнал |
//+----------------------------------------------------------------------------+
//void Message(string m) {
// Comment(m);
// if (StringLen(m)>0) Print(m);
//}


return(0);
}//0
//+------------------------------------------------------------------+





//+------------------------------------------------------------------+
 
Armen63:

privet ya ne programist svyazal nekotorie idei vmesto zakinul sovetnik na reale stal zakrivat vse sdelki drugix sovetnikov vrode bi prisvoil i svoyu magik number . privoju kod chtobi postobli v chem prichina i eshe dorobotali vzyali nailuchie svyazki indikatorov

privet. chtobi posmotret chom prichina - nuzhno kod pravilno razmestit - button "SCR" - togda kod budet bolee strukturirovan i sim budet easier work
 
abolk:
privet. chtobi posmotret chom prichina - nuzhno kod pravilno razmestit - kopka "SCR" - togda kod budet bolee strukturirovan i sim budet easier work
Files:
artur1.mq4  14 kb
 
eto chernovik xotel posmotret cto etogo poluchitsya i spasibo