Quote:
|
Originally Posted by yossi1177
someone can help me to do code or EA for trailing profit?
i think that it is very good idea
|
This is a simple 3 candles profit trailing (PT) code or more like a trailing stop. It is activated by GapPT=number of pips in profit. Attached is chart example of 3 candles method.
Wackena
Code:
extern int GapPT=10;
int c, n, p;
double LongPT, ShortPT;
c=0; p=0;
for(n=0;n<=6;n++)
{
if(High[c+1]<High[c+2] && Low[c+1]>Low[c+2]) {n--;}
c++;
p++;
if(n==3) break;
}
ShortPT=NormalizeDouble(High[iHighest(Symbol(),0,MODE_HIGH,p,1)],Digits);
LongPT=NormalizeDouble(Low[iLowest(Symbol(),0,MODE_LOW,p,1)],Digits);
int total = OrdersTotal();
for(int cnt=0;cnt<total;cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && OrderClosePrice()-OrderOpenPrice() >= GapPT*Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),LongPT,OrderTakeProfit(),0,GreenYellow);
}
if(OrderType()==OP_SELL && OrderOpenPrice()-OrderClosePrice() >= GapPT*Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),ShortPT,OrderTakeProfit(),0,Red);
}
}