//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #property copyright "Tech-Assistent - by transcendreamer" #property description "Technical Trading Assistant" #property description "trades by your trend lines and level lines" #property description "while you are away from terminal" #property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #ifdef __MQL5__ #include CTrade trading; CPositionInfo position; #endif //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ input double Lot_Default =0.01; input int Lot_Digits =2; input int Stop_Loss =0; input int Take_Profit =0; input int Trail_Start =0; input int Trail_Size =0; input int Gap_Protect =900; input bool Only_Bid =true; input bool Show_Average =true; input color Text_Color =Magenta; input ENUM_BASE_CORNER Text_Corner =CORNER_RIGHT_UPPER; input int Magic_Number =777; input string Order_Comment ="XXX"; input int Retry_Delay =1000; input int Retry_Times =20; input bool Manual_Confirm =true; input bool Auto_Alerts =false; input int Hotkey_Sell =219; input int Hotkey_Buy =221; input int Hotkey_Close =220; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double profit_total=0,volume_total=0,average_buy=0,average_sell=0; double current_ask=0,current_bid=0,previous_ask=0,previous_bid=0; string acc_currency=AccountInfoString(ACCOUNT_CURRENCY); //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnInit() { #ifdef __MQL5__ trading.SetTypeFillingBySymbol(_Symbol); trading.SetExpertMagicNumber(Magic_Number); trading.SetDeviationInPoints(0); trading.SetMarginMode(); #endif PlaceLabel("BUTTON_SELL",190,1,Text_Corner,"SELL",Text_Color,"Fixedsys",8); PlaceLabel("BUTTON_BUY",156,1,Text_Corner,"BUY",Text_Color,"Fixedsys",8); PlaceLabel("BUTTON_CLOSE",105,1,Text_Corner,"CLOSE",Text_Color,"Fixedsys",8); UpdateStatus(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(0,"BUTTON_SELL"); ObjectDelete(0,"BUTTON_BUY"); ObjectDelete(0,"BUTTON_CLOSE"); ObjectDelete(0,"STATUS_LINE"); ObjectDelete(0,"AVERAGE_BUY"); ObjectDelete(0,"AVERAGE_SELL"); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { RunTrailing(); RunMonitoring(); UpdateStatus(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK) { ObjectSetInteger(0,sparam,OBJPROP_STATE,false); if(sparam=="BUTTON_BUY") { TradeBuy(Lot_Default,false); UpdateStatus(); } if(sparam=="BUTTON_SELL") { TradeSell(Lot_Default,false); UpdateStatus(); } if(sparam=="BUTTON_CLOSE") { TradeCloseAll(false); UpdateStatus(); } } if(id==CHARTEVENT_KEYDOWN) { if(int(lparam)==Hotkey_Buy) { TradeBuy(Lot_Default,false); UpdateStatus(); } if(int(lparam)==Hotkey_Sell) { TradeSell(Lot_Default,false); UpdateStatus(); } if(int(lparam)==Hotkey_Close) { TradeCloseAll(false); UpdateStatus(); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void RunMonitoring() { previous_ask=current_ask; previous_bid=current_bid; if(Only_Bid) previous_ask=previous_bid; current_ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK); current_bid=SymbolInfoDouble(_Symbol,SYMBOL_BID); if(Only_Bid) current_ask=current_bid; if(previous_ask==0 || previous_bid==0) return; if(current_ask==0 || current_bid==0) return; if(MathAbs(current_ask-previous_ask)>Gap_Protect) return; if(MathAbs(current_bid-previous_bid)>Gap_Protect) return; for(int i=0; i0) {type_buy=true;modifier=volume;} if(volume<0) {type_sell=true;modifier=-volume;} } if(!type_buy && !type_sell && !type_close && !type_spike && !type_upward && !type_downward && !type_alert && !type_disable) continue; if(type==OBJ_TREND) trigger=ObjectGetValueByTime(0,name,TimeCurrent()); if(type==OBJ_HLINE) trigger=ObjectGetDouble(0,name,OBJPROP_PRICE); if(trigger<=0) continue; if(modifier==0) { int length=StringLen(text); int index=StringFind(text,":"); if(index!=-1) modifier=StringToDouble(StringSubstr(text,index+1,length-index-1)); } bool cross_up = (previous_ask=trigger); bool cross_dn = (previous_bid>trigger && current_bid<=trigger); bool crossing = cross_dn || cross_up; if(!crossing) continue; if(type_buy) { string message=_Symbol+": BUY LEVEL TRIGGERED"; if(Auto_Alerts) Alert(message); else Print(message); double volume_trade=(modifier==0)?Lot_Default:NormalizeDouble(modifier,Lot_Digits); TradeBuy(volume_trade,true); ObjectSetString(0,name,OBJPROP_TEXT,"LONG:"+string(modifier)); } if(type_sell) { string message=_Symbol+": SELL LEVEL TRIGGERED"; if(Auto_Alerts) Alert(message); else Print(message); double volume_trade=(modifier==0)?Lot_Default:NormalizeDouble(modifier,Lot_Digits); TradeSell(volume_trade,true); ObjectSetString(0,name,OBJPROP_TEXT,"SHORT:"+string(modifier)); } if(type_spike) { bool bar0=(iOpen(_Symbol,PERIOD_CURRENT,0)>=trigger); bool bar1=(iLow(_Symbol,PERIOD_CURRENT,1)trigger); bool bar4=(iLow(_Symbol,PERIOD_CURRENT,4)>trigger); if(bar1 && (bar1 || bar2) && bar3 && bar4) { string message=_Symbol+": BUY SPIKE DETECTED"; if(Auto_Alerts) Alert(message); else Print(message); double volume_trade=(modifier==0)?Lot_Default:NormalizeDouble(modifier,Lot_Digits); TradeBuy(volume_trade,true); ObjectSetString(0,name,OBJPROP_TEXT,"LONG:"+string(modifier)); } } if(type_spike) { bool bar0=(iOpen(_Symbol,PERIOD_CURRENT,0)<=trigger); bool bar1=(iHigh(_Symbol,PERIOD_CURRENT,1)>trigger); bool bar2=(iHigh(_Symbol,PERIOD_CURRENT,2)>trigger); bool bar3=(iHigh(_Symbol,PERIOD_CURRENT,3)=0) { string message=_Symbol+": DOWNWARD LEVEL TRIGGERED"; if(Auto_Alerts) Alert(message); else Print(message); if(modifier==0) modifier=1; double volume_trade=(volume_total==0)?Lot_Default: NormalizeDouble(MathAbs(volume_total)*(1+modifier),Lot_Digits); TradeSell(volume_trade,true); } if(type_close) if(volume_total!=0) { string message=_Symbol+": CLOSE LEVEL TRIGGERED"; if(Auto_Alerts) Alert(message); else Print(message); TradeCloseAll(true); ObjectSetString(0,name,OBJPROP_TEXT,"EXIT"); } if(type_alert) { string message=_Symbol+": "+DoubleToString(trigger,_Digits)+" LEVEL REACHED"; if(Auto_Alerts) Alert(message); else Print(message); ObjectSetString(0,name,OBJPROP_TEXT,"LEVEL"); } if(type_disable) { if(Auto_Alerts) Alert(_Symbol+": ALL LINES DISABLED"); else Print(_Symbol+": ALL LINES DISABLED"); DisableAllLines(); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void DisableAllLines() { for(int i=0; i=0; i--) { if(!position.SelectByIndex(i)) continue; if(position.Magic()!=Magic_Number) continue; if(position.Symbol()!=_Symbol) continue; TradeClose(position.Ticket()); } #else for(int i=OrdersTotal()-1; i>=0; i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderMagicNumber()!=Magic_Number) continue; if(OrderSymbol()!=_Symbol) continue; TradeClose(OrderTicket()); } #endif } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void TradeClose(long ticket) { bool check=false; #ifdef __MQL5__ for(int i=0;i=0; i--) { if(!position.SelectByIndex(i)) continue; if(position.Magic()!=Magic_Number) continue; if(position.Symbol()!=_Symbol) continue; double open=position.PriceOpen(); double stop=position.StopLoss(); double take=position.TakeProfit(); int type=position.PositionType(); if(type==POSITION_TYPE_BUY) { double price=SymbolInfoDouble(_Symbol,SYMBOL_BID); double trail=NormalizeDouble(price-Trail_Size*_Point,_Digits); if(price>=open+Trail_Start*_Point) if(trail>stop) TradeModify(position.Ticket(),open,trail,take); } if(type==POSITION_TYPE_SELL) { double price=SymbolInfoDouble(_Symbol,SYMBOL_ASK); double trail=NormalizeDouble(price+Trail_Size*_Point,_Digits); if(price<=open-Trail_Start*_Point) if(trail=0; i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderMagicNumber()!=Magic_Number) continue; if(OrderSymbol()!=_Symbol) continue; double open=OrderOpenPrice(); double stop=OrderStopLoss(); double take=OrderTakeProfit(); int type=OrderType(); if(type==OP_BUY) { double price=MarketInfo(_Symbol,MODE_BID); double trail=NormalizeDouble(price-Trail_Size*_Point,_Digits); if(price>=OrderOpenPrice()+Trail_Start*_Point) if(trail>OrderStopLoss()) TradeModify(OrderTicket(),open,trail,take); } if(type==OP_SELL) { double price=MarketInfo(_Symbol,MODE_ASK); double trail=NormalizeDouble(price+Trail_Size*_Point,_Digits); if(price<=OrderOpenPrice()-Trail_Start*_Point) if(trail