Get a line object to substitute the trailing stop - page 2

 
deVries:

Please explain what kind of martingale strategy are you trying to make ???

Your code is full of strange coding....  that i get problems to understand what you try to do

you don't tell how your trailing is coded now

and now we get an opposite strategy where you in the loop of your orderstotal open new trades and refresh fresh fresh rates

this is the begin if the ea restarts what has there to happen  ???

  

Do you look in the closed trades for last closed trade if it is buy or sell if buy you want open sell

if last closed sell you want to open new buy trade ??

Question(s)

don't you have to know if there is still trades running ?? 

and what has to happen if there is no history of the EA in historytrades

 

So what did you wanna make the moment you started to code this ??

 


Hi deVries,

  You alert me for the fact that I do not need to get information about last type of order closed.

The strategy is:

 Start: there is no open orders

If price goes up then a Buy order is open, then if price don't reach the MinimumProfit and bounce back the amount of OppositeDistance a Sell order will open with a lot increase given by multiplier. Here if the Sell order do not reach the MinimumProfit and bounce back the amount of OppositeDistance a second Buy order will open and so on.

The same if price goes down.

Once price equals the amount given by MinimumProfit then Trail will start, if price bounce back all open orders will close.

Hope that gives you the clarification you need to help me.

The problem with the fail of Trailing stop is ok after I've change the direction of count the orders. Before I had the orders counting down and now is counting up and trail do not fail now.

Take your advise about getting the state of ea  at start I thing that the way to go is to first identify which orders in the pool are from the ea (if any) and if are == 0 then the ea can open orders. Here my doubt is if we have more than one order open how can figure out that this orders are ok and the ea can keep to opening orders ?

Thank you again

Luis 

 
luisneves:


Hi deVries,

  You alert me for the fact that I do not need to get information about last type of order closed.

The strategy is:

 Start: there is no open orders

    //Then if the EA has to restart check openorders of the EA first if this is true

       if not true the EA has to find out what trade it has open.... 

If price goes up then a Buy order is open, then if price don't reach the MinimumProfit and bounce back the amount of OppositeDistance a Sell order will open with a lot increase given by multiplier. Here if the Sell order do not reach the MinimumProfit and bounce back the amount of OppositeDistance a second Buy order will open and so on.

    // No open trade set buystop and sellstop order with xx pips distance from price that moment and one of them will hit certainly moment

       if buy or sell open delete old remaining stoptrade

       place opposite stoptrade from open trade xxx pips from orderopenprice first trade with new lotsize

       if this stoptrade hits you can close first trade and place new stoptrade where first started with your new multiplier lotsize

      Remember total losses  if you get in profit  don't close directly maybe with moving orderopenprice open stoptrade you can trail first moment

      if this moves over orderopenprice open trade you have i think the profit for sure to close open buy or sell that part you have first lotsize 

      if profit big enough close both trades  

 

The same if price goes down.

Once price equals the amount given by MinimumProfit then Trail will start, if price bounce back all open orders will close.

Hope that gives you the clarification you need to help me.

The problem with the fail of Trailing stop is ok after I've change the direction of count the orders. Before I had the orders counting down and now is counting up and trail do not fail now.

Take your advise about getting the state of ea  at start I thing that the way to go is to first identify which orders in the pool are from the ea (if any) and if are == 0 then the ea can open orders. Here my doubt is if we have more than one order open how can figure out that this orders are ok and the ea can keep to opening orders ?

Thank you again

Luis 

 

It is a dangerously strategy and it can blow up your account in a bad period where price bounce alot with support and resistance area
 
deVries:
It is a dangerously strategy and it can blow up your account in a bad period where price bounce alot with support and resistance area


Hi deVries,

 Thank you for your comments which are of up most importance for me. Nevertheless and with the objective to show only those orders that have to get processed  by the ea I've write these lines of code. Here I've a problem; When use Orders, which from what I understand should be only the orders sorted from orderstotal() that are present in the pool the ea keeps open orders. When I substitute that by orderstotal() the ea works fine. So of course that I'm sort out the orders from the pool in a wrong way. Is possible some help here ?

Luis 

 Orders = 0;
  for(int OpenOrders = OrdersTotal()-1; OpenOrders >= 0; OpenOrders--)
      {    
      if(!OrderSelect(OpenOrders,SELECT_BY_POS,MODE_TRADES))continue;
         {
        if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)
          {
          if(OrderType()== OP_BUY)
            {
              BuyAllowed = false;SellAllowed = true;
            } 
         else                   
            {
             BuyAllowed = true;SellAllowed = false;
            }     
            Orders = OrdersTotal();//<----------------- is this wrong way to sort out the orders from the ones that are not from this ea ?
            }
           }
         }
           
  return(0);   
   }

   //+------------------------------------------------------------------------------------------------------------------+ 
 int start()
 
   {//0 
   
                                 
    OTLastTick = OTCurrentTick;                      
    OTCurrentTick = Orders; //<---------------------------------------- if use orderstotal() is ok (....)
                     
    if(OTCurrentTick == 0 && OTLastTick > 0)
      {      
      BuyTrigger = Ask + OpenDistance * pips2dbl;
      SellTrigger = Bid - OpenDistance * pips2dbl;
      }                                  
    if(OTLastTick >= 2                                                
      && OTCurrentTick < OTLastTick
      && OTCurrentTick > 0)
      {
       CloseAllOnSL(); return;            
      }                                                                  
    if(OTCurrentTick > 0 && OTCurrentTick < MaxOrders)OpenOppositeOrder();              
    if(OTCurrentTick == MaxOrders &&  LastOrderProfit < - 0.2) CloseAll(); 
                   
    if(OTCurrentTick == 0)
      {
       BuyAllowed = true;  
       SellAllowed = true;      
 
//+------------------------------------------------------------------+
//|                                                         Luis.mq4 |
//|                               Copyright © 2013,  Tjipke de Vries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013,  Tjipke de Vries"
#property link      "https://forum.mql4.com/54215/"


extern string UserSettings        = "=== User Settings ===";
extern bool   DynamicLotSize      = false;
extern double PercentageToTrade   =   1;
extern double FixedLotSize        = 0.01;
extern double Multiplier          =   4;
extern int    MagicNumber         =  10;


int TotalOpenEA,TotalBuy,TotalSell,TotalBuyStop,
    TotalSellStop,TotalBuyLimit,TotalSellLimit;

//++++ These are adjusted for 5 digit brokers.
int     pips2points;      // slippage  3 pips    3=points    30=points
double  pips2dbl;         // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;      // DoubleToStr(dbl/pips2dbl, Digits.pips)
//---


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
    if(Digits % 2 == 1)  // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
     {pips2dbl = Point*10; pips2points = 10;   Digits.pips = 1;}
     else {pips2dbl = Point;    pips2points =  1;   Digits.pips = 0;}
     // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl       
      
    if(OrdersTotal() >0 )TotalOpenEA=OrdersTotal(); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- Number ONE to DO  ==>  CHECK OPEN TRADES
   if(TotalOpenEA > 0)
     {
      TotalOpenEA = 0;
      TotalBuy = 0;
      TotalSell =0;
      TotalBuyStop =0;
      TotalSellStop=0;
      TotalBuyLimit =0;
      TotalSellLimit =0;
      double BuyLots,SellLots,HighestLot;          <<=====  ATTENTION   Buylots for  ......      Selllots for ......   and HighestLot is for ....
      for(int i = OrdersTotal()-1; i >= 0 ; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
         if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;
         TotalOpenEA++;
         if(HighestLot < OrderLots())HighestLot=OrderLots();     <<====== HighestLot can be every OrderType()   
         //---- check order type
         if(OrderType()==OP_BUY)
           {
            TotalBuy++;
            if(OrderLots()> BuyLots)BuyLots=OrderLots();          <<===== This is OrderType()
           } 
//finish this loop for all OrderTypes      
      
      
      
      
        }//end loop
//   if(HighestLot==BuyLots)....
//   if(HighestLot==SellLots)....           
     }
      

   
   
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 finish this for all OrderTypes

 
deVries:

 

 finish this for all OrderTypes

 


Good Morning deVries,

So, I believe have done  what  you ask me to do. Here is de code:

 

 

Is anything wrong or missing ? 

Thanks is advance for your support and patience.

Luis

int start()
  {
//---- Number ONE to DO  ==>  CHECK OPEN TRADES
   if(TotalOpenEA > 0)
     {
      TotalOpenEA = 0;
      TotalBuy = 0;
      TotalSell =0;
      TotalBuyStop =0;
      TotalSellStop=0;
      TotalBuyLimit =0;
      TotalSellLimit =0;
      double BuyLots,SellLots,HighestLot;
      for(int i = OrdersTotal()-1; i >= 0 ; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
         if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;
         TotalOpenEA++;
         if(HighestLot < OrderLots())HighestLot=OrderLots();
         //---- check order type
         if(OrderType()==OP_BUY)
           {
            TotalBuy++;
            if(OrderLots()> BuyLots)BuyLots=OrderLots();
           } 
         if(OrderType()==OP_SELL)         
           {
            TotalSell++;
            if(OrderLots()> BuyLots)BuyLots=OrderLots();
           }
         if(OrderType()==OP_BUYSTOP)
           {
            TotalBuyStop++;
            if(OrderLots()> BuyLots)BuyLots=OrderLots();
            }
          if(OrderType()==OP_SELLSTOP
            {
             TotalSellStop++
             if(OrderLots()> BuyLots)BuyLots=OrderLots();
            }
          if(OrderType()==OP_BUYLIMIT)
            {
             TotalBuyLimit++;
             if(OrderLots()> BuyLots)BuyLots=OrderLots();
            }
          if(OrderType()==OP_SELLLIMIT)
            {
             TotalSellLimit++;
             if(OrderLots()> BuyLots)BuyLots=OrderLots();
                            
//finish this loop for all OrderTypes      
          
        }//end loop
//   if(HighestLot==BuyLots)....
//   if(HighestLot==SellLots)....           
     }
         
   
//----
   return(0);
  }
 
luisneves:


Is anything wrong or missing ? 

Thanks is advance for your support and patience.

Read the code you have added . . . .

if(OrderType()==OP_SELLSTOP
            {
             TotalSellStop++
             if(OrderLots()> BuyLots)BuyLots=OrderLots();
            }

 Why are you setting  BuyLots for a SELL STOP ?

 
RaptorUK:

Read the code you have added . . . .

 Why are you setting  BuyLots for a SELL STOP ?

 


Hi RaptorUK,

Right !

On Fridays seems that I'm a complete idiot (just not to mention the other days...)

Is updated now.

Thanks

Luis 

 
deVries:

Thank you Simon for the help

to Luis and all who read this goodday to you   ( don't know what timezone you live in )

Edit your post for updated code till now we can't see you have done it

Look also to the code i gave to you  a few attention might help


Hi deVries,

Which code do you refer, the one you ask to me to complete or your code inside the code that I've to moment ?  

 
luisneves:


Hi deVries,

Which code do you refer, the one you ask to me to complete or your code inside the code that I've to moment ?  


De code you gave yourself edit that message        you can't edit other persons messages

luisneves 2013.03.01 12:06

 
deVries:


De code you gave yourself edit that message        you can't edit other persons messages

luisneves 2013.03.01 12:06


Hi deVries,

In attach is the code, but something is wrong (...)

I've put out from the code Get History and get a new CloseOnSL () function to identify the last order closed by the ea and the proceed to call CloseAll () function.

Luis 

Update issue;

I get several errors and seem that some variables are not defined. While those variables are defined as global shouldn't be recognized ? 

Reason: