|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Please help, splitting a trade
hi
Does anyone have code or an ea that splits the trade at certain profit levels, e.i. Enter trade - when 30 pips in profit sell half of trade, when at 50 pips profit sell 30% of original, at 70 sell the last 20%. I am getting myself into a serious knot trying to code this. Any help is greatly appreciated. Thanks Last edited by cardio : 04-24-2006 at 04:02 PM. |
|
|||
|
Quote:
i am also in process creating my ea and woking for same kind of functionality. take this as an example. double exit1 = 30; double exit2 = 60; double exit3 = 90; // above three lines are there for profit levels.. // if(OrderType() == OP_SELL) and if(OrderType() == OP_BUY) you must have this code for buy and sell where you close your open positions right? below these lines you need to add the condition to close the above 3 exits lets use for sell and only 1 /// static int lots = { number of lots } // this is just to control the lots.. if{ normal stuff} else if ( Ask < OrderOpenPrice() - exit1 ) * Point && lots >= {number} ) { CloseOrder{}... lots--; } -- more else if'sssss //// this is one way to do it ![]() hope this helps..! -sonic. |
|
|||
|
Quote:
![]() -sonic. |
|
|||
|
Thanks Sonic
Thanks Sonic
You reminded me of something I tried to do a while back - I will modify this code, I have not tested this - but will do so this week. Code:
/////////////////////////////////////////////
void twostepts(string Symbol1, int magicNum, int ts1)
{
/*
So my exit is like this:
1) start trade
2) when profit is 30p move sl to be
3) form there use ts 30p
4) when profit will reach 60p move sl to 55p
5) if price still goes up and is above 60p then use ts 15p
and exit on stop.
*/
int total, cnt, ticket1;
int period2;
double n1, newsl;
total = OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol1 && OrderMagicNumber()== magicNum)
{
//close any other outstanding pending OrderSelect
if (totalstop>0)
{
Print("closing all pending, totalstops = ", totalstop);
CloseAllPendingBUYSELL(Symbol1,magicNum);
}
if(OrderType()==OP_BUY) // long position is opened
{
// check for trailing stop
if(ts1>0)
{
if(Bid-OrderOpenPrice()>Point*62)
{
if(OrderStopLoss()<Bid-Point*15)
{
// Print("stage3 nts, Profit : ",Bid-OrderOpenPrice(),", Current sl : ",OrderStopLoss(),", new sl : ", Bid-Point*15);
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*15,OrderTakeProfit(),0,Green);
return(0);
}
return(0);
}
if(Bid-OrderOpenPrice()>Point*60)
{
if(OrderStopLoss()<OrderOpenPrice()+55*Point)
{
// Print("stage2 nts, Profit : ",Bid-OrderOpenPrice(),", Current sl : ",OrderStopLoss(),", new sl : ", OrderOpenPrice()+55*Point);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+55*Point,OrderTakeProfit(),0,Green);
return(0);
}
return(0);
}
if(Bid-OrderOpenPrice()>Point*30)
{
if(OrderStopLoss()<Bid-Point*30)
{
// Print("stage1 nts, Profit : ",Bid-OrderOpenPrice(),", Current sl : ",OrderStopLoss(),", new sl : ", OrderOpenPrice()+2*Point);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+2*Point,OrderTakeProfit(),0,Green);
return(0);
}
return(0);
}
}
}
else // go to short position
{
// check for trailing stop
if(ts1>0)
{
if((OrderOpenPrice()-Ask)>(Point*62))
{
if((OrderStopLoss()>(Ask+Point*15)) || (OrderStopLoss()==0))
{
//Print("stage1 nts, Profit : ",Bid-OrderOpenPrice(),", Current sl : ",Ask+Point*15,", new sl : ", OrderOpenPrice()+2*Point);
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*15,OrderTakeProfit(),0,Red);
return(0);
}
return(0);
}
if((OrderOpenPrice()-Ask)>(Point*60))
{
if((OrderStopLoss()>(OrderOpenPrice()-55*Point)) || (OrderStopLoss()==0))
{
//Print("stage1 nts, Profit : ",Bid-OrderOpenPrice(),", Current sl : ",OrderOpenPrice()-55*Point,", new sl : ", OrderOpenPrice()+2*Point);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-55*Point,OrderTakeProfit(),0,Red);
return(0);
}
return(0);
}
if((OrderOpenPrice()-Ask)>(Point*30))
{
if((OrderStopLoss()>(OrderOpenPrice()-2*Point)) || (OrderStopLoss()==0))
{
//Print("stage1 nts, Profit : ",Bid-OrderOpenPrice(),", Current sl : ",OrderOpenPrice()-2*Point,", new sl : ", OrderOpenPrice()+2*Point);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-2*Point,OrderTakeProfit(),0,Red);
return(0);
}
return(0);
}
}
}
}
//end trailing stop
}
}
///////////////////////////////////
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To trade or not to trade Indicators? | yaniv_av | Indicators - Metatrader 4 | 1 | 03-27-2007 01:01 PM |