Page 1 of 3 123 LastLast
Results 1 to 10 of 23
 7 Attachment(s)    

Thread: Take Profit Increment - Help please

  1. #1

    Question Take Profit Increment - Help please

    I have the following code, but it is not working, please help to correct it, thanks in advance.

    void TPI()
    {
    int cnt,total=OrdersTotal();
    for(cnt=0;cnt<total;cnt++)
    {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic)
    {
    if(OrderType()==OP_BUY)
    {
    if((Bid-OrderOpenPrice())/(point*digits)>=20) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()+10*point,digits),OrderTa keProfit(),0,Blue);
    if((Bid-OrderOpenPrice())/(point*digits)>=30) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()+15*point,digits),OrderTa keProfit(),0,Blue);
    if((Bid-OrderOpenPrice())/(point*digits)>=40) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()+25*point,digits),OrderTa keProfit(),0,Blue);
    if((Bid-OrderOpenPrice())/(point*digits)>=50) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()+35*point,digits),OrderTa keProfit(),0,Blue);
    if((Bid-OrderOpenPrice())/(point*digits)>=60) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()+45*point,digits),OrderTa keProfit(),0,Blue);
    if((Bid-OrderOpenPrice())/(point*digits)>=70) TrailingStop=15;
    return(0);
    }
    else
    {
    if((OrderOpenPrice()-Ask)/(point*digits)>=20) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()-10*point,digits),OrderTakeProfit(),0,Red);
    if((OrderOpenPrice()-Ask)/(point*digits)>=30) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()-15*point,digits),OrderTakeProfit(),0,Red);
    if((OrderOpenPrice()-Ask)/(point*digits)>=40) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()-25*point,digits),OrderTakeProfit(),0,Red);
    if((OrderOpenPrice()-Ask)/(point*digits)>=50) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()-35*point,digits),OrderTakeProfit(),0,Red);
    if((OrderOpenPrice()-Ask)/(point*digits)>=60) OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(OrderOpenPrice()-45*point,digits),OrderTakeProfit(),0,Red);
    if((OrderOpenPrice()-Ask)/(point*digits)>=70) TrailingStop=15;
    return(0);
    }
    }
    }
    }

  2. #2

    Default

    Code:
    void TPI()
    {
    double newSL;
    int cnt,total=OrdersTotal();
    for(cnt=0;cnt<total;cnt++)
    {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic)
    {
    if(OrderType()==OP_BUY)
    {
    if((Bid-OrderOpenPrice())>=20*Point) newSL=OrderOpenPrice()+10*point;//you will need to adjust this for 3/5 digit brokers
    if((Bid-OrderOpenPrice())>=30*Point) newSL=OrderOpenPrice()+15*point;
    if((Bid-OrderOpenPrice())>=40*Point) newSL=OrderOpenPrice()+25*point;
    if((Bid-OrderOpenPrice())>=50*Point) newSL=OrderOpenPrice()+35*point;
    if((Bid-OrderOpenPrice())>=70*Point) newSL=OrderOpenPrice()+45*point;
    if((Bid-OrderOpenPrice())>=70*Point) newSL=Bid-15*Point;
    
    newSL=NormalizeDouble(newSL,Digits);
    if(newSL>OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,OrderTa keProfit(),0,Blue);
    }
    else
    {//and so on ....
    }
    }
    //return(0); there's no need to return zero because void functions return zero anyway
    }
    }

  3. #3

    Thumbs up

    Quote Originally Posted by jezzer1961 View Post
    Code:
    void TPI()
    {
    double newSL;
    int cnt,total=OrdersTotal();
    for(cnt=0;cnt<total;cnt++)
    {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic)
    {
    if(OrderType()==OP_BUY)
    {
    if((Bid-OrderOpenPrice())>=20*Point) newSL=OrderOpenPrice()+10*point;//you will need to adjust this for 3/5 digit brokers
    if((Bid-OrderOpenPrice())>=30*Point) newSL=OrderOpenPrice()+15*point;
    if((Bid-OrderOpenPrice())>=40*Point) newSL=OrderOpenPrice()+25*point;
    if((Bid-OrderOpenPrice())>=50*Point) newSL=OrderOpenPrice()+35*point;
    if((Bid-OrderOpenPrice())>=70*Point) newSL=OrderOpenPrice()+45*point;
    if((Bid-OrderOpenPrice())>=70*Point) newSL=Bid-15*Point;
    
    newSL=NormalizeDouble(newSL,Digits);
    if(newSL>OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,OrderTa keProfit(),0,Blue);
    }
    else
    {//and so on ....
    }
    }
    //return(0); there's no need to return zero because void functions return zero anyway
    }
    }
    Thank you very much! Please could you check if the following code is right?

    void TPI()
    {
    double newSL;
    int cnt,total=OrdersTotal();
    for(cnt=0;cnt<total;cnt++)
    {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic)
    {
    if(OrderType()==OP_BUY)
    {
    if((Bid-OrderOpenPrice())/(point*digits)>=20) newSL=OrderOpenPrice()+10*point;
    if((Bid-OrderOpenPrice())/(point*digits)>=30) newSL=OrderOpenPrice()+15*point;
    if((Bid-OrderOpenPrice())/(point*digits)>=40) newSL=OrderOpenPrice()+25*point;
    if((Bid-OrderOpenPrice())/(point*digits)>=50) newSL=OrderOpenPrice()+35*point;
    if((Bid-OrderOpenPrice())/(point*digits)>=60) newSL=OrderOpenPrice()+45*point;
    if((Bid-OrderOpenPrice())/(point*digits)>=70) TrailingStop=15; MoveTrailingStop(); //From this level I want to set a trailing stop of 15 points and call the trailing stop function
    newSL=NormalizeDouble(newSL,digits);
    if(newSL>OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,O rderTakeProfit(),0,Blue);

    }
    else
    {
    if((OrderOpenPrice()-Ask)/(point*digits)>=20) newSL=OrderOpenPrice()-10*point;
    if((OrderOpenPrice()-Ask)/(point*digits)>=30) newSL=OrderOpenPrice()-15*point;
    if((OrderOpenPrice()-Ask)/(point*digits)>=40) newSL=OrderOpenPrice()-25*point;
    if((OrderOpenPrice()-Ask)/(point*digits)>=50) newSL=OrderOpenPrice()-35*point;
    if((OrderOpenPrice()-Ask)/(point*digits)>=60) newSL=OrderOpenPrice()-45*point;
    if((OrderOpenPrice()-Ask)/(point*digits)>=70) TrailingStop=15; MoveTrailingStop(); //From this level I want to set a trailing stop of 15 points and call the trailing stop function
    newSL=NormalizeDouble(newSL,digits);
    if(newSL<OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,O rderTakeProfit(),0,Red);

    }
    }
    }
    }
    Last edited by szmvscla; 06-17-2009 at 11:25.

  4. #4

    Default

    What is "digits" and why have you added it to the condition lines? This now does not make sense unless you have defined it correctly elsewhere.

    Why also do you need to hop to another function (MoveTrailingStop())? This element can be done from within the existing function as I have shown.

  5. #5

    Arrow

    Quote Originally Posted by jezzer1961 View Post
    What is "digits" and why have you added it to the condition lines? This now does not make sense unless you have defined it correctly elsewhere.

    Why also do you need to hop to another function (MoveTrailingStop())? This element can be done from within the existing function as I have shown.
    // Broker digit function
    if(Digits<4)
    {
    point=0.01;
    digits=2;
    }
    else
    {
    point=0.0001;
    digits=4;
    }


    return(0);
    }

    void MoveTrailingStop()
    {
    int cnt,total=OrdersTotal();
    for(cnt=0;cnt<total;cnt++)
    {
    OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic)
    {
    if(OrderType()==OP_BUY)
    {
    if(TrailingStop>0&&Ask>NormalizeDouble(OrderOpenPr ice()+TrailingProfit*point,digits))
    {
    if((NormalizeDouble(OrderStopLoss(),digits)<Normal izeDouble(Bid-point*(TrailingStop+TrailingStep),digits))||(Order StopLoss()==0))
    {
    OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(Bid-point*TrailingStop,digits),OrderTakeProfit(),0,Blu e);
    return(0);
    }
    }
    }
    else
    {
    if(TrailingStop>0&&Bid<NormalizeDouble(OrderOpenPr ice()-TrailingProfit*point,digits))
    {
    if((NormalizeDouble(OrderStopLoss(),digits)>(Norma lizeDouble(Ask+point*(TrailingStop+TrailingStep),d igits)))||(OrderStopLoss()==0))
    {
    OrderModify(OrderTicket(),OrderOpenPrice(),Normali zeDouble(Ask+point*TrailingStop,digits),OrderTakeP rofit(),0,Red);
    return(0);
    }
    }
    }
    }
    }
    }

    Can you understand now?

  6. #6

    Default

    No!

    If your Digits are 2 or 4, your integer "digits will need to equal 1.

    If your Digits are 3 or 5, your integer "digits" will need to equal 10.

    Don't include your own double "point". Instead leave it as the MT4 double Point.

  7. #7
    Member
    Join Date
    May 2009
    Location
    Gold Coast, Australia
    Posts
    55

    Default

    Hey szmvscla,

    Not to be rude but I have been trying to do the exact stepping stop function, as you may have seen on another post of mine.....(without success). I wanted to be able to put all my profit/step amounts in the 'extern int = ' for easy management of changing values, but I cant code to save my life.
    Could you post any global varriable/int start..etc code that goes with your above code so that I might be able to try to get it to work for me.

    If not thanks anyway and Trade Well.

    Dono

  8. #8

    Default

    Quote Originally Posted by Dono View Post
    Hey szmvscla,

    Not to be rude but I have been trying to do the exact stepping stop function, as you may have seen on another post of mine.....(without success).

    Dono
    Firstly, does the EA compile with and without the code for the stop-loss function added? I find that when I type blocks of code into a message box on a forum, I frequently make syntax errors (maybe a typo or missing semi-colon or an odd number of brackets). If I had used MetaEditor, I would have seen straight away that it didn't compile, but typing straight into a message box is obviously different. I then read back through the thread at a later date and find myself editing errors that I've made.

    On the basis that it compiles OK, are you calling the function from the appropriate place in the loop? If you are using a stop-loss system like this, you will need to call the function from towards the top of the start() function so that the stop-loss is re-calculated with every incoming tick. With other types of variable stop-loss, it may only be necessary to adjust the stop at new bar open, in which case you would call the function from a different part of the loop.

    Finally, if it still doesn't work, you will need to paste or attach the whole EA so that somebody can debug it.
    Last edited by jezzer1961; 06-18-2009 at 07:48.

  9. #9

    Thumbs up

    Quote Originally Posted by jezzer1961 View Post
    Firstly, does the EA compile with and without the code for the stop-loss function added? I find that when I type blocks of code into a message box on a forum, I frequently make syntax errors (maybe a typo or missing semi-colon or an odd number of brackets). If I had used MetaEditor, I would have seen straight away that it didn't compile, but typing straight into a message box is obviously different. I then read back through the thread at a later date and find myself editing errors that I've made.

    On the basis that it compiles OK, are you calling the function from the appropriate place in the loop? If you are using a stop-loss system like this, you will need to call the function from towards the top of the start() function so that the stop-loss is re-calculated with every incoming tick. With other types of variable stop-loss, it may only be necessary to adjust the stop at new bar open, in which case you would call the function from a different part of the loop.

    Finally, if it still doesn't work, you will need to paste or attach the whole EA so that somebody can debug it.
    So, please, if you can take a the code, the EA is attached. Thanks in advance!
    Attached Files Attached Files

  10. #10

    Arrow

    Quote Originally Posted by Dono View Post
    Hey szmvscla,

    Not to be rude but I have been trying to do the exact stepping stop function, as you may have seen on another post of mine.....(without success). I wanted to be able to put all my profit/step amounts in the 'extern int = ' for easy management of changing values, but I cant code to save my life.
    Could you post any global varriable/int start..etc code that goes with your above code so that I might be able to try to get it to work for me.

    If not thanks anyway and Trade Well.

    Dono
    I am sorry, but my code is not working too, let's wait for our friend Jeezer to check it if possible.

Similar Threads

  1. Replies: 6
    Last Post: 02-18-2016, 21:12
  2. EA źNetwork For Profit╗.
    By NetworkFP in forum Commercial expert advisors
    Replies: 19
    Last Post: 08-24-2012, 19:35
  3. Fx Profit EA
    By bnbb2004 in forum Ideas for expert advisors
    Replies: 8
    Last Post: 05-18-2012, 20:23
  4. (REQ) Add a take profit feature to an EA
    By Meister_Propper in forum Ideas for expert advisors
    Replies: 1
    Last Post: 05-24-2010, 11:37
  5. Trailing stop/TP increment - Help please
    By szmvscla in forum MQL programming
    Replies: 4
    Last Post: 06-11-2009, 03:21

Tags for this Thread

breakeven, broker, brokers, change, color, eas, eur, eur/usd, live, low, magic, mql, mql5, mt4, profit, sells, signal, slippage, stop, system, thank you, time, trading, trailing, trailingstep, trailingstop, usd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •