Стоп в без убыток как сделать? - страница 2

 
1Rakso >>:

наверно сложная функция, мне делал один прогер такую штуку я советник не сохранил, теперь гадаю как там было сделано....


может у кого есть кусок кода, не думаю что его не применял никто, или покажет где можно посмотреть, может я плохо искал?

Добавишь в начало советника

extern int    Tral        =    40;    //----

а это можно в конец

//---- Трейлинг стоп для открытых ордеров 
  if (total>0)
  for ( i = 0;  i < total;  i ++ )
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    {
    if(OrderType()==OP_SELL)
     {
     if(OrderOpenPrice()>Ask+Tral*Point)
      {
      OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE);
      }
     }
    }
   }
  if (total>0)
  for ( i = 0;  i < total;  i ++ )
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    {
    if(OrderType()==OP_BUY)
     {
     if(OrderOpenPrice()<Bid-Tral*Point)
      {
      OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE);
      }
     }
    }
   }
 
Да не то это все, вот нашел его код на почте, все таки профи dolsergon......
extern int 		NoLoss        =     0; 		// безубыток - (0-отключение)
extern int 		NoLoss_act    =    25;	   	// активация безубытка после профита...


// Orders control ========================================================
bool Orders.BuyClose; 
bool Orders.SellClose;
int Orders.Total;
int Orders.BuyTotal;
int Orders.SellTotal;
//```````````````````````````````````````````````````````````````````````
void Orders_Control() {
double spread = Ask - Bid;
		
Orders.BuyTotal = 0;
Orders.SellTotal = 0;
Orders.Total = OrdersTotal();
for (int i = 0; i < Orders.Total; i++) {
  	OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  	if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) {
		int ord.ticket = OrderTicket(); 
		int ord.type = OrderType();
		double ord.price = OrderOpenPrice();
		double ord.SL = OrderStopLoss();
		double ord.TP = OrderTakeProfit();
		double SL;
			
// BUY ``````````````````````````````````````````````````````````````
 if (ord.type == OP_BUY) {
 if (Orders.BuyClose) {
		if (OrderClose(ord.ticket, OrderLots(), Bid, Slippage)) {
		if (visual) PlaySound("ok.wav");
		Orders.BuyClose = false;
		}
		} else {
				
		Orders.BuyTotal++;
					
// Trail ````````````````````````````````````````````````````````````````````````
SL = -1;
      if (StopLoss > 0)
      if (ord.SL == 0) SL = ord.price - StopLoss*Point;
      
      if (TakeProfit > 0)
      if (ord.TP == 0)  ord.TP = ord.price  + spread + TakeProfit*Point;
				
      if (NoLoss != 0)
      if ( Bid >= (ord.price + NoLoss_act*Point) )
      if (SL < (ord.price + NoLoss_act*Point)) 	SL = ord.price + NoLoss*Point;	
					
		SL = NormalizeDouble(SL, Digits);
		ord.TP = NormalizeDouble(ord.TP, Digits);
		if (SL > ord.SL) {
		//Print("ASK="+Ask + "BID="+Bid + "price="+ord.price + "     " + ord.SL + " -> " + SL + ",   " + ord.TP);
		if (OrderModify(ord.ticket, ord.price, SL, ord.TP, 0, CLR_NONE)) {
		if (visual) {
		PlaySound("ok.wav");
		Sleep(PauseAfterOrder*1000);
		}
		}
		}
		}
  		}
  			
 // SELL ```````````````````````````````````````````````````````````````````````````````
  		if (ord.type == OP_SELL) {
  			if (Orders.SellClose) {
			if (OrderClose(ord.ticket, OrderLots(), Ask, Slippage)) {
				if (visual) PlaySound("ok.wav");
				Orders.SellClose = false;
				}
				} else {
				
				Orders.SellTotal++;
					
// Trail ````````````````````````````````````````````````````````````````````````````````
			SL = 9999999;
			if (ord.SL == 0) {
			ord.SL = SL;
			SL = ord.price + StopLoss * Point;
			}				
			if (TakeProfit > 0)    
			if (ord.TP == 0)  ord.TP = ord.price - spread - TakeProfit*Point;
				
			if (NoLoss != 0) 
				if ( Ask <= (ord.price - NoLoss_act*Point) ) 	
				if (SL > (ord.price - NoLoss*Point))  SL = ord.price - NoLoss*Point;
				
				SL = NormalizeDouble(SL, Digits);
				ord.TP = NormalizeDouble(ord.TP, Digits);
				if (SL < ord.SL) {
				if (OrderModify(ord.ticket, ord.price, SL, ord.TP, 0, CLR_NONE)) {
				if (visual) {
				PlaySound("ok.wav");
				Sleep(PauseAfterOrder*1000);
				}
				}
				}
				}
			        }	
			        } 
	                        }
	                  return;
                          }
 
Вот еще он трал делал с активацией на НМА, если кому надо.........
extern int 		Trail           = 25;   	// трал расстояние до HMA - (0-отключение)
extern int 		Trail_act       = 10; 		// активация трала после профита ...


void Trail() {
	
   int total = OrdersTotal();
   for (int i = 0; i < total; i++) {
  	OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  	if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) {
		int vOrderTicket = OrderTicket(); 
		double vOrderPrice = OrderOpenPrice();
		double vOrderSL = OrderStopLoss();
		double vOrderTP = OrderTakeProfit();
		double SL;
			
double indHMA1 = iCustom(Symbol(), Trail_HMA_TF, "VininI_HMA", Trail_HMAperiod, 3, 0, 0, 0, 1);
			
			
		if (OrderType() == OP_BUY) {
			SL = -1;
			if (vOrderSL == 0)    SL = vOrderPrice - StopLoss*Point;
			if (TakeProfit > 0)    if (vOrderTP == 0)    vOrderTP = Ask + TakeProfit*Point;
			if (Trail > 0) 
			if ( Bid >= (vOrderPrice + Trail_act*Point) ) 	SL = indHMA1 - Trail*Point;
			if (SL > vOrderSL) {
			PlaySound("ok.wav");
			OrderModify(vOrderTicket, vOrderPrice, SL, vOrderTP, 0, CLR_NONE);
			Sleep(5000);
			}
  			}
  			
		if (OrderType() == OP_SELL) {
			SL = 9999999;
			if (vOrderSL == 0) {
			vOrderSL = SL;
			SL = vOrderPrice + StopLoss * Point;
			}
			if (TakeProfit > 0)    if (vOrderTP == 0)    vOrderTP = Bid - TakeProfit*Point;
			if (Trail > 0) 
			if ( Ask <= (vOrderPrice - Trail_act*Point) ) 	SL = indHMA1 + Trail*Point;
			if (SL < vOrderSL) {
			PlaySound("ok.wav");
			OrderModify(vOrderTicket, vOrderPrice, SL, vOrderTP, 0, CLR_NONE);
			Sleep(5000);
			}
			}
        		} 
	                }
	          return;
                  }
 
можно еще вот так сделать, чередой стопов что то типа трала, жаль не могу достучатся до него наверно уехал отдыхать...
void Trail() {
	
  int total = OrdersTotal();
  for (int i = 0; i < total; i++) {
  	OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  	if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) {
		int vOrderTicket = OrderTicket(); 
		double vOrderPrice = OrderOpenPrice();
		double vOrderSL = OrderStopLoss();
		double vOrderTP = OrderTakeProfit();
		double SL;
			
			
	if (OrderType() == OP_BUY) {
		SL = -1;
		if (vOrderSL == 0)  SL = vOrderPrice - StopLoss*Point;
				
		if (TakeProfit > 0)
		if (vOrderTP == 0)  vOrderTP = Ask + TakeProfit*Point;
				
		if (NoLoss1 != 0) 
		if ( Bid >= (vOrderPrice + NoLoss1_act*Point) )
		if (SL < (vOrderPrice + NoLoss1*Point)) 	SL = vOrderPrice + NoLoss1*Point;	
					
			if (NoLoss2 != 0) 
			if ( Bid >= (vOrderPrice + NoLoss2_act*Point) )
			if (SL < (vOrderPrice + NoLoss2*Point)) 	SL = vOrderPrice + NoLoss2*Point;	
					
         			if (NoLoss3 != 0) 
				if ( Bid >= (vOrderPrice + NoLoss3_act*Point) )
				if (SL < (vOrderPrice + NoLoss3*Point)) 	SL = vOrderPrice + NoLoss3*Point;	
					
				if (SL > vOrderSL) {
				PlaySound("ok.wav");
				OrderModify(vOrderTicket, vOrderPrice, SL, vOrderTP, 0, CLR_NONE);
				Sleep(5000);
				}
  	        		}
  			
  		if (OrderType() == OP_SELL) {
				SL = 9999999;
				if (vOrderSL == 0) {
				vOrderSL = SL;
				SL = vOrderPrice + StopLoss * Point;
				}				
				if (TakeProfit > 0)    
				if (vOrderTP == 0)    vOrderTP = Bid - TakeProfit*Point;
				
		if (NoLoss1 != 0) 
			if ( Ask <= (vOrderPrice - NoLoss1_act*Point) ) 	
			if (SL > (vOrderPrice - NoLoss1*Point))  SL = vOrderPrice - NoLoss1*Point;
				
			if (NoLoss2 != 0) 
				if ( Ask <= (vOrderPrice - NoLoss2_act*Point) ) 	
				if (SL > (vOrderPrice - NoLoss2*Point))  SL = vOrderPrice - NoLoss2*Point;
				
		        		if (NoLoss3 != 0) 
					if ( Ask <= (vOrderPrice - NoLoss3_act*Point) ) 	
					if (SL > (vOrderPrice - NoLoss3*Point))  SL = vOrderPrice - NoLoss3*Point;
				
				if (SL < vOrderSL) {
				PlaySound("ok.wav");
				OrderModify(vOrderTicket, vOrderPrice, SL, vOrderTP, 0, CLR_NONE);
				Sleep(5000);
				}
			        }
  		                } 
	                        }
	                  return;
                          }
 
1Rakso >>:
Да не то это все, вот нашел


Да, твой код намного проще...