<code>#property copyright "Copyright © 2014, Хлыстов Владимир" #property link "cmillion@narod.ru" #property show_inputs #property strict //-------------------------------------------------------------------- extern int stoploss = 50, //уровень выставления SL, если 0, то SL не выставляется takeprofit = 50, //уровень выставления TP, если 0, то TP не выставляется MaxOrders = 1, //кол-во ордеров Magic = 123456; //уникальный номер ордера extern double LotBuy = 0.1; //объем ордера если 0 то не откоывать extern double LotSell = 0.1; //объем ордера если 0 то не откоывать extern int attempts = 10; //кол-во попыток открытия extern int Slippage = 3; //кол-во попыток открытия string txt; int n,slippage; double STOPLEVEL; //-------------------------------------------------------------------- int start() { STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL); slippage = Slippage; if (Digits==3 || Digits==5) slippage=Slippage*10; for (int i=1; i<=MaxOrders; i++) { if (LotBuy>0) OPENORDER (OP_BUY,NormalizeDouble(Ask,Digits),LotBuy,i); if (LotSell>0) OPENORDER (OP_SELL,NormalizeDouble(Bid,Digits),LotSell,i); } Comment("Скрипт закончил свою работу, выставлено ",n," ордеров "); return(0); } //-------------------------------------------------------------------- void OPENORDER(int ord,double Price,double LOT,int i) { int error,err=0; double SL=0,TP=0; while (true) { error=true; RefreshRates(); if (ord==OP_BUY) { if (takeprofit>=STOPLEVEL) TP = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0; if (stoploss>=STOPLEVEL) SL = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0; error=OrderSend(Symbol(),OP_BUY, LOT,Price,slippage,SL,TP,"http://cmillion.ru",Magic,0,Blue); } if (ord==OP_SELL) { if (takeprofit>=STOPLEVEL) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0; if (stoploss>=STOPLEVEL) SL = NormalizeDouble(Price + stoploss*Point,Digits); else SL=0; error=OrderSend(Symbol(),OP_SELL,LOT,Price,slippage,SL,TP,"http://cmillion.ru",Magic,0,Red); } if (error==-1) { txt=StringConcatenate(txt,"\nError ",GetLastError()); if (ord== 1) txt = StringConcatenate(txt," OPENORDER BUY ",i," Ask =",DoubleToStr(Ask,Digits)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),") STOPLEVEL=",STOPLEVEL); if (ord==-1) txt = StringConcatenate(txt," OPENORDER SELL ",i," Bid =",DoubleToStr(Bid,Digits)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),") STOPLEVEL=",STOPLEVEL); Print(txt); Comment(txt," ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)); err++;Sleep(1000);RefreshRates(); } else { Comment("Ордер ",error," успешно выставлен ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)); n++; return; } if (err >attempts) return; } return; } //-------------------------------------------------------------------- </code>
<code>//-------------------------------------------------------------------- void OPENORDER(int ord,double Price,double LOT) { int rez,err=0; double SL=0,TP=0; while (true) { rez=true; RefreshRates(); if (ord==OP_BUY) { if (takeprofit>=STOPLEVEL) TP = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0; if (stoploss>=STOPLEVEL) SL = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0; rez=OrderSend(Symbol(),OP_BUY, LOT,Price,slippage,SL,TP,"http://cmillion.ru",Magic,0,Blue); } if (ord==OP_SELL) { if (takeprofit>=STOPLEVEL) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0; if (stoploss>=STOPLEVEL) SL = NormalizeDouble(Price + stoploss*Point,Digits); else SL=0; rez=OrderSend(Symbol(),OP_SELL,LOT,Price,slippage,SL,TP,"http://cmillion.ru",Magic,0,Red); } if (rez==-1) { txt=StringConcatenate(txt,"\nError ",GetLastError()); if (ord== 1) txt = StringConcatenate(txt," OPENORDER BUY "," Ask =",DoubleToStr(Ask,Digits)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),") STOPLEVEL=",STOPLEVEL); if (ord==-1) txt = StringConcatenate(txt," OPENORDER SELL "," Bid =",DoubleToStr(Bid,Digits)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),") STOPLEVEL=",STOPLEVEL); Print(txt); err++;Sleep(1000);RefreshRates(); } else { Comment("Ордер ",rez," успешно выставлен "); return; } if (err >attempts) return; } return; } //-------------------------------------------------------------------- </code>
<code>//-------------------------------------------------------------------- void OPENORDER_2(int ord,double Price,double LOT) { int rez,err=0; double SL=0,TP=0; while (true) { rez=true; RefreshRates(); if (ord==OP_BUY) rez=OrderSend(Symbol(),OP_BUY, LOT,Price,slippage,0,0,"",Magic,0,Blue); if (ord==OP_SELL) rez=OrderSend(Symbol(),OP_SELL,LOT,Price,slippage,0,0,"",Magic,0,Red); if (rez==-1) { txt=StringConcatenate(txt,"\nError ",GetLastError()); if (ord== 1) txt = StringConcatenate(txt," OPENORDER BUY "," Ask =",DoubleToStr(Ask,Digits)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),") STOPLEVEL=",STOPLEVEL); if (ord==-1) txt = StringConcatenate(txt," OPENORDER SELL "," Bid =",DoubleToStr(Bid,Digits)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),") STOPLEVEL=",STOPLEVEL); Print(txt); err++; Sleep(1000); RefreshRates(); } else { Comment("Ордер ",rez," успешно выставлен "); return; } if (err >attempts) return; } return; } //-------------------------------------------------------------------- </code>
<code> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PutOrder(int type,double price,double lot) { int r=0; color clr=Green; double sl=0,tp=0; if(type==1 || type==3 || type==5) { clr=Red; if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*_Point,_Digits); if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*_Point,_Digits); } if(type==0 || type==2 || type==4) { clr=Blue; if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*_Point,_Digits); if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*_Point,_Digits); } r=OrderSend(NULL,type,lot,NormalizeDouble(price,_Digits),Slip,sl,tp,Comm,Magic,0,clr); return; } //+------------------------------------------------------------------+ </code>
<code>//+------------------------------------------------------------------+ //| Locker.mq4 | //| Copyright 2022, AM2 | //| https://www.forexsystems.biz | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, AM2" #property link "https://www.forexsystems.biz" #property version "1.00" #property strict //--- Inputs extern int StopLoss = 23; // лось в пунктах extern int TakeProfit = 78; // язь в пунктах extern int Slippage = 3; // реквот в пунктах strig symbol; int digits, slippage; double pnt,sl,tp; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { symbol = Symbol(); digits = Digits; pnt = Point; if(digits==3 || digits==5) { tp = TakeProfit*pnt*10; sl = StopLoss*pnt*10; slippage = Slippage*pnt*10; } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(CountTrades()==Count && !TimeSession(StartHour,StartMin,EndHour,EndMin,TimeCurrent())) { if(Sell) PutOrder(OP_BUY,Ask,Lot); if(Buy) PutOrder(OP_SELL,Bid,Lot); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PutOrder(int type,double price,double lot) { int r=0; color clr=Green; if(type==OP_SELL || type==OP_SELLLIMIT || type==OP_SELLSTOP) { clr=Red; if(StopLoss>0) sl=NormalizeDouble(price+sl,digits); if(TakeProfit>0) tp=NormalizeDouble(price-tp,digits); } if(type == OP_BUY || type == OP_BUYLIMIT || type==OP_BUYSTOP) { clr=Blue; if(StopLoss>0) sl=NormalizeDouble(price-sl,digits); if(TakeProfit>0) tp=NormalizeDouble(price+tp,digits); } r=OrderSend(NULL,type,lot,NormalizeDouble(price,digits),slippage,sl,tp,Comm,Magic,0,clr); return; } //+------------------------------------------------------------------+</code>
Меня всегда интересуют причинно-следственные связи.
Простой советник от того и простой. Жаловаться на него, то же, что и на отсутствие зонта во время дождя. Т.е. бесполезно. Человек с колена поделился мыслью. Не нравится — проходи мимо. А если он тебе в жилу, разберись сам, чего понедельник тяжелый день. У меня тоже, как правило.
К стати не смотрел, но уверен: там орднра открываются не таким образом.
А подобных функций валом. Почти один в один. Так как программист я еще тот, то в кодомарании я больше доверяю Хлыстову, чем себе. Так мне жизненный опыт шепчет.
Тут у нас девушка обитает. Почему-то мама OXY назвала. Так вот, ее коды гораздо симпатичнее и продуманнее, чем коды АМ2. Так она тоже не брезгует подобными подходами. Сейчас что-нибудь найду.
Блин. В моем бардаке сходу хрен что найдешь. Попался Хлыстов первым, вот его и взял.
Не важно. Взял пример. Работаю над ним. Кто-то предложит другой вариант (может гораздро лучше) поработаем и с ним. А пока что конкурентции ноль.
Всех благ.
kvashnin007