Trailing Stops and Trailing Profit - page 4

 

Yes, I've understood. It's not possible to compare as cnt will have value like 3,2,1 while Ticket Number is something different.

if(OrdersTotal()>0){

        for(cnt=OrdersTotal()-1;cnt>=0;cnt--){

        

        if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;

        if(OrderSymbol() == Symbol() && OrderMagicNumber() ==  MagicNumber){



                sl     = OrderStopLoss(); // Stop Loss. 

                tStopLoss = NormalizeDouble(OrderStopLoss(), Digits); // Stop Loss. 

                Order Ticket=OrderTicket(); 

                

                if(OrderType()==OP_SLL){ 

                if( Order Ticket== Sell_Order_Ticket_1){ Do the Normal Trailing Stop}

                if( Order Ticket== Sell_Order_Ticket_2){ Do the Normal Trailing Stop}

                if( Order Ticket== Sell_Order_Ticket_3){ Don't move the Stop Loss} 

Can I compare the Ticket Number like this?

Regards

 
Arav007:

Yes, I've understood. It's not possible to compare as cnt will have value like 3,2,1 while Ticket Number is something different.

Can I compare the Ticket Number like this?

Regards

no
if your pc has to restart then value Sell_Order_Ticket_1 (2 and 3 also) is lost

check orderopenprice and ordertakeprofit

 
deVries:

no
if your pc has to restart then value Sell_Order_Ticket_1 (2 and 3 also) is lost

check orderopenprice and ordertakeprofit


I haven't understood why the value of Sell_Order_Ticket_1 will be lost after restarting the Terminal?

It's a variable and it is not getting over written unless a New Sell order is opening.

This is what I understand but there is logic behind your comment. So please explain a bit.

And I've looked the OrderOpenPrice and OrderTakeProfit functions. What to do with them?

 
Arav007:


I haven't understood why the value of Sell_Order_Ticket_1 will be lost after restarting the Terminal?

It's a variable and it is not getting over written unless a New Sell order is opening.

This is what I understand but there is logic behind your comment. So please explain a bit.

And I've looked the OrderOpenPrice and OrderTakeProfit functions. What to do with them?


All variables are lost on restarting the terminal.

Only Global Variables of the client terminal can be retrieved.

 
Arav007:


I haven't understood why the value of Sell_Order_Ticket_1 will be lost after restarting the Terminal?

It's a variable and it is not getting over written unless a New Sell order is opening.

This is what I understand but there is logic behind your comment. So please explain a bit.

And I've looked the OrderOpenPrice and OrderTakeProfit functions. What to do with them?


do some more testing creating your files

open the 3 trades

note the numbers you get

then close your metatrader4 and restart it again check the value of Sell_Order_Ticket_1, Sell_Order_Ticket_2 and Sell_Order_Ticket_3

are they the same ?? if not what value do you get ??

 

OK got it. This piece of info about 'Variable' will be Helpful for Future too.

if(OrdersTotal()>0){

        for(cnt=3;cnt>0;cnt--){

        if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;

        if(OrderSymbol() == Symbol() && OrderMagicNumber() ==  MagicNumber){



                sl     = OrderStopLoss(); // Stop Loss. 

                tStopLoss = NormalizeDouble(OrderStopLoss(), Digits); // Stop Loss. 

if(OrderType()==OP_BUY){ 

if (cnt==3) { Do the Normal Trailing Stop}

if (cnt==2) { Do the Normal Trailing Stop}

if (cnt==1) { Don't move the Stop Loss}

}

}

} 

How about this?

 
Arav007:

OK got it. This piece of info about 'Variable' will be Helpful for Future too.

How about this?


can we first look to your code of opening trades again ??

check the stoploss and takeprofit of those trades there is still something wrong do you see ??

 
deVries:


can we first look to your code of opening trades again ??

check the stoploss and takeprofit of those trades there is still something wrong do you see ??


ohh, it's for wrong code. After Fixing the flaws, the Take Profit part is Fine Now but Stop Loss is the problem.

Logic:

if (Fast_EMA>Slow_SMA)

{

if (MA_Difference_1>=Value_Diff && iOpenOrders_Buy ==0)

{

Buy

}

}

 
Arav007:


ohh, it's for wrong code. After Fixing the flaws, the Take Profit part is Fine Now but Stop Loss is the problem.

what stoploss did you wanted ?? for those trades ??
 
deVries:
what stoploss did you wanted ?? for those trades ??


Like here for USDJPY trades:

1st Trade (here the Last one due to the reverse arrangement of Time) has TP= 103.636

2nd Trade's TP= 103.736

3rd Trade's TP= 108.536 [ I set this TP at such distance thus it'll work like there is no TP]

Now, as per my requirement, when the price would be say 7 pip [103.603] in profit, the Stop Loss of

1st and 2nd trade will become say 1 pip profit [103.543] and 3rd trade's Stop Loss will remain at 103.386.

Like here in the below image:

1st GBPUSD order got closed at 10 pips Profit.

2nd Order is still running and it's SL got moved.

For 3rd Trade the SL got Moved too which I don't Want.

Reason: