If 90% of TP -> Set New SL-> Set new TP... But why does it not work??!

 

If 90% of TP -> Set New SL-> Set new TP... But why does it not work??!

It either works only for the SL but not for the TP

if i hide the SL part-> it creates endless Takeprofits (everytime +210+210+210+210) <- actually after one Modification the Condition wouldnt be true, but it still goes on adding 210.

if (OrderSelect(LongOrder,SELECT_BY_TICKET) == true && OrderCloseTime()==0)
   {
   
   
if ((OrderTakeProfit()-OrderOpenPrice())*0.80 <= Ask - OrderOpenPrice()){
       
    if (OrderStopLoss()>0.1000 && OrderTakeProfit()>0.1000) {
   
        // SL Neu
        if ((OrderOpenPrice()+(OrderTakeProfit()-OrderOpenPrice())*0.80)-(_Points*210)>OrderStopLoss()){
        SL_Setzen = OrderModify( OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+(OrderTakeProfit()-OrderOpenPrice())*0.8)-(_Points*210),OrderTakeProfit(),0,Yellow); GetLastError();
      
        //Check
        if( SL_Setzen=false ) {GetLastError();Print("SL konnte nicht nachgesetzt werden");}
        if( SL_Setzen==true ) {Comment ("TPTRUE");Print("New StopLoss=",(OrderStopLoss()));//TPLongNew=true;
        
        
        //TP Neu
        double NewTP=OrderTakeProfit()+(_Points*210);
        TP_Setzen = OrderModify( OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NewTP,0,Yellow);
        RefreshRates();
        //check
        
        if( !OrderModify( OrderTicket(), OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+(_Points*210),0,Yellow) ) {GetLastError(); Print("TP2 konnte nicht gesetzt werden");}
        if( OrderModify( OrderTicket(), OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+(_Points*210),0,Yellow) ) {Print("New TakeProfit=",(OrderTakeProfit()));}
}}}}}
 
Bayne:

If 90% of TP -> Set New SL-> Set new TP... But why does it not work??!

It either works only for the SL but not for the TP

if i hide the SL part-> it creates endless Takeprofits (everytime +210+210+210+210) <- actually after one Modification the Condition wouldnt be true, but it still goes on adding 210.

Where does the 90% figure in your code?

I am not sure what you are trying to do but

if ((OrderTakeProfit()-OrderOpenPrice())*0.80 <= Ask - OrderOpenPrice())

for a long order surely you should be using Bid not Ask.

The code body is to be executed when price reaches 80% of Take Profit?


if (OrderStopLoss()>0.1000 && OrderTakeProfit()>0.1000)

Won't this always be true unless TP and SL are not set?

 

I think you can design new rule by this concept

Profit_in_points = Current_Profit/Current_Lot;

Move_TP_Start = 80 points;

Step_TP_move = 21 points;

Max_move_times = x;

for(int i = 0; i=x; i++)

 {

 if(Profit_in_points >= (Move_TP_Start + i*Step_TP_move) ) Move_TP();

 else break;

 }

Note: () meaning function call

 
 if( SL_Setzen=false )

should be

 if( SL_Setzen==false )


        if( !OrderModify( OrderTicket(), OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+(_Points*210),0,Yellow) )
           {GetLastError(); Print("TP2 konnte nicht gesetzt werden");}
        if( OrderModify( OrderTicket(), OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+(_Points*210),0,Yellow) )
           {Print("New TakeProfit=",(OrderTakeProfit()));}

I have made the above 4 lines instead of 2 to make it easier to read.

You have not updated OrderSelect() so it will still hold the previous TP value.

You are trying to modify the order 3 times with the same values. The 2nd and 3rd modify will always fail.

                  if( !OrderModify( OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NewTP,0,Yellow) )
                   {GetLastError(); Print("TP2 konnte nicht gesetzt werden");}
                  else
                   {Print("New TakeProfit=",DoubleToStr(NewTP,Digits));}
 
Keith Watford:

Where does the 90% figure in your code?

I am not sure what you are trying to do but

for a long order surely you should be using Bid not Ask.

The code body is to be executed when price reaches 80% of Take Profit?


Won't this always be true unless TP and SL are not set?

->Yes, the 90% was mentioned as 0.80% (forgot to change that sry)

->With Bid i want to check the possible Close Price (to the Price to open)-> in a LongOrder wouldnt that be the Ask?

->Yes

-> kind of true, but its purpose is only to check if the first SL & TP were set successfully (otherwise would be ==0 and then the next SLs & TPs wouldnt work)

@Pham Khanh Duy

Thank you, is that code only for the TP?

& why do you mention Lots in?     Profit_in_points = Current_Profit/Current_Lot;

Sorry but i dont understand the idea behind that concept: why do you say  i=0 & i=x in the following?       for(int i = 0; i=x; i++) (did you mean "for(int i = 0; i==x; i++)")

 
Bayne:

->With Bid i want to check the possible Close Price (to the Price to open)-> in a LongOrder wouldnt that be the Ask?

When a Buy/Long order is open it will always close at Bid

//if ((OrderTakeProfit()-OrderOpenPrice())*0.80 <= Ask - OrderOpenPrice())   //Wrong

if ((OrderTakeProfit()-OrderOpenPrice())*0.80 <= Bid - OrderOpenPrice())

//Or better still
if ((OrderTakeProfit()-OrderOpenPrice())*0.80 <= OrderClosePrice() - OrderOpenPrice())
 
Keith Watford:
if (OrderStopLoss()>0.1000 && OrderTakeProfit()>0.1000)

Won't this always be true unless TP and SL are not set?

Bayne:

-> kind of true, but its purpose is only to check if the first SL & TP were set successfully (otherwise would be ==0 and then the next SLs & TPs wouldnt work)

Then why not

if (OrderStopLoss()!=0 && OrderTakeProfit()!=0)
 ? Then the logic is understood by others reading your code