some error 130 about code

 

about below codes, it is very different when the red code "if(Pro<10000*Point)" is activated or not when I test it on the history data;

In the fact the history data is very simple, about consecutive 5 days, and Pro never exceeds 10000*Point.

when the red code is activated, the order stop line seems never move whatever.

it is very confusing.

void Move_Stop_Loss()         
{                                 
  if(OrdersTotal()==0) return;    
 
  int Move_Stop;
  for(int i=OrdersTotal();i>0;i--)
  {
    OrderSelect(i-1,SELECT_BY_POS);
    double Pro=OrderProfit();
    if(OrderType()==OP_BUY)
    {
      if(Pro<200*Point) Move_Stop=100;
      else /*if(Pro<10000*Point) */Move_Stop=200;

      if(Close[0]-OrderStopLoss()>Move_Stop*Point)
      {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-Move_Stop*Point,0,0,0);}
    }  

  }


  return;
}

 
vx0532:

about below codes, it is very different when the red code "if(Pro<10000*Point)" is activated or not when I test it on the history data;

In the fact the history data is very simple, about consecutive 5 days, and Pro never exceeds 10000*Point.

when the red code is activated, the order stop line seems never move whatever.

it is very confusing.

What does point have to do with profit in your account currency ? do you understand what OrderProfit() is ?
 
RaptorUK:
What does point have to do with profit in your account currency ? do you understand what OrderProfit() is ?


haha,sorry,

OrderProfit() returns the current unrealized profit of the selected order.

I want to change stop loss line when the profit is more than some value, shall I?

 
vx0532: I want to change stop loss line when the profit is more than some value, shall I?
      if(Pro<200*Point) Move_Stop=100;
      else /*if(Pro<10000*Point) */Move_Stop=200;

  1. on EURUSD Point is 0.0001 (4 digit broker) or 0.00001 (5) so 10000*Point is 10 or 1. So your first test is when profit < $0.2 or <$0.02 and the second test is profit < $1.00 or profit < $10.00
  2. If you don't execute the first (because profit is more than 0.2) AND you don't execute the second (because profit is more than $1) Then what is the value of Move_Stop?
  3. You want to "change when profit is more" so why are you testing for less?
  4. "shall you?" We don't know - have you learn to code?
  5. If your orderSelect fails, so does your code - What are Function return values ? How do I use them ? - MQL4 forum If the OrderModify fails don't you want to know why. If it's not working don't you want to know whether its the OrderModify or the fact it's not being called?
  6. If you change brokers (from 4 to 5 digits or back or put is on a JPY or metals chart) are you going to remember to change every number? In the right direction? Don't use Point, auto-adjust using pips2dbl
 
WHRoeder:
  1. on EURUSD Point is 0.0001 (4 digit broker) or 0.00001 (5) so 10000*Point is 10 or 1. So your first test is when profit < $0.2 or <$0.02 and the second test is profit < $1.00 or profit < $10.00
  1. my first test is profit <$0.2 or $0.02 and my second test is profit >$0.2&& <$10.0 or profit>$0.02 && <$1.0; in the other case (without if(Pro<10000*Point) ), just delete profit<$1.0 or <$10.0;

  • If you don't execute the first (because profit is more than 0.2) AND you don't execute the second (because profit is more than $1) Then what is the value of Move_Stop?
  1. yes, Move_Stop=0, that is why error 130.

  • You want to "change when profit is more" so why are you testing for less?
  1. testing less, because when less, Move_Stop will get "less" 's value just as "more".
  1. of course I have, that is why you see my post here.

  1. thanks for your advice.

  • If you change brokers (from 4 to 5 digits or back or put is on a JPY or metals chart) are you going to remember to change every number? In the right direction? Don't use Point, auto-adjust using pips2dbl
  1. thanks


 

thanks all

I have understand the situation.

 
vx0532:

thanks all

I have understand the situation.

Well done
 
RaptorUK:
Well done


I modify them as below:

if(OrderSelect(i-1,SELECT_BY_POS))
    {
      int Profit_Point=NormalizeDouble(OrderProfit()*Close[0]/100000/Point+50*Point,0); 
      int Move_Stop=100;
      if(Profit_Point>0&&Profit_Point<=500) Move_Stop=400;
      if(Pro*Close[0]/100000>500*Point)Move_Stop=50;
      if(MathAbs(Close[0]-OrderStopLoss())>Move_Stop*Point)
      if(OrderType()==OP_BUY) {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]-Move_Stop*Point,0,0,0);}
      else if(OrderType()==OP_SELL) {iWait();OrderModify(OrderTicket(),OrderOpenPrice(),Close[0]+Move_Stop*Point,0,0,0);}
    } 
 
OrderProfit()*Close[0]/100000/Point
$n.nn profit * exchange rate / (1/Point) / Point = $n.nn profit * exchange rate = what? A meaningless value with meaningless units. What is the sound of the temperature of the sun - Huh?
 
WHRoeder:
$n.nn profit * exchange rate / (1/Point) / Point = $n.nn profit * exchange rate = what? A meaningless value with meaningless units. What is the sound of the temperature of the sun - Huh?
http://www.telegraph.co.uk/science/space/8114694/Stars-song-captured-by-scientists.html
Reason: