Trailing Stops and Trailing Profit

 

I need to use Trailing Stops and Trailing Profit.

My plan:

For Trailing Stop:

*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.

For Trailing Profit:

*If that trade moves 5 pips more(i.e. 10+5=15 pips) then 'One Third' of that trade will be closed and remaining 'Two Third' will keep running.

*And then say after 10 pips more, (i.e. 15+10=25 pips) 'Half' of the remaining trade will be closed and the remaining 'Half' will keep running without any Take Profit limit.

But I am not Sure if it can be done for a 'Single' trade. That is why I was thinking a bit differently.

--->Three different trade will be opened of 'Same' of Lot at the 'Same' time.

--->Two of them will be closed if the price comes back to trailed stop loss level and remaining One will keep running for Trailing Stop part.

--->First trade will be closed at 'TP-1', Second trade will be closed at 'TP-2' and the last one will keep running for Trailing Profit part.

But how to Distinguish these trades? 'Order Ticket' can be used but there is no assurance that all these three trades will have consecutive Ticket serials as there will be other pair's trades too.

It is actually like for One trade the initial Stop Loss wont move.
 

Are you a Programmer?

Are you learning how to Program?

Are you interested in learning how to Program your ideas?

If your answer is No to the above then Please try Searching the Code-Base for what you're looking for.

Arav007:

I need to use Trailing Stops and Trailing Profit.

My plan:

For Trailing Stop:

*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.

For Trailing Profit:

*If that trade moves 5 pips more(i.e. 10+5=15 pips) then 'One Third' of that trade will be closed and remaining 'Two Third' will keep running.

*And then say after 10 pips more, (i.e. 15+10=25 pips) 'Half' of the remaining trade will be closed and the remaining 'Half' will keep running without any Take Profit limit.

But I am not Sure if it can be done for a 'Single' trade. That is why I was thinking a bit differently.

--->Three different trade will be opened of 'Same' of Lot at the 'Same' time.

--->Two of them will be closed if the price comes back to trailed stop loss level and remaining One will keep running for Trailing Stop part.

--->First trade will be closed at 'TP-1', Second trade will be closed at 'TP-2' and the last one will keep running for Trailing Profit part.

But how to Distinguish these trades? 'Order Ticket' can be used but there is no assurance that all these three trades will have consecutive Ticket serials as there will be other pair's trades too.

It is actually like for One trade the initial Stop Loss wont move.

 
ubzen:

Are you a Programmer?

Are you learning how to Program?

Are you interested in learning how to Program your ideas?

If your answer is No to the above then Please try Searching the Code-Base for what you're looking for.



I searched and then Posted this.

There are posts about 'Trailing Stops' but couldn't find 'Exactly' what I need. May be I have missed it there. So if you know the link please give me.

 
Arav007: I searched and then Posted this. There are posts about 'Trailing Stops' but couldn't find 'Exactly' what I need. May be I have missed it there. So if you know the link please give me.
Sorry I cannot find one for you either. Please be patient, perhaps someone will come along and code it for you.
 
ubzen:
Sorry I cannot find one for you either. Please be patient, perhaps someone will come along and code it for you.


Actually I don't need the whole code. I just need to know which 'Logic' can be implemented here with which 'Function(s)'?

I have some Logic in my mind but need a way to 'Distinguish' the trades by 1,2,3.

 
Arav007:


Actually I don't need the whole code. I just need to know which 'Logic' can be implemented here with which 'Function(s)'?

I have some Logic in my mind but need a way to 'Distinguish' the trades by 1,2,3.


then try to make it and show here your attempts when you don't succeed whatever you try....

implemented easiest way open 3 trades 'at new signal' then do your plan

 

I have thought something like this:

There will be Three trades.

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

{

if (cnt==1)

{ 

 Disable Trailing Stop and Trailing Step

}

else

{

Enable Trailing Stop and Trailing Step

}

} 

//Trailing Profit:

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

{

if (cnt==3)

{ 

Set take profit=TP1

}

if (cnt==2)

{

Set take profit= TP2

} 

else

{

Disable Take Profit

}

}  

This is just schematic. There will be Flesh on this Skeletal if the 'Logic' works.

 
Arav007:

I have thought something like this:

There will be Three trades.

This is just schematic. There will be Flesh on this Skeletal if the 'Logic' works.


no you get signal to open sell or buy

now you have to make a logic you open 3 trades

with same stoploss

1 with takeprofit at your first level

1 with takeprofit at your second level

1 without a takeprofitlevel

 
deVries:


no you get signal to open sell or buy

now you have to make a logic you open 3 trades

with same stoploss

1 with takeprofit at your first level

1 with takeprofit at your second level

1 without a takeprofitlevel


So it's to be something like this?

double dTakeProfitPrice_1=10;

double dTakeProfitPrice_2=20;

double dTakeProfitPrice_3=0;

if (Buy Condition Met)

{

if(iOpenOrders_Buy < iMaxOrders)

{

if(iOpenOrders_Buy ==0) // there is no 'Open' Buy orders

{

BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);

BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);

BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);

}

And what about Stop Loss?

 
Arav007:


So it's to be something like this?

And what about Stop Loss?


stoploss you modify for two trades when the price has moved > 10 pips over orderopenprice

double dTakeProfitPrice_1=10;

double dTakeProfitPrice_2=20;

double dTakeProfitPrice_3=0;
double BuyOrder_1,.......,.......;
if (Buy Condition Met && iOpenOrders_Buy == 0)
{

iOpenOrders_Buy = 3;

{

if(iOpenOrders_Buy  > 0) // we have to open new Buy orders

{

if(iOpenOrders_Buy == 3)
         {
         BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);
         if(BuyOrder_1 > 0).......
         

         }
if(iOpenOrders_Buy == 2)
         {
         BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);
....



if(iOpenOrders_Buy == 1)
         {
         BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);
....
}
 
deVries:


stoploss you modify for two trades when the price has moved > 10 pips over orderopenprice


Sorry actually I have become confused a bit.

if(iOpenOrders_Buy = 3)

Here if the Total Opened Buy order is equal to '3' then the code will proceed to next part.

if(iOpenOrders_Buy > 0)

Then if the Total Opened Buy order's count is greater than '0' then it'll proceed to next.

if(iOpenOrders_Buy == 3)

Then if the Open Buy order count is equal to 3 then it'll open BuyOrder_1, if equal to '2' then it'll open BuyOrder_2 and then BuyOrder_3 is Opened Buy order count is equal to 1.

Am I right?

Reason: