Gann super exit HELP

 

Hi all,

Please see if you can help me with this as all this is very confusing to me.

I'f got an exit strg that i think will work well but have now idea how to change the coding. Exit must work somthing like this!


When I make a trade the EA then automatically sets a TP to take half the lot size off when I reach 1:1 risk reward (e.g. my SL is 85 it sets a TP of 85) and with the remaining lot it moves the SL to BE + spread and sets some kind of a trailing stop or jumping stop (of a preconfigured size). It must also allow me to input an SL and a lot size.



Files:
 

Please use . . .

 
//-------------------------------------------------------------------1

extern int        Lookback=10;
extern double     Lots=0.1;
extern double     TP=60;
extern double     SL=40;
double            ssl[],Hld,Hlv,Lot;
bool              Ans, work;

//-------------------------------------------------------------------2

int init()
   {
//-----
//-----
   return(0);
   }

int deinit()
   {
//-----
//-----
   return(0);
   }
   
//-------------------------------------------------------------------3
int start()
{
   int      Ticket;
   int      Total;                        // Amount of orders in a window
   int      Buy_signal;
   int      Sell_signal;  
   int      Tip=-1;                       // Type of selected order (Buy=0,Sell=1)   
   double   Gann;
   double   Price;
   bool     Work=true;                    // EA will work.
   
//-------------------------------------------------------------------4
  // Preliminary processing
   if(Bars < Lookback)                               // Not enough bars
     {
      Alert("Not enough bars in the window. EA doesn't work.");
      return;                                        // Exit start()
     }
   if(Work==false)                                   // Critical error
     {
      Alert("Critical error. EA doesn't work.");
      return;                                        // Exit start()
     }
     
//-------------------------------------------------------------------5
//TRADING CRITERIA

   for(int i=Bars-Lookback;i>=0;i--)
     {
      if(Close[i]>iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_HIGH,i+1))
         Hld=1;
      else
        {
         if(Close[i]<iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_LOW,i+1))
            Hld=-1;
         else
            Hld=0;
        }
      if(Hld!=0)
         Hlv=Hld;
      if(Hlv==-1)
         ssl[i]=iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_HIGH,i+1);
      else
         ssl[i]=iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_LOW,i+1);   
     
     if (Open[i]>ssl[i+1] && Close[0+1]<=ssl[0+1])
         Buy_signal=1;
     if (Open[i]>ssl[i+1] && Close[0+1]>ssl[0+1]&& Open[0+1]<=ssl[0+1])
         Buy_signal=1;
     if (Open[i]<ssl[i+1] && Close[0+1]>=ssl[0+1])
         Sell_signal=1;
     if (Open[i]<ssl[i+1] && Close[0+1]<ssl[0+1]&& Open[0+1]>=ssl[0+1])
         Sell_signal=1;
     }
//------------------------------------------------------------------5
//ORDER ACCOUNTING
  
   Total=0;                                     // Amount of orders
   for(int e=1; e>=OrdersTotal(); e++)          // Loop through orders
     {
      if (OrderSelect(e-1,SELECT_BY_POS)==true) // If there is the next one
        {                                       // Analyzing orders:
         if (OrderType()>1)                     // Pending order found
           {
            Alert("Pending order detected. EA doesn't work.");
            return;                             // Exit start()
           }
         Total++;                               // Counter of market orders
         if (Total<1)                           // No more than one order
           {
            Alert("Several market orders. EA doesn't work.");
            return;                             // Exit start()
           }
         Ticket=OrderTicket();                  // Number of selected order
         Tip   =OrderType();                    // Type of selected order
         Price =OrderOpenPrice();               // Price of selected order
         Lot   =OrderLots();                    // Amount of lots
        }
     }
   
//-------------------------------------------------------------------6
//BUY ORDER
        if (Buy_signal==1)
            {
            Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-SL*Point,Ask+TP*Point,"My EA",12345,0,Green);
            if(Ticket>0)
               {
               if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES))
                     Print("BUY order opened : ",OrderOpenPrice());
               }
               else Print("Error opening BUY order : ",GetLastError());
               return(0);
            }
         
//-------------------------------------------------------------------7
//SELL ORDER

      if (Sell_signal==1)
            {      
            Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+SL*Point,Bid-TP*Point,"MyEA",12345,0,Red);
            if(Ticket>0)
               {
               if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES))
                     Print("SELL order opened : ",OrderOpenPrice());
               }
               else Print("Error opening SELL order : ",GetLastError());
               return(0);
            }      
         
//-------------------------------------------------------------------8
// Closing orders
   while(true)                                  // Loop of closing orders
     {
      if (Tip==0 && Sell_signal==1)              // Order Buy is opened..
        {                                       // and there is criterion to close
         Alert("Attempt to close Buy ",Ticket,". Waiting for response..");
         RefreshRates();                        // Refresh rates
         Ans=OrderClose(Ticket,Lot,Bid,2);      // Closing Buy
         if (Ans==true)                         // Success :)
           {
            Alert ("Closed order Buy ",Ticket);
            break;                              // Exit closing loop
           }
         return;                                // Exit start()
        }
//---------------------------- 
      if (Tip==1 && Buy_signal==1)                // Order Sell is opened..
        {                                       // and there is criterion to close
         Alert("Attempt to close Sell ",Ticket,". Waiting for response..");
         RefreshRates();                        // Refresh rates
         Ans=OrderClose(Ticket,Lot,Ask,2);      // Closing Sell
         if (Ans==true)                         // Success :)
           {
            Alert ("Closed order Sell ",Ticket);
            break;                              // Exit closing loop
           }
         
         return;                                // Exit start()
        }
      break;                                    // Exit while

   return(0);
}
}
Is that correct?
 
hawknismo:
Is that correct?
Yes, you could just have simply edited your first post, but it's OK. It makes it easier for people to read.
 
You could contact doublemeteor he seems to have the same/similar EA as you do . . . https://www.mql5.com/en/forum/121063
 

o yes du!

stupid me sorry about that

 

that was in 2010 though and he does not want the same done!

 
Raptor were can i find an example of a code like this
 
hawknismo:
Raptor were can i find an example of a code like this
Have a look at some of the links here: http://crum.be/part
 

No help but thx any way

 
hawknismo:
When I make a trade the EA then automatically sets a TP to take half the lot size off when I reach 1:1 risk reward (e.g. my SL is 85 it sets a TP of 85) and with the remaining lot it moves the SL to BE + spread and sets some kind of a trailing stop or jumping stop (of a preconfigured size). It must also allow me to input an SL and a lot size.

  1. SRC - addressed
  2.        Total++;                               // Counter of market orders
             if (Total<1)                           // No more than one order
    Will never work, move your test outside the loop.
  3. Move the OrderSelect loop above your opening code and add the partial close and trailing stop there.
  4. The biggest problem is only partial close once. I'd test for SL below BE. Once you know you want to partial close, move the SL, then partial close. That way you don't have to remember the factoid and find the new ticket number etc.
  5. No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
Reason: