//+------------------------------------------------------------------+ //| ba.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ #include #include #include #include #include #include #include //--- CChartObjectRectangle Rect; CChartObjectFibo Fibo; CTrade trade; CSymbolInfo m_symbol; CMoneyFixedRisk money; //--- input ENUM_TIMEFRAMES trade_bar=PERIOD_H1; input ENUM_TIMEFRAMES period=PERIOD_H1; input int days = 10; input double Money_FixRisk_Percent=0.5; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { EventSetTimer(1); m_symbol.Name(Symbol()); m_symbol.Refresh(); /* if(!RefreshRates()) { Print("Error RefreshRates. Bid=",DoubleToString(m_symbol.Bid(),Digits()), ", Ask=",DoubleToString(m_symbol.Ask(),Digits())); return(INIT_FAILED); } */ //--- tuning for 3 or 5 digits int digits_adjust=1; /* if(m_symbol.Digits()==3 || m_symbol.Digits()==5) digits_adjust=10; ExtStopLoss=InpStopLoss*m_symbol.Point()*digits_adjust; */ //--- if(!money.Init(GetPointer(m_symbol),Period(),m_symbol.Point()*digits_adjust)) return(INIT_FAILED); money.Percent(Money_FixRisk_Percent); // 10% risk //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ int check_pot(string name){ string name_bot,name_top; name_bot=name+"_bot"; name_top=name+"_top"; double pricebot_low= ObjectGetDouble(0,name_bot,OBJPROP_PRICE,1); double pricebot_top= ObjectGetDouble(0,name_bot,OBJPROP_PRICE,0); double pricetop_low= ObjectGetDouble(0,name_top,OBJPROP_PRICE,1); double pricetop_top= ObjectGetDouble(0,name_top,OBJPROP_PRICE,0); double pot=(pricetop_top-pricebot_low)/_Point; //Alert(price_low+" "+price_top); return pot; } int find_point(ENUM_TIMEFRAMES timefr, string bt="top", int sh=1){ double high2, open1, close2, open2, close1,price,low2; int sh2,i; for(i=1;i<100;i++){ sh=i; sh2=sh+1; high2=iHigh(NULL,timefr,sh2); low2=iLow(NULL,timefr,sh2); open1=iOpen(NULL,timefr,sh); close2=iClose(NULL,timefr,sh2); open2=iOpen(NULL,timefr,sh2); close1=iClose(NULL,timefr,sh); //time=iTime(NULL,timefr,sh2); //time=sh2; price=close2; if(close2>open2 && high2>open1 && open1>close1 && bt=="top") break; if(close2open1 && close2>open2 && close2>pricetop_top && open1>close1 && askclose1 )out="sell"; if(low2pricebot_low && pricebot_lowhigh2)high2=high1; if(low10) { //--- получим свойства ордера // type =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE))); //--- подготовим и выведем информацию об ордере // Alert(PositionGetInteger(POSITION_TYPE)); if(PositionGetInteger(POSITION_TYPE)==1){ order_sell_c++; sell_id=PositionGetInteger(POSITION_IDENTIFIER); } else{ order_buy_c++; buy_id=PositionGetInteger(POSITION_IDENTIFIER); } } } string com=""; tant_kr("orange","top"); tant_kr("blue","top"); tant_kr("yellow","top"); tant_kr("orange","bot"); tant_kr("blue","bot"); tant_kr("yellow","bot"); com=check_pot("orange"); com+="y-"+check_pot("yellow")+"b-"+check_pot("blue"); Comment(com); //Alert("222"); double lastday_top,lastday_bot,lot2; int high=iHighest(NULL,period,MODE_HIGH,days,0); int low=iLowest(NULL,period,MODE_LOW,days,0); // iLowest( //iHighest( // lastday_top=iHigh(NULL,PERIOD_H4,high); // lastday_bot=iLow(NULL,PERIOD_H4,low); lastday_top=iHigh(NULL,period,high)+SymbolInfoInteger(NULL,SYMBOL_SPREAD)*_Point+20*_Point; lastday_bot=iLow(NULL,period,low)-20*_Point; if(find_enter()=="sell" && order_sell_c==0){ lot2=money.CheckOpenShort(SymbolInfoDouble(NULL,SYMBOL_BID),lastday_top); trade.Sell(lot2,NULL,SymbolInfoDouble(NULL,SYMBOL_BID),lastday_top); trade.PositionClose(buy_id); } if(find_enter()=="buy" && order_buy_c==0 ){ lot2=money.CheckOpenLong(SymbolInfoDouble(NULL,SYMBOL_ASK),lastday_bot); trade.Buy(lot2,NULL,SymbolInfoDouble(NULL,SYMBOL_ASK),lastday_bot); //trade.PositionModify(trade.ResultDeal(),fibo_bottom); trade.PositionClose(sell_id); } } //+------------------------