//+------------------------------------------------------------------+ //| Darvas Boxes Advisor.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #include //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- TODO: Add your code here. //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: Add your code here. //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- TODO: Add your code here. bool buy_darvas = false; int i; int total; int ticket; int level_limit = 5; double box_top = iCustom(NULL, 0, "Darvas Boxes", 0, 2); double box_bottom = iCustom(NULL, 0, "Darvas Boxes", 1, 2); int level = 0; int idx = 4; for (; idx < Bars-1 && level < level_limit; idx++) { double bottom = iCustom(NULL, 0, "Darvas Boxes", 1, idx); if (bottom > box_bottom) { box_bottom = bottom; level++; } else if (bottom < box_bottom) { break; } } if (level == level_limit) buy_darvas = true; double spread = MarketInfo(Symbol(), 13); if (Close[idx] < Ask) return (0); if (buy_darvas) { if ( High[1] < High[0] && Low[1] < Low[0] ) return (0); if (AccountFreeMargin() > 2000) { bool trading_on_symbol = false; total = OrdersTotal(); for (i = 0; i < total; i++) { OrderSelect(i, SELECT_BY_POS); if (OrderSymbol() == Symbol()) { trading_on_symbol = true; break; } } if (!trading_on_symbol) { ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-40*Point,Ask+10*Point, NULL, 0, 0, Aqua); } } } for (i = 0; i < total; i++) { OrderSelect(i, SELECT_BY_POS); if (OrderProfit() > 50) { OrderClose( OrderTicket(), 1, Ask, 3, Aqua); break; } } //---- return(0); } //+------------------------------------------------------------------+