# what wrong of my code???

14

my ea  can run the sl and tp as well as i wanna , but only one thing is that when the OrderClosePrice is bigger or lesser than 400 pips but my T/P do not move to -200pips(because i want it be my stop lose)

my original idea is that for example i order a buy eur/usd at 1.12093 , tp was 1.12193 (100pips).  then the tp will move at 1.11893(-200pips)  afther the market price is 1.11693(-400pips)

pls help me to fix it out
-------------------------------------------------------------------------------------------------------------------------------------
```nput double StopLoss = 900;
input double TickProfit = 100;

#define MAGIC_NUM 0x12345

void OnTick()
{
//double curr_rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
//double previous_rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 1);
double curr_main = iStochastic(NULL, 0, 5, 3, 3 , MODE_SMA, 0, MODE_MAIN, 0);
double curr_signal = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
double previous_main = iStochastic(NULL, 0, 5, 3, 3 , MODE_SMA, 0, MODE_MAIN, 1);
double previous_signal = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 1);
int order_total = OrdersTotal();
if (order_total == 1)
{
if (OrderSelect(0, SELECT_BY_POS))
{
double new_tickprofit;
if (MathAbs(OrderClosePrice() - Close[0]) >= 400 * Point)
{
new_tickprofit = NormalizeDouble(OrderClosePrice() + 200 * Point, 4);
else if (OrderType() == OP_SELL)
new_tickprofit = NormalizeDouble(OrderClosePrice() - 200 * Point, 4);
bool ret = OrderModify(OrderTicket(), OrderClosePrice(), OrderStopLoss(), new_tickprofit, 0, Blue);
if (ret)
Print("Order modified successfully.");
else
Print("Error in OrderModify. Error code=", GetLastError());
}
}
else
Print("Error in OrderSelect. Error code=", GetLastError());
}
else
{
double lots = AccountBalance() / 10000;
//if (previous_rsi <= 30 && curr_rsi > previous_rsi)
if (curr_main <= 20 && curr_signal <= 20 && previous_main <= 20 && previous_signal <= 20
&& curr_signal < curr_main && previous_main < previous_signal)
{
double stoploss = NormalizeDouble(Bid - StopLoss * Point, 4);
double tickprofit = NormalizeDouble(Bid + TickProfit * Point, 4);
int ticket = OrderSend(Symbol(), OP_BUY, lots, ask, 99, stoploss, tickprofit, "My order", MAGIC_NUM, 0, clrGreen);
if (ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
else
{
Print("OrderSend placed successfully");
}
}
//else if (previous_rsi >= 70 && curr_rsi < previous_rsi)
else if (curr_main >= 80 && curr_signal >= 80 && previous_main >= 80 && previous_signal >= 80
&& curr_signal > curr_main && previous_main > previous_signal)
{
// sell
stoploss = NormalizeDouble(Bid + StopLoss * Point, 4);
tickprofit = NormalizeDouble(Bid - TickProfit * Point, 4);
ticket = OrderSend(Symbol(), OP_SELL, lots, ask, 99, stoploss, tickprofit, "My order", MAGIC_NUM, 0, clrGreen);
if (ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
else
{
Print("OrderSend placed successfully");
}
}
}
}```

2203

1. EDIT your post and place your code in a SRC block. Use the "SRC" icon in the toolbar.
2. Explain what is wrong! Don't just say what you want. Explain what is happening, what errors you are getting, etc.
Moderator
10411

`        if (OrderClosePrice() - Close[0] >= 400)`

If the open price was at 1.12093, it would have to reach 401.12093, not likely to happen

14

FMIC:
1. EDIT your post and place your code in a SRC block. Use the "SRC" icon in the toolbar.
2. Explain what is wrong! Don't just say what you want. Explain what is happening, what errors you are getting, etc.
thank brother! for you remind
14

GumRai:

If the open price was at 1.12093, it would have to reach 401.12093, not likely to happen

because i think the 400pips is the distance between order price and current preice .

is it my concept wrong???

15350

You didn't specify 400 pips your specified 400.

There is Tick, PIP, and Point. They are all different in general. A tick is the smallest change of price. A Point is the least significant digit quoted. In currencies a pip is defined as 0.0001 (or for JPY 0.01)

On a 4 digit broker a point (0.0001) = pip (0.0001). [JPY 0.01 == 0.01] On a 5 digit broker a point (0.00001) = 1/10 pip (0.00010/10). Just because you quote an extra digit doesn't change the value of a pip. (0.0001 == 0.00010) EA's must adjust pips to points (for mq4.) In currencies a tick is a point. Price can change by least significant digit (1.23456 -> 1.23457)

In metals a Tick is still the smallest change but is larger than a point. If price can change from 123.25 to 123.50, you have a TickSize of 0.25 and a point of 0.01. Pip has no meaning.

This is why you don't use TickValue by itself. Only as a ratio with TickSize. See DeltaValuePerLot()

14

WHRoeder:
You didn't specify 400 pips your specified 400.
```   if (OrderSelect(0, SELECT_BY_POS))
{
double new_tickprofit;
if (MathAbs(OrderClosePrice() - Close[0]) >= 400 * Point)
{
`if (MathAbs(OrderClosePrice() - Close[0]) >= 400 * Point)`