"Switch" function

 
what is wrong with this code?


if(OrdersTotal() > 0 && OrderSelect(0, SELECT_BY_POS)==true && A==1)
{
switch(OrderProfit())
{
case -0.2:
if(OrderStopLoss() < resetlong + 0.0003)
{
OrderModify(OrderTicket(),OrderOpenPrice(),resetlong+ 0.0003,OrderTakeProfit(),Blue) ;
Alert(GetLastError()); break;
}
case 0.0 :
if(OrderStopLoss() < resetlong + 0.0009)
{
OrderModify(OrderTicket(),OrderOpenPrice(),resetlong+ 0.0009,OrderTakeProfit(),Blue) ;
Alert(GetLastError()); break;
}
case 0.3 :
if(OrderStopLoss() < resetlong + 0.0014)
{
OrderModify(OrderTicket(),OrderOpenPrice(),resetlong+ 0.0014,OrderTakeProfit(),Blue) ;
Alert(GetLastError()); break;
}
case 0.4 :
if(OrderStopLoss() < resetlong + 0.0015)
{
OrderModify(OrderTicket(),OrderOpenPrice(),resetlong+ 0.0015,OrderTakeProfit(),Blue) ;
Alert(GetLastError()); break;
}
case 1.0 :
if(OrderStopLoss() < resetlong + 0.0020)
{
OrderModify(OrderTicket(),OrderOpenPrice(),resetlong+ 0.0020,OrderTakeProfit(),Blue) ;


what it is supposed to do, is at each profit level(which is each case) the stoploss is supposed to move up, but for some reason the stoploss is being moved up before the specified case it is supposed to move up at.

i just tried it out and i only got upto case 0.3 but the stoplose was moved up asif it hit case 1.0
 
OrderProfit() returns a value of (for example) $112.65
 
what is happening is when price fluctuates and hits the same case price point several times, each time the price is it, it moves the stoploss up another level, as if it is going thru all the levels like -0.2 then 0.0 then 0.3 then 0.4 etc. but really it is just hitting -0.2 over and over.
 

For a long:

if(Bid - desiredStopLoss > OrderStopLoss()){

... calculate new stoploss value and modify order.

.

I see you are trying to do levels, not a smoothly moving stop. Hmm.

 
yeah the way i was using the case is i was buying 0.01lots so for example at 3 pips up i would be at case 0.3
 
The case breaks should probably not be conditionally executed inside the if.
 

YAY PHY


i think you fixed it, i just tried it with a short trade and it seems to work so it will probably work with a long trade, but before i have having trouble getting it to work with both long and short trades so we will see


thank you very much, i would never have realized that was the problem if you hadnt told me, i am indebted to you.


you have helped me very much in the 3 or 4 threads i have made with questions about making my first ever EA!!!


thanks alot

-Alex