// Dichiarazione dei parametri personalizzabili dall'utente input int BBLength = 100; // Lunghezza delle Bande di Bollinger input double BBDeviation = 2; // Deviazione standard delle Bande di Bollinger input int BBOffset = 0; // Offset delle Bande di Bollinger input int PipThreshold = 200; // Numero di pips per scatenare un trade input int TakeProfitPips = 150; // Take Profit in pips input double LotSize = 0.01; // Lottaggio fisso per le operazioni //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { ChartApplyTemplate(0,"bb_template.tpl"); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ChartIndicatorDelete(0,0,"Bollinger Bands"); } double upperBB, lowerBB; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { upperBB = iBands(NULL, 0, BBLength, BBDeviation, BBOffset, PRICE_CLOSE, MODE_UPPER, 1); lowerBB = iBands(NULL, 1, BBLength, BBDeviation, BBOffset, PRICE_CLOSE, MODE_LOWER, 1); double pipDistance = MarketInfo(Symbol(), MODE_POINT) *10* PipThreshold; if(newCandle()) { // Verifica se il prezzo esce dalla banda superiore if(Bid >= upperBB + pipDistance) { double TakeProf = Bid - TakeProfitPips*10*_Point; // Apre una posizione di sell con il take profit specificato int ticket_a = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 0, 0, TakeProf, "", 0, clrNONE); } // Verifica se il prezzo esce dalla banda inferiore if(Bid <= lowerBB - pipDistance) { double TakeProf2 = Ask + TakeProfitPips*10*_Point; // Apre una posizione di buy con il take profit specificato int ticket_b = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 0, 0, TakeProf2, "", 0, clrNONE); } } } //+------------------------------------------------------------------+ datetime OpenTime = iTime(Symbol(), PERIOD_CURRENT, 0); // bool newCandle() { datetime newOpenTime = iTime(Symbol(), PERIOD_CURRENT, 0); if(newOpenTime != OpenTime) { OpenTime = newOpenTime; return true; } else return false; } //+------------------------------------------------------------------+