//+------------------------------------------------------------------+
//| GT BB SINWIN.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| https://www.mql5.com/ru/users/rustein |
//+------------------------------------------------------------------+
#define MAGIC 131313
//-------------------------------------------------------------------+
extern int StopLoss = 37;
extern int Slippage = 3;
//-------------------------------------------------------------------+
extern double Lots = 0.01;
extern double MaximumRisk = 0.2;
extern double DecreaseFactor = 5.0;
//-------------------------------------------------------------------+
extern bool Trailing = true;
extern int MinProfit = 37;
extern int TrailingStop = 23;
extern int TrailingStep = 14;
//-------------------------------------------------------------------+
extern bool NoLoss = false;
extern int MinProfitB = 23;
extern int NoLossLevel = 5;
//+------------------------------------------------------------------+
extern int Shift = 0;
//+------------------------------------------------------------------+
extern int BBPeriod = 30; // works better than 20
extern int BBDeviation = 2;
extern int BBPrice = 0; // 0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted
//-------------------------------------------------------------------+
extern int MA = 20; //
extern int MAMode = 0; // 0=SMA,1=EMA,2=SSMA,3=LWMA
extern int MAPrice = 0; // 0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted
double pointvalue;
int init() {
pointvalue = Point;
if(Digits==3 || Digits==5){pointvalue=Point*10;/*SpreadLimit*= 10;*/}else{pointvalue=Point;} // auto digit select
return (0);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,2);
//---- calcuulate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,2);
}
//---- return lot size
if(lot<0.1) lot=0.1;
return(lot);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--------------------------------------------------------------------+
double BBup = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_UPPER,Shift+1);
double BBlo = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_LOWER,Shift+1);
double MAnow = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift);
double MApre = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift+1);
//--------------------------------------------------------------------+
//---- buy conditions
if(Low[Shift+1] < BBlo && MAnow > MApre)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,Slippage,Ask-(StopLoss*pointvalue),0,"GT BB SINWIN",MAGIC,0,Green);
return;
}
//---- sell conditions
if(High[Shift+1] > BBup && MAnow < MApre)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,Slippage,Bid+(StopLoss*pointvalue),0,"GT BB SINWIN",MAGIC,0,Red);
return;
}
//----
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
double ma;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--------------------------------------------------------------------+
double BBup = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_UPPER,Shift);
double BBlo = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_LOWER,Shift);
double MAnow = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift);
double MApre = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift+1);
//--------------------------------------------------------------------+
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(High[Shift] > BBup && MAnow < MApre) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Gold);
break;
}
if(OrderType()==OP_SELL)
{
if(Low[Shift] < BBlo && MAnow > MApre) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Gold);
break;
}
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
if(Trailing) TrailPositions();
if(NoLoss) CreateNoLoss();
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
}
//+------------------------------------------------------------------+
//|-----------------------// Trail positions //----------------------+
//+------------------------------------------------------------------+
void TrailPositions()
{
int Orders = OrdersTotal();
for (int i=0; i<Orders; i++)
{
if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if (OrderSymbol() != Symbol()) continue;
{
if (OrderType() == OP_BUY)
{
if (Bid-OrderOpenPrice() > MinProfit*pointvalue)
{
if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*pointvalue)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_SELL)
{
if (OrderOpenPrice()-Ask > MinProfit*pointvalue)
{
if (OrderStopLoss() > Ask+(TrailingStop+TrailingStep-1)*pointvalue)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//|---------------------------// No Losee //-------------------------+
//+------------------------------------------------------------------+
void CreateNoLoss()
{
int Orders = OrdersTotal();
for (int i=0; i<Orders; i++)
{
if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if (OrderSymbol() != Symbol()) continue;
{
if (OrderType() == OP_BUY && OrderStopLoss() < OrderOpenPrice())
{
if (Bid-OrderOpenPrice() > MinProfitB*pointvalue)
{
if (OrderStopLoss() < Bid-(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_BUY && OrderStopLoss() == 0)
{
if (Bid-OrderOpenPrice() > MinProfitB*pointvalue)
{
if (OrderStopLoss() < Bid-(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_SELL && OrderStopLoss() > OrderOpenPrice())
{
if (OrderOpenPrice()-Ask > MinProfitB*pointvalue)
{
if (OrderStopLoss() > Ask+(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()-NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_SELL && OrderStopLoss() == 0)
{
if (OrderOpenPrice()-Ask > MinProfitB*pointvalue)
{
if (OrderStopLoss() > Ask+(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()-NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//|---------------------------// END //------------------------------|
//+------------------------------------------------------------------+
Pheniox:
Modified to work on 4 or 5 digit brokers automatically
//+------------------------------------------------------------------+
//| GT BB SINWIN.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| https://www.mql5.com/ru/users/rustein |
//+------------------------------------------------------------------+
#define MAGIC 131313
//-------------------------------------------------------------------+
extern int StopLoss = 37;
extern int Slippage = 3;
//-------------------------------------------------------------------+
extern double Lots = 0.01;
extern double MaximumRisk = 0.2;
extern double DecreaseFactor = 5.0;
//-------------------------------------------------------------------+
extern bool Trailing = true;
extern int MinProfit = 37;
extern int TrailingStop = 23;
extern int TrailingStep = 14;
//-------------------------------------------------------------------+
extern bool NoLoss = false;
extern int MinProfitB = 23;
extern int NoLossLevel = 5;
//+------------------------------------------------------------------+
extern int Shift = 0;
//+------------------------------------------------------------------+
extern int BBPeriod = 30; // works better than 20
extern int BBDeviation = 2;
extern int BBPrice = 0; // 0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted
//-------------------------------------------------------------------+
extern int MA = 20; //
extern int MAMode = 0; // 0=SMA,1=EMA,2=SSMA,3=LWMA
extern int MAPrice = 0; // 0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted
double pointvalue;
int init() {
pointvalue = Point;
if(Digits==3 || Digits==5){pointvalue=Point*10;/*SpreadLimit*= 10;*/}else{pointvalue=Point;} // auto digit select
return (0);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,2);
//---- calcuulate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,2);
}
//---- return lot size
if(lot<0.1) lot=0.1;
return(lot);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--------------------------------------------------------------------+
double BBup = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_UPPER,Shift+1);
double BBlo = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_LOWER,Shift+1);
double MAnow = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift);
double MApre = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift+1);
//--------------------------------------------------------------------+
//---- buy conditions
if(Low[Shift+1] < BBlo && MAnow > MApre)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,Slippage,Ask-(StopLoss*pointvalue),0,"GT BB SINWIN",MAGIC,0,Green);
return;
}
//---- sell conditions
if(High[Shift+1] > BBup && MAnow < MApre)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,Slippage,Bid+(StopLoss*pointvalue),0,"GT BB SINWIN",MAGIC,0,Red);
return;
}
//----
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
double ma;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--------------------------------------------------------------------+
double BBup = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_UPPER,Shift);
double BBlo = iBands(NULL,0,BBPeriod,BBDeviation,0,BBPrice, MODE_LOWER,Shift);
double MAnow = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift);
double MApre = iMA(NULL,0,MA,0,MAMode,MAPrice,Shift+1);
//--------------------------------------------------------------------+
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(High[Shift] > BBup && MAnow < MApre) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Gold);
break;
}
if(OrderType()==OP_SELL)
{
if(Low[Shift] < BBlo && MAnow > MApre) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Gold);
break;
}
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
if(Trailing) TrailPositions();
if(NoLoss) CreateNoLoss();
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
}
//+------------------------------------------------------------------+
//|-----------------------// Trail positions //----------------------+
//+------------------------------------------------------------------+
void TrailPositions()
{
int Orders = OrdersTotal();
for (int i=0; i<Orders; i++)
{
if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if (OrderSymbol() != Symbol()) continue;
{
if (OrderType() == OP_BUY)
{
if (Bid-OrderOpenPrice() > MinProfit*pointvalue)
{
if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*pointvalue)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_SELL)
{
if (OrderOpenPrice()-Ask > MinProfit*pointvalue)
{
if (OrderStopLoss() > Ask+(TrailingStop+TrailingStep-1)*pointvalue)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//|---------------------------// No Losee //-------------------------+
//+------------------------------------------------------------------+
void CreateNoLoss()
{
int Orders = OrdersTotal();
for (int i=0; i<Orders; i++)
{
if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if (OrderSymbol() != Symbol()) continue;
{
if (OrderType() == OP_BUY && OrderStopLoss() < OrderOpenPrice())
{
if (Bid-OrderOpenPrice() > MinProfitB*pointvalue)
{
if (OrderStopLoss() < Bid-(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_BUY && OrderStopLoss() == 0)
{
if (Bid-OrderOpenPrice() > MinProfitB*pointvalue)
{
if (OrderStopLoss() < Bid-(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_SELL && OrderStopLoss() > OrderOpenPrice())
{
if (OrderOpenPrice()-Ask > MinProfitB*pointvalue)
{
if (OrderStopLoss() > Ask+(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()-NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
if (OrderType() == OP_SELL && OrderStopLoss() == 0)
{
if (OrderOpenPrice()-Ask > MinProfitB*pointvalue)
{
if (OrderStopLoss() > Ask+(NoLossLevel-1)*pointvalue)
{
OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()-NoLossLevel*pointvalue,OrderTakeProfit(),0,Gold);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//|---------------------------// END //------------------------------|
//+------------------------------------------------------------------+
А можно спросить... Почему столько много строк в коде?
Мне казалось, что чтобы взять показания с индюка функцией iCustom много кода не нужно писать .А в чём я ошибаюсь ?
А можно спросить... Почему столько много строк в коде?
Мне казалось, что чтобы взять показания с индюка функцией iCustom много кода не нужно писать .А в чём я ошибаюсь ?
советнику не нужен индикатор, алгоритм стратегии(индикатора) вложен в советнике
Здравствуйте! скачал Ваш советник, но при тех же параметрах на той же паре и в том же промежутке времени, но в другом ДЦ(инстафорекс), на тестере дает совершенно другие результаты(отрицательные) . может ли советник работать с этим ДЦ? или проблема в чем то другом?
Pheniox:
Modified to work on 4 or 5 digit brokers automatically
rustein:
какое плечо там ?тебе чем мой вопрос не угодил ???
Здравствуйте! скачал Ваш советник, но при тех же параметрах на той же паре и в том же промежутке времени, но в другом ДЦ(инстафорекс), на тестере дает совершенно другие результаты(отрицательные) . может ли советник работать с этим ДЦ? или проблема в чем то другом?
![MQL5 - Язык торговых стратегий для клиентского терминала MetaTrader 5](https://c.mql5.com/i/registerlandings/logo-2.png)
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Вы принимаете политику сайта и условия использования
GT BB SINWIN:
Author: Warstein