//+------------------------------------------------------------------+ //| TSS1.mq4 | //| Copyright © 2010, Magellantech Software Corp. | //| http://www.tss.do.am | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Magellantech Software Corp." #property link "http://www.tss.do.am" //---- input parameters extern int Fast_MA=14; extern int Middle_MA=21; extern int Slow_MA=35; extern int rsi_period=22; extern string note="для 5х знаков, все значения *10"; extern int offset=3; extern double delta=0.0001; extern int SellSignalLevel=70;//was 90 extern int BuySignalLevel=70;//was 90 extern double lots=2; extern int TP=260;// was 270 extern int SL=200;// was 200 extern int RiskLevel = 41;// was 100 datetime SigLastTime=0; int magic = 26022010; datetime new_time; string File_Name="tse.dat"; int Buy_ticket; int Sell_ticket; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- FileDelete(File_Name); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int SellTickArr[]; int BuyTickArr[]; void MyOrderModify() { for(int i=0;iClose[0]"); //Alert(OP); if(OP>Close[0]) { if(((Close[0]+((SL)*Point))(OrderOpenPrice()+(SL/2)))) { OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+(SL*Point),Close[0]-(TP*Point),0,YellowGreen); } if(((Close[0]-OrderTakeProfit())<=((SL)*Point))&&((Close[0] + (SL*Point)) < OrderStopLoss() ) ) { OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+(SL*Point),Close[0]-(TP*Point),0,YellowGreen); } //Alert("||||||||||||||||||||||||||||||||||||||||||||||||||||Начинаю модифицировать!"); // if((Close[0]+((SL*2)*Point))OrderStopLoss())&&(OrderStopLoss()<(OrderOpenPrice()+(SL/2)))) OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL)*Point),Close[0]+(TP)*Point,0,LightSteelBlue); if(((OrderTakeProfit()-Close[0])<=((SL)*Point))&&((Close[0] - (SL*Point)) > OrderStopLoss() ) ) { OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL)*Point),Close[0]+(TP)*Point,0,LightSteelBlue); } //Alert("||||||||||||||||||||||||||||||||||||||||||||||||||||Начинаю модифицировать! BUY"); // if((Close[0]-((SL*2)*Point))>OrderStopLoss()) // OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL*2)*Point),Close[0]+(TP)*Point,0,LightSteelBlue); // if(((OrderTakeProfit()-Close[0])<=((SL)*Point))&&((Close[0] - (SL*Point)) > OrderStopLoss() ) ) // { // OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-((SL)*Point),Close[0]+(TP)*Point,0,LightSteelBlue); // } } } } } } void MyCloseAllOrderByPrice(double CurPrice,int MyOrderType) { //RefreshRates(); for(int i=0;i(CurPrice+(SL/2))) { OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),100,Black); } } if(MyOrderType==OP_BUY) { if(OrderOpenPrice()<(CurPrice-(SL/2))) { OrderClose(OrderTicket(),OrderLots(),OrderOpenPrice(),100,Black); } } /* kbi++; M_ob[kbi][0]=OrderTicket(); M_ob[kbi][1]=OrderOpenPrice(); M_ob[kbi][2]=OrderLots(); M_ob[kbi][3]=OrderType(); M_ob[kbi][4]=OrderMagicNumber(); M_ob[kbi][5]=OrderStopLoss(); M_ob[kbi][6]=OrderTakeProfit(); M_ob[kbi][7]=OrderProfit();*/ } } //Sleep(100); //RefreshRates(); } void MyCloseAllOrder(int MyOrderType) { //RefreshRates(); for(int i=0;i0) { DataRead=FileReadString(f); // чтение из файла index1=StringFind(DataRead, "|", 0); // Разделяем строку buf=StringSubstr(DataRead,0,index1); // Извлекаем сигнал на покупку SigBuy=StrToDouble(buf); // Преобразование типа данных index2=StringFind(DataRead, "|", index1+1); // Разделяем строку buf=StringSubstr(DataRead,index1+1,index2-1); // Извлекаем сигнал на продажу SigSell=StrToDouble(buf); // Преобразование типа данных buf=StringSubstr(DataRead,index2+1,index2+9); // Извлекаем вреия сигнала SigTime =StrToTime(buf); Alert("Прочитал"); if(SigLastTime!=SigTime) { Alert(" Время "+SigTime); if(SigBuy>=BuySignalLevel) { Alert(" Сигнал "+SigBuy); if(SigSell=5) { //if(Close[4]=SellSignalLevel) { Alert(" Сигнал "+SigSell); if(SigBuy=5) { //// if(Close[4]>Close[0]) // { // MyCloseAllOrder(OP_BUY);//сначала закрываем все такого же типа как собираемся открыть //} MyCloseAllOrderByPrice(Bid,OP_SELL); int sNewTP = TP;// + 10; Sell_ticket=OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 50, Close[0]+((SL)*Point), Bid-(sNewTP)*Point, "SELL_tss", magic, 0, Green); } else { //if(Close[4]>Close[0]) //{ // MyCloseAllOrder(OP_BUY);//сначала закрываем все такого же типа как собираемся открыть //} Alert(" Откр " ); MyCloseAllOrderByPrice(Bid,OP_SELL); Sell_ticket=OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 50, Close[0]+((SL)*Point), Bid-(TP)*Point, "SELL_tss", magic, 0, Green); } } // MyCloseAllOrder(OP_BUY); } } SigLastTime=SigTime; FileClose(f); int s_count=ArraySize(SellTickArr); int b_count=ArraySize(BuyTickArr); Comment(" TSS-1 "," Buy:",SigBuy," Sell:",SigSell," SellArCount:",s_count," BuyArCount:",b_count); } } int start() { // Alert(" Здесь "); // Comment(TP); // Sell_ticket=OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 50, Close[0]+((SL)*Point), Bid-(TP)*Point, "SELL_tss", magic, 0, Green); // return (0); MySendOrder(); int counted_bars=IndicatorCounted(); string CurrentSymbol =Symbol(); double CurrentClosePrice = iClose(CurrentSymbol,PERIOD_M1,0); if(CurrentClosePrice==0) { int LastError = GetLastError(); return(0); } int FileHandle = FileOpen(CurrentSymbol+".dat", FILE_BIN |FILE_WRITE); if(FileHandle>0) { string strPrice = CurrentClosePrice; FileWrite(FileHandle,strPrice);// Close[0] FileClose(FileHandle); } MySendOrder(); /* //---- // 1. определяем данные===================================================== double ma42_0 = NormalizeDouble(iMA(Symbol(), 0, Slow_MA, 0, 1, 0, 1), Digits); double ma42_1 = NormalizeDouble(iMA(Symbol(), 0, Slow_MA, 0, 1, 0, 2), Digits); double dif_ma42 = ma42_0 - ma42_1; //---- double ma21_0 = NormalizeDouble(iMA(Symbol(), 0, Middle_MA, 0, 1, 0, 1), Digits); double ma21_1 = NormalizeDouble(iMA(Symbol(), 0, Middle_MA, 0, 1, 0, 2), Digits); double dif_ma21 = ma21_0 - ma21_1; //---- double ma14_0 = NormalizeDouble(iMA(Symbol(), 0, Fast_MA, 0, 1, 0, 1), Digits); double ma14_1 = NormalizeDouble(iMA(Symbol(), 0, Fast_MA, 0, 1, 0, 2), Digits); double dif_ma14 = ma14_0 - ma14_1; //---- double rsi17_0 = NormalizeDouble(iRSI(Symbol(), 0, rsi_period, 0, 1), Digits); double rsi17_1 = NormalizeDouble(iRSI(Symbol(), 0, rsi_period, 0, 2), Digits); double dif_rsi17 = rsi17_0 - rsi17_1; //---- Comment("dif42 = "+dif_ma42, "\nma42_0="+ma42_0, " ma42_1="+ma42_1, "\n\ndif21 = "+dif_ma21, "\nma21_0="+ma21_0, " ma21_1="+ma21_1, "\n\ndif14 = "+dif_ma14, "\nma14_0="+ma14_0, " ma14_1="+ma14_1, "\n\ndifrsi = "+dif_rsi17, "\nrsi17_0="+rsi17_0, " rsi_17_1="+rsi17_1); // 1. ====================================================================== // 2. открытие позиций ===================================================== if(new_time!=Time[0]) { // 2.1 открытие бай if(rsi17_1<50 && rsi17_0>50) { if(dif_ma42>delta && dif_ma21>delta && dif_ma14>delta) { OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask,Digits), 3, Low[1]-offset*Point, Ask+TP*Point, "BUY_sidus", magic, 0, CLR_NONE); } } //================= // 2.2 открытие селл if(rsi17_1>50 && rsi17_0<50) { if(dif_ma42