auto trail EA

 

can some one help me to see why this ea's trail stop not working properly

Files:
trailme1.mq4  18 kb
 
bewise wrote >>

can some one help me to see why this ea's trail stop not working properly

well i didn't really read it bc it is so long.

this one works for me:

total = OrdersTotal();
int k ;
static int TrailingStop;
if (total == 0) TrailingStop = 0;


// ADD TRAILING STOP

if (trail == true)
{
for ( k = 0; k < total; k++) // OR for (int k = total-1 ; k > -1; k-- )
{
OrderSelect(k, SELECT_BY_POS, MODE_TRADES);
double pips = OrderProfit() / OrderLots();

if (pips > 25) TrailingStop = 20;
if (pips > 15) TrailingStop = 10;
if (pips > 10) TrailingStop = 8;

// Type 0 Buy Order

if (OrderType() == 0 ) // OP_BUY
if( Ask - OrderOpenPrice() > TrailingStop * Point )
if( Ask - TrailingStop * Point > OrderStopLoss() )
{

Print ("..............................TRAILING STOP PIPS is ", pips );
Print ("..............................TRAILING STOP is ", TrailingStop );

OrderModify(OrderTicket(),OrderOpenPrice(),Ask-TrailingStop * Point, 0,0,0);
}

// Type 1 Sell Order


if (OrderType() == 1 ) // OP_SELL
if( OrderOpenPrice() - Bid > TrailingStop * Point )
if( OrderStopLoss() > Bid + TrailingStop * Point )
{

Print ("..............................TRAILING STOP PIPS is ", pips );
Print ("..............................TRAILING STOP is ", TrailingStop );
OrderModify(OrderTicket(),OrderOpenPrice(),Bid + TrailingStop * Point, 0,0,0);
}
}
}

 

I dont think this would work correctly

OrderSelect(k, SELECT_BY_POS, MODE_TRADES);
double pips = OrderProfit() / OrderLots();

i dont believe you can get a correct pip value from that.

for instance EUR/USD if your lot size was 1 lot on a standard account it would make $10 per pip

therefore a profit of $100 would be from 10 pips

apply that formula to the same: pips=OrderProfit()/OrderLots() is $100.00/1 lots = 100 pips instead of 10 pips.

as lot sizes are different on different types of accounts is it even possible for a universal formula to calculate pip values from OrderProfit ()

if it is possible does anyone know of a formula to correctly convert OrderProfit() to a pip value on orders that are still open ?

I have been trying to figure it out but so far I cant see how it can be done

 

I have been testing by printing out the result of the various MarketInfo modes and order functions and it seems that MarketInfo("currency pair",MODE_TICKVALUE); gives the value in base currency for 1 pip based on a 1 lot trade of the currency pair in question.

So (OrderProfit divided by TICKVALUE) divided by OrderLots should be the formula to convert the current value of OrderProfit to the amount of pips made, can anyone see any reason this would not work ?

Reason: