loop very big

Back to topics list To post a new topic, please log in or register
avatar
41
KeepMarcos 2016.03.05 22:24
 

Heey gus!

I'm trying to make a Trailling Stop

Bad, is very large. Is there something I'm missing?

 

Example:

OrdenOpenPrice() is 1.00000

 

OrdenOpenPrice() is 1.20  (STOPLOSS())

OrderOpenPrice() is 1.50 (STOPLOSS())

thank you for help. 

AutoStop=20;
AutoStop2=30;
int cnt, total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
      if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
      {

 if(OrderType()==OP_SELL)
         {
          double stnewprice = OrderOpenPrice();
          SLshell = stnewprice-AutoStop*MyPoint;
          double SLshell2 = stnewprice-40*MyPoint;
          if(OrderOpenPrice()-Bid > AutoStop*MyPoint) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLshell,0,0,clrGreen);
          
          if(OrderOpenPrice()-Bid > AutoStop2*MyPoint) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLshell2,0,0,clrGreen);

}}} 
avatar
13009
WHRoeder 2016.03.06 02:52 #
 

KeepMarcos:

OrdenOpenPrice() is 1.00000

OrdenOpenPrice() is 1.20  (STOPLOSS())

OrderOpenPrice() is 1.50 (STOPLOSS())

  1. Can't be all three. Your statement is illogical.
  2. SLshell = stnewprice-AutoStop*MyPoint;
    double SLshell2 = stnewprice-40*MyPoint;
    if(OrderOpenPrice()-Bid > AutoStop*MyPoint) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLshell,0,0,clrGreen);
    You only are checking against OOP You need to also check against the current SL to avoid Error=1
  3. You have two separate values SLshell and SLshell2. Make up your mind which is the trailing.
  4. double SL = ...
    if(OrderOpenPrice() > SL         // sell order
    && OrderStopLoss() - SL > _Point // Prevent Error 1
    ){
       modify = OrderModify(OrderTicket(),OrderOpenPrice(),SL,0,0,clrGreen);
    and Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  5.    for(cnt=0;cnt<total;cnt++)
    In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
avatar
872
eevviill 2016.03.06 11:13 #
 
KeepMarcos:

Heey gus!

I'm trying to make a Trailling Stop

Bad, is very large. Is there something I'm missing?

 

Example:

OrdenOpenPrice() is 1.00000

 

OrdenOpenPrice() is 1.20  (STOPLOSS())

OrderOpenPrice() is 1.50 (STOPLOSS())

thank you for help. 

Look at example. Maybe helps.

 extern int TrailingStart =0;
 extern int TrailingStop = 20;
 extern int TrailingStep =10;

///////////////////////////////////////////////////////////////////////////
 void Traling_Stop_f()
 {
  for(int i=0; i<OrdersTotal(); i++) 
  { 
    if(OrderSelect(i, SELECT_BY_POS))
    {
    if(OrderSymbol() == Symbol())
    {        
    if(OrderMagicNumber()==Magic)
    {

    if(OrderType()==OP_BUY) 
      { 
      if(Bid>=NormalizeDouble(OrderOpenPrice()+TrailingStart*point+TrailingStop*point,Digits)) 
      { 
        if(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(TrailingStop+TrailingStep)*point,Digits))
        {
        if(NormalizeDouble(OrderStopLoss(),Digits)!=NormalizeDouble(Bid-TrailingStop*point,Digits))
        {
        while(IsTradeContextBusy()) Sleep(200);
        RefreshRates();
          if(OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits), OrderTakeProfit(), 0, clrNONE))
          continue;
        } 
        }
      }
      } 
     else
    if(OrderType()==OP_SELL) 
      { 
      if(Ask<=NormalizeDouble(OrderOpenPrice()-TrailingStart*point-TrailingStop*point,Digits)) 
      { 
        if((NormalizeDouble(OrderStopLoss(),Digits)>NormalizeDouble(Ask+(TrailingStop+TrailingStep)*point,Digits)) || OrderStopLoss()==0) 
        {
        if(NormalizeDouble(OrderStopLoss(),Digits)!=NormalizeDouble(Ask+TrailingStop*point,Digits))
        {
        while(IsTradeContextBusy()) Sleep(200);
        RefreshRates();
          if(OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits), OrderTakeProfit(), 0, clrNONE))
          continue;
        }
        }
      }
      } 
    }
    }
    } 
  }
  
 }

 

 

avatar
41
KeepMarcos 2016.03.06 14:29 #
 
Thank you for responding eevviill and WHRoeder
Bad, I'm not change correctly =\

I need to change the stoploss when the price reaches 10 pips for example.

 The code below is correct. bad when the price reaches another 10 pips can not change.

:(((((

Help-me people!!!

make 5 days in this code line. I can not change :(((('

 *Sorry some error in English.

AutoStop=20;
AutoStop2=30;
int cnt, total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
      if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
      {

 if(OrderType()==OP_SELL)
         {
          double stnewprice = OrderOpenPrice();
          SLshell = stnewprice-AutoStop*MyPoint;
          double SLshell2 = stnewprice-40*MyPoint;
          if(OrderOpenPrice()-Bid > AutoStop*MyPoint) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLshell,0,0,clrGreen);
avatar
41
KeepMarcos 2016.03.06 15:41 #
 
   int cnt, total=OrdersTotal();
      for(cnt=0;cnt<total;cnt++)
      {
         if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
         {
            if(OrderType()==OP_BUY)
            {
               double stnewprice = OrderOpenPrice();
               SLbuy = stnewprice+AutoStop*MyPoint;
                           
               //if(Ask>SLbuy)   modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLbuy,0,0,clrGreen);
               if(stnewprice+20*MyPoint>stnewprice) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLbuy,0,0,clrGreen);
               if(stnewprice+40*MyPoint> stnewprice) modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewprice+40*MyPoint,0,0,clrGreen);
               
             
                
            }
      


this screen is my real doubts.

It is in an infinite loop. =(

avatar
872
eevviill 2016.03.06 16:39 #
 
 int cnt, total=OrdersTotal();
      for(cnt=0;cnt<total;cnt++)
Why you use construction like this?
Why not
      for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
avatar
872
eevviill 2016.03.06 16:41 #
 

Maybe like this

double stnewprice = OrderStopLoss(); 

  if( stnewprice<Bid-20*MyPoint)
avatar
41
KeepMarcos 2016.03.06 19:29 #
 
I do not have enough words to thank.

thank you eevviill.

tank you too WHRoader =))))) 

avatar
41
KeepMarcos 2016.03.06 19:29 #
 

CODE:

 int cnt, total=OrdersTotal();
      for(cnt=0;cnt<total;cnt++)
      {
         if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
         {
            if(OrderType()==OP_BUY)
            {  double st =  OrderStopLoss();
               double stnewprice = OrderOpenPrice();
               SLbuy = stnewprice+AutoStop*MyPoint;
              
                           
             
               if(Ask+35*MyPoint>st);  modify = OrderModify(OrderTicket(),OrderOpenPrice(),st+35*MyPoint,0,0,clrLightGreen);
                
            }

 

avatar
872
eevviill 2016.03.06 20:10 #
 
KeepMarcos:
I do not have enough words to thank.

thank you eevviill.

tank you too WHRoader =))))) 

My pleasure.
Back to topics list  

To add comments, please log in or register