//+------------------------------------------------------------------+ //| AO_Lightning.mq5 | //| Evgeny Kravchenko | //| https://www.mql5.com/ru/users/evgen333 | //+------------------------------------------------------------------+ #property copyright "Evgeny Kravchenko" #property link "https://www.mql5.com/ru/users/evgen333" #property version "1.00" #include //--- input parameters input double LotFixed=0.01; //Lots input int LotFromPercent=0; //Lot From Percent input int Period_sma_slow=5; //Period sma slow input int Period_sma_fast=34; //Period sma fast input int Orders=10; //Orders max input int Magic=5632; //Magic number //---Create a object for opening positions CTrade trade; //---create variables and arrays int bars; int buy_total; int sell_total; double buy_profit; double sell_profit; double Bid; double Ask; double Lot; double AO[10]; double High[],Low[],Media[]; datetime Time[]; datetime time_bar=0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set the magic number trade.SetExpertMagicNumber(Magic); bars=Period_sma_fast+Period_sma_slow; ArrayResize(Media,bars); Alert("AO_Lightning Load"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //---Let's check how many bars if(Bars(_Symbol,PERIOD_CURRENT)0) { Alert("Close Sell ",sell_profit); close_sell(_Symbol); } if(buy_totalAO[1]) { //---Close buy orders if(buy_total>0) { Alert("Close Buy ",buy_profit); close_buy(_Symbol); } if(sell_total0) return(true); else return(false); } //+------------------------------------------------------------------+ //| Low | //+------------------------------------------------------------------+ bool low(string symbol,ENUM_TIMEFRAMES timeframe,double &data[]) { ArraySetAsSeries(data,true); int copied=CopyLow(symbol,timeframe,0,bars,data); if(copied>0) return(true); else return(false); } //+------------------------------------------------------------------+ //| high | //+------------------------------------------------------------------+ bool high(string symbol,ENUM_TIMEFRAMES timeframe,double &data[]) { ArraySetAsSeries(data,true); int copied=CopyHigh(symbol,timeframe,0,bars,data); if(copied>0) return(true); else return(false); } //+------------------------------------------------------------------+ //| info_order | //+------------------------------------------------------------------+ void info_order(string simb,int magic) { buy_total=0; sell_total=0; buy_profit=0.0; sell_profit=0.0; for(int i=0; i0) { lot=MathFloor(Free*proc/contrakt/Lot_step)*Lot_step; } if(lotLot_max) { lot=Lot_max; } return(NormalizeDouble(lot,2)); } //+------------------------------------------------------------------+ //| CheckMoneyForTrade | //+------------------------------------------------------------------+ bool CheckMoneyForTrade(string symb,double lots,ENUM_ORDER_TYPE type,double price) { string eror=""; //--- value of necessary and free margin double margin,free_margin=AccountInfoDouble(ACCOUNT_MARGIN_FREE); //--- call the validation function if(!OrderCalcMargin(type,symb,lots,price,margin)) { eror="Error in Function CheckMoneyForTrade "; Print("Error in ",__FUNCTION__," code=",GetLastError()); return(true); } //--- if there is not enough money for the operation if(margin>free_margin) { eror="Not enough money for "+EnumToString(type)+" "+DoubleToString(lots,2)+" "+symb+". "; //--- report an error and return true MessageBox(eror,NULL,0); Print(eror); return(true); } //--- the check was successful return(false); } //+------------------------------------------------------------------+ //| normalPrice | //+------------------------------------------------------------------+ bool normalPrice(double &price) { double tick_size_simb=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE); if(tick_size_simb>0) { int ratio=(int)MathRound(price/tick_size_simb); if(MathAbs(ratio*tick_size_simb-price)>0.0000001) { price=NormalizeDouble(ratio*tick_size_simb,_Digits); return true; } } return false; } //+------------------------------------------------------------------+ //| close_buy | //+------------------------------------------------------------------+ void close_buy(string simb) { while(buy_total>0) { for(int i=0; i0) { for(int i=0; i