Trailing Stops and Trailing Profit - page 3

 
deVries:


Thanks for the corrections.

If we are using count=count-1; then there is no need to use 'for' loop which I was trying to get cleared two post back

And sometime it's worthy of trying. Like just now I have fixed some mistakes by my own and it gave me such a pleasure!

Thanks once again. Take Profit part is working so far as expected.

 
Arav007:


Thanks for the corrections.

If we are using count=count-1; then there is no need to use 'for' loop which I was trying to get cleared two post back

And sometime it's worthy of trying. Like just now I have fixed some mistakes by my own and it gave me such a pleasure!

Thanks once again. Take Profit part is working so far as expected.


keep testing and reading codes you see and you learn a lot,

you can do yourself a lot learning

if you try to understand and explore the things

with testing and creating it on your own 'demo' testing account

 
deVries:


keep testing and reading codes you see and you learn a lot,

you can do yourself a lot learning

if you try to understand and explore the things

with testing and creating it on your own 'demo' testing account


Yes I'm trying to understand what I'm getting across.

Now for the 'Stop Loss Trailing' part I have thought something.

The condition for starting the 'Trailing Stop' loop:

if(OrdersTotal()>0){

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

{

Trailing Stops;

}

}

Now what I was thinking that this loop will run as many times as the number of total opened orders. And my aim is 'Not to Trail' Stops for the Last/Third order.

So if I stop the loop at 'Second' order, how it'd be?

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

 
Arav007:


Yes I'm trying to understand what I'm getting across.

Now for the 'Stop Loss Trailing' part I have thought something.

The condition for starting the 'Trailing Stop' loop:

if(OrdersTotal()>0){

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

{

Trailing Stops;

}

}

Now what I was thinking that this loop will run as many times as the number of total opened orders. And my aim is 'Not to Trail' Stops for the Last/Third order.

So if I stop the loop at 'Second' order, how it'd be?

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


find the right symbol and right magicnumber

then it is a trade of your EA now check if Bid/Ask is xx pips away from orderopenprice()

do some searching here and you find examples you can use

 
deVries:


find the right symbol and right magicnumber

then it is a trade of your EA now check if Bid/Ask is xx pips away from orderopenprice()

do some searching here and you find examples you can use


I have the checking and the conditional part.

 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. 

                

                if(OrderType()==OP_BUY){

                

                        if(Ask> NormalizeDouble(OrderOpenPrice()+TrailingStart* vPoint,Digits)

                        && tStopLoss < NormalizeDouble(Bid-(TrailingStop+TrailingStep)*vPoint,Digits)){

 tStopLoss = NormalizeDouble(Bid-TrailingStop*vPoint,Digits); 

}

}

But here I'm not understanding how to distinguish between trades. The 'Trailing Stop' function is called at the starting of the program.

 

*After reaching a certain profit limit say 10 pips, the Stop Loss will move to 5 pips. Now if that trade retraces back to 5 pips then 'Two Third' of the trade will be Closed.

*Remaining 'One Third' will keep Running and 'Trailing Stop' wont be applied for it then.

You have three trades so how do you wanna handle the three trades

so it is doing like you wanted ??

or which one has to be modified, after certain profit...

 
deVries:

*After reaching a certain profit limit say 10 pips, the Stop Loss will move to 5 pips. Now if that trade retraces back to 5 pips then 'Two Third' of the trade will be Closed.

*Remaining 'One Third' will keep Running and 'Trailing Stop' wont be applied for it then.

You have three trades so how do you wanna handle the three trades

so it is doing like you wanted ??

or which one has to be modified, after certain profit...


To simplify matter I decided to go with 'Three' separate trade of same lot thus if two of them get closed, 'Two Third' of total trades (Lots) will be closed.

And the remaining trade (One Third) will keep running i.e. that 'Trailing Stop' wont be applied for it.

Stop Loss will be moved to a certain pips in profit for First Two trades but for the Third one, it wont move.

 
Arav007:


To simplify matter I decided to go with 'Three' separate trade of same lot thus if two of them get closed, 'Two Third' of total trades (Lots) will be closed.

And the remaining trade (One Third) will keep running i.e. that 'Trailing Stop' wont be applied for it.

Stop Loss will be moved to a certain pips in profit for First Two trades but for the Third one, it wont move.


You have to use some functions to get the modify done right

at this moment you have to check somehow a way to select a trade you have to modify

check the functions here Trade Functions and see if you can select trade 1

 
deVries:


You have to use some functions to get the modify done right

at this moment you have to check somehow a way to select a trade you have to modify

check the functions here Trade Functions and see if you can select trade 1


Can index number be compared with ticket number?

   if (count==3) 

    {

  SellOrder_1=OrderSend(Symbol() , iOrderType_Sell , LotSize,OpenPrice,Slippage ,dStopLossPrice ,dTakeProfitPrice_1 , "Sell Order",MagicNumber , 0,Red);

                

    if (SellOrder_1>0) //Checking if the order was opened or not

      { 

      sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Sell order 1 sent successfully. Ticket=" + SellOrder_1;

      Sell_Order_Ticket_1=SellOrder_1;

      count = count - 1; 

      }

     else {

          iLastError = GetLastError();                               

          sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending sell order 1. Error code=" + ErrorDescription(iLastError);



} 

} 

//Trailing Stop Function 

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. 

                

                if(OrderType()==OP_BUY){

if (cnt==Sell_Order_Ticket_1){

Proceed to Next 

} 

Please refer to the Color Blocked parts above.

Thanks

 
Arav007:


Can index number be compared with ticket number?

Please refer to the Color Blocked parts above.

Thanks


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

your orderstotal is 3 trades

do this

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

for(cnt= 3 -1;cnt>=0;cnt--)
   {
   Print ("cnt =  ",cnt);
   }

what do you read if you open Terminal and look at Experts ??

will Sell_Order_Ticket_1 have a value same as cnt ??

if yes can you proof me, it is...

if not why not ??

Reason: