Missing one single line

 

After much trial and error, after many x rated words and telling the computer to X - off I am just down to one single thing in my EA.

I have learned to make my EA one function at a time. And now, if possible I just need help with the last final thing.

I need the following to be programmed into the code.

When I am 10 pips in profit, that will be my new close target. So if the trade turns (lets say it goes to 12) and goes back... I close the trade at 10 pips plus.

BUT, I am also using a trail stop so it must only overwrite the trail stop if the trail stop (lets say it is 20) has reached the 30 pips in profit to set the close line at 10 pips.........



So, ehh,, anyone know if I can do this? and if so.. how and where in my code would I put this?

Thanks for any help you can offer.

 
Are you just talking about setting a "Take Profit" ?
 
cloudbreaker wrote >>
Are you just talking about setting a "Take Profit" ?


Nope, I wish it was that simple :D

What I want is this. I have a trail stop, and I have gotten the program to the point that 9 out of 10 trades are in 10 pips or more profit. When it goes for a good run I want the trail stop to do its job so it picks up the nice profits. But, I also want the functionality that when a trade breaks 10 pips in profit. It will automaticly close the order IF the market turns and goes down again. So lets say it goes up to 14 pips profit and turns down, when it hits 10 pips profit mark...close and take the 10 pips profit.

Hope that made it clearer.
 

Hmm, perhaps..

Run with a stop - loss of X pips.

THen have a trail-stop that starts of 10 pips profit

Is that at all possible?

 

:D The X-Words....

Of course this is possible, but what you just described is a trailing stop.

So here's how far I have understood it:

1. Step:

You are up 10 Pips => Nothing happens

2. Step:

The profit rose to 10 + x (not in the meaning of X-Words) Pips => Stop loss is moved to 10 Pips

3. Step:

The Profit rose to 10 + x + y Pips => Stop Loss is moved to 10 + y Pips

Is that the right understanding?

 

Hm, let me see.

Yes, I think we are talking the same language now... :D

I got a trail stop that is working great on the larger movement. But.. as we all know not all movement is of the larger kind. Actually most are not.

most of my trades are in 10 - 20 pips plus mark before they turn and go the other way.

So if I can have a 10 pips from entry price closing point.... BUT only if the trade turns and goes against you (if it passes the 10 pips profit from entry point and keeps going.. let it go.. that is what the trail stop is there for) I will actually have a profit on 8 out of 10 trades. And that gentlemen.. (and potential ladies) are great odds :)

 

Ok, just quickly wrote this, which certainly will be optimizable...but should work for now.

So, embed the TrailManage-Function into your code and pass the order numbers on.

For Passing the order numbers on I will give you an Example:

for(int n=0; n<=OrdersTotal; n++)
   {
   if(OrderSelect(n, SELECT_BY_POS,MODE_TRADES)==true)
      {
      TrailManage(OrderTicket);
      }
   else                                                                             //If order could not be selected
      {
      Alert("Could not select order no. ", Orderidentification," for passing on to trailing function due to following Error: ", ErrorDescription(GetLastError()));
      }
   }
And here is the TrailManage-Function

#include <stderror.mqh>                         //Important for error code description

extern int TrailStartLevel                      //Defines the first level from entry point
extern int TrailDistance                        //Defines the Price distance the stop trails after

//Variables global
double Trailing[];
                       
int TrailManage (int OrderIdentification)       //OrderIdentification is the ticket number of the order to check
   {
   //Checking Function
   if(OrderSelect(OrderIdentification, SELECT_BY_TICKET)==true)                     //Selecting Order
      {
      if(OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT ||OrderType()==OP_BUYSTOP) //Verifying Order direction for calculations
         {
         if(Trailing[OrderIdentification]>0)                                        //Checking if it has already trailed/is active
            {
            if(Close[0]-OrderStopLoss()>TrailDistance*Point)                        //Cheking if price rose any higher
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-TrailDistance*Point,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
               }
            }
         else                                                                       //If order has not yet been trailed...
            {
            if(Close[0]-OrderOpenPrice()>= TrailStartLevel*Point + TrailDistance*Point)   //checking if it verifies for trailing
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-TrailDistance*Point,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
               Trailing[OrderIdentification]=1;
               }
            }
         }
      else                                                                          //If order is short
         {
         if(Trailing[OrderIdentification]>0)
            {
            if(OrderStopLoss()-Close[0]>TrailDistance*Point)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+TrailDistance*Point,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
               }
            }
         else
            {
            if(OrderOpenPrice()-Close[0]>= TrailStartLevel*Point + TrailDistance*Point)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+TrailDistance*Point,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
               Trailing[OrderIdentification]=1;
               }
            }
         }
      }
   else                                                                             //If order could not be selected
      {
      Alert("Could not select order no. ", OrderIdentification," for trailing due to following Error: ", ErrorDescription(GetLastError()) );
      }
   return(1);
   }



Hope it helps :D!!
 

ops.. ohh, will look at it and try to implement it.. :) thanks

This is actually really funny since I have no clue really yet...getting to grips with it bit by bit :D

 

Ah, ok,

so you are not known to MQL, are you?

 

getting there.. bit by bit :D

 

Ok, then I'll leave you going your way....

Reason: