//+------------------------------------------------------------------+
//| Super.mq4 |
//| Copyright © 2008, |
//| http://tradenetsoft.net |
//+------------------------------------------------------------------+
extern int Step=100;
extern double StopLots=0.2;
extern double LimitLots=0.1;
extern int Profit=1000;
extern int Slippage=3;
extern string OrdersComment="Super";
int i,MAGIC,STP,SPR,MN1,MN2,Prf;
double LotS,LotL,sl,tp,MaxLots,MinLots,StepLots,I;
string CMM,txt;
bool First;
datetime StartTime;
int init()//==================================================================================================
{
int yy;
ObjectCreate("Copyright",OBJ_LABEL,0,0,1.0);
ObjectSet("Copyright", OBJPROP_CORNER, 2);
ObjectSet("Copyright", OBJPROP_XDISTANCE, 3);
ObjectSet("Copyright", OBJPROP_YDISTANCE, 1);
txt="Shurka "+CharToStr(174)+" SHFOREX.NAROD.RU";
ObjectSetText("Copyright",txt,8,"Times New Roman",Tomato);
ObjectSet("Copyright",OBJPROP_TIMEFRAMES,NULL);
ObjectSet("Copyright",OBJPROP_BACK,false);
MAGIC=220808+StringGetChar(Symbol(),0)+StringGetChar(Symbol(),1)*2
+StringGetChar(Symbol(),3)*3+StringGetChar(Symbol(),4)*4;
MN1=MAGIC; MN2=MN1+1;
// Определение размера лота
MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);
MinLots=MarketInfo(Symbol(),MODE_MINLOT);
StepLots=MarketInfo(Symbol(),MODE_LOTSTEP);
LotS=StopLots; LotL=LimitLots;
if(LotS<MinLots) LotS=MinLots; else if(LotS>MaxLots) LotS=MaxLots; else LotS=NormalizeDouble(LotS/StepLots,0)*StepLots;
if(LotL<MinLots) LotL=MinLots; else if(LotL>MaxLots) LotL=MaxLots; else LotL=NormalizeDouble(LotL/StepLots,0)*StepLots;
I=NormalizeDouble(Step*Point,Digits);
CMM=OrdersComment+" Magic#="+MAGIC;
First=true; StartTime=TimeCurrent();
return(0);
}
int deinit()
{
ObjectDelete("Copyright");
return(0);
}
//============================================================================================================
// Основная функция
int start()
{
double p,u,d,SLp,SSp,BLp,BSp,Sp,Bp,Sstop,Bstop,Lotb,Lots;
bool sb,ss,lb,ls;
datetime tb,ts;
// Проверка доступности торговли.
if(!IsTesting())
{
if(!IsExpertEnabled()) { Comment("В торговом терминале запрещён запуск экспертов."); return(0); } else
if(!IsTradeAllowed()) { Comment("Торговля запрещена или торговый поток занят."); return(0); } else Comment("");
}
STP=MarketInfo(Symbol(),MODE_STOPLEVEL);
SPR=MarketInfo(Symbol(),MODE_SPREAD);
// Определение текущих актуальных цен
u=NormalizeDouble(Bid+STP*Point,Digits);
d=NormalizeDouble(Bid-STP*Point,Digits);
SLp=0; p=0; while(SLp==0) { p+=I; if(p<=d) SSp=p; if(p>=u) SLp=p; }
SSp=NormalizeDouble(SSp,Digits);
SLp=NormalizeDouble(SLp,Digits);
BSp=NormalizeDouble(SLp+SPR*Point,Digits);
BLp=NormalizeDouble(SSp+SPR*Point,Digits);
Sstop=0; p=0; while(Sstop==0) { p+=I; if(p<=Bid) Bstop=Bid; if(p>=Bid) Sstop=Bid; }
Sstop=NormalizeDouble(Sstop+I+SPR*Point,Digits);
Bstop=NormalizeDouble(Bstop-I,Digits);
// Проверяем все закрытые ордера---------------------------------------------------------------------------
if(First) for(i=OrdersHistoryTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MN1 || OrderOpenTime()<StartTime) continue;
if(OrderProfit()>0) First=false;
}
// Проверяем все открытые ордера---------------------------------------------------------------------------
for(ts=0,tb=0,Sp=0,Bp=0,Lotb=0,Lots=0,Prf=0,i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()!=Symbol() || (OrderMagicNumber()!=MN1 && OrderMagicNumber()!=MN2) || OrderType()>OP_SELL) continue;
p=NormalizeDouble(OrderOpenPrice(),Digits);
if(OrderMagicNumber()==MN2 && !First)
{
if(OrderType()==OP_SELL && (OrderStopLoss()>Sstop || OrderStopLoss()==0))
OrderModify(OrderTicket(),OrderOpenPrice(),Sstop,0,0,CLR_NONE); else
if(OrderType()==OP_BUY && OrderStopLoss()<Bstop)
OrderModify(OrderTicket(),OrderOpenPrice(),Bstop,0,0,CLR_NONE);
}
if(OrderType()==OP_SELL)
{
if(OrderOpenTime()>ts) { ts=OrderOpenTime(); Sp=NormalizeDouble(OrderOpenPrice(),Digits); }
Lots+=OrderLots();
Prf+=(OrderOpenPrice()-Ask)/Point;
} else
if(OrderType()==OP_BUY)
{
if(OrderOpenTime()>tb) { tb=OrderOpenTime(); Bp=NormalizeDouble(OrderOpenPrice(),Digits); }
Lotb+=OrderLots();
Prf+=(Bid-OrderOpenPrice())/Point;
}
}
if(Prf>=Profit) { CloseAll(); First=true; StartTime=TimeCurrent(); return(0); }
// Проверяем все отложенные ордера-------------------------------------------------------------------------
for(sb=false,ss=false,lb=false,ls=false,i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()!=Symbol() || (OrderMagicNumber()!=MN1 && OrderMagicNumber()!=MN2) || OrderType()<=OP_SELL) continue;
p=NormalizeDouble(OrderOpenPrice(),Digits);
if(OrderType()==OP_SELLSTOP)
{
if(p<SSp-I) OrderDelete(OrderTicket()); else
{
if(p==SSp) ss=true;
if(!First && OrderStopLoss()>0) OrderModify(OrderTicket(),OrderOpenPrice(),0,0,0,CLR_NONE);
}
} else
if(OrderType()==OP_BUYSTOP)
{
if(p>BSp+I) OrderDelete(OrderTicket()); else
{
if(p==BSp) sb=true;
if(!First && OrderStopLoss()>0) OrderModify(OrderTicket(),OrderOpenPrice(),0,0,0,CLR_NONE);
}
} else
if(OrderType()==OP_SELLLIMIT)
{
if(p>SLp+I) OrderDelete(OrderTicket()); else
{
if(p==SLp) ls=true;
if(!First && OrderStopLoss()<OrderOpenPrice()+I)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+I+SPR*Point,Digits)
,OrderTakeProfit(),0,CLR_NONE);
}
} else
if(OrderType()==OP_BUYLIMIT)
{
if(p<BLp-I) OrderDelete(OrderTicket()); else
{
if(p==BLp) lb=true;
if(!First && OrderStopLoss()>OrderOpenPrice()-I)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-I-SPR*Point,Digits)
,OrderTakeProfit(),0,CLR_NONE);
}
}
}
RefreshRates();
if(!sb && BSp!=Bp)
{
if(!First) sl=0; else sl=NormalizeDouble(SLp-I*2,Digits);
if(!First) tp=0; else tp=NormalizeDouble(SLp+I,Digits);
OrderSend(Symbol(),OP_BUYSTOP,LotS,BSp,0,sl,tp,CMM,MN2,0,Blue);
}
if(!lb && BLp!=Bp)
{
sl=NormalizeDouble(SSp-I,Digits);
tp=NormalizeDouble(SSp+I,Digits);
OrderSend(Symbol(),OP_BUYLIMIT,LotL,BLp,0,sl,tp,CMM,MN1,0,Blue);
}
if(!ss && SSp!=Sp)
{
if(!First) sl=0; else sl=NormalizeDouble(BLp+I*2,Digits);
if(!First) tp=0; else tp=NormalizeDouble(BLp-I,Digits);
OrderSend(Symbol(),OP_SELLSTOP,LotS,SSp,0,sl,tp,CMM,MN2,0,Red);
}
if(!ls && SLp!=Sp)
{
sl=NormalizeDouble(BSp+I,Digits);
tp=NormalizeDouble(BSp-I,Digits);
OrderSend(Symbol(),OP_SELLLIMIT,LotL,SLp,0,sl,tp,CMM,MN1,0,Red);
}
return(0);
}
void CloseAll()
{
bool Yes=true;
while(Yes)
{
Yes=false;
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()!=Symbol() || (OrderMagicNumber()!=MN1 && OrderMagicNumber()!=MN2)) continue;
Yes=true;
RefreshRates();
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE); else
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE); else
OrderDelete(OrderTicket());
}
}
First=true;
StartTime=TimeCurrent();
return;
}
- Помогите с NormalizeDouble(AccountFreeMargin()
- Отложенные ордера в Советнике!! Прошу помощи!!!
- ОШИБКИ ПРИ КОМПИЛЯЦИИ
Вот этот кусок удали:
if(OrderMagicNumber()==MN2 && !First)
{
if(OrderType()==OP_SELL && (OrderStopLoss()>Sstop || OrderStopLoss()==0))
OrderModify(OrderTicket(),OrderOpenPrice(),Sstop,0,0,CLR_NONE); else
if(OrderType()==OP_BUY && OrderStopLoss()<Bstop)
OrderModify(OrderTicket(),OrderOpenPrice(),Bstop,0,0,CLR_NONE);
}

Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь