How can I intergrate stoploss code into an already coded MQ4 algorithm?

 

Hey,

I found this stoploss code, first off, what do you think of it? Secondly how would i integrate it into the code I already have which is 990 lines long? 

Thanks guys


Nat

if((OrderMagicNumber()==MagicNumber1))
   if(OrderType()==OP_SELL)
     {
      StopLoss=iHigh(NULL,0,1);
      TakeProfit=OrderTakeProfit();
      StopLoss=MathMax(iHigh(Symbol(),Period(),1),Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);  //<--HERE
      int sellclose=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StopLoss,Digits),TakeProfit,0,Green);
      Comment("\nStop Loss will move to BE at ",High[1]);
     }
//-----------------------------------------------------------------+

// STOP LOSSE 4 BUY ORDERS
if((OrderMagicNumber()==MagicNumber2))
   if(OrderType()==OP_BUY)
     {
      StopLoss=iLow(NULL,0,1);
      TakeProfit=OrderTakeProfit();
      StopLoss=MathMin(iLow(Symbol(),Period(),1),Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);  //<--HERE
      int buyclose=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(StopLoss,Digits),TakeProfit,0,Green);


      Comment("\nStop Loss will move to BE at ",Low[1]);
     }
 
Your question is vague, 

What you just said is. 

I found  bolt, that holds a screw firm. 

I have a car with a steering wheel, where do i put the bolt. 


Provide more data 

How are ur orders opened. 


 
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. ERR_NO_RESULT
    You Server
    Change the SL to X It is at X!
    Change the SL to X It is at X!
    Change the SL to X You are insane
    Insanity: doing the same thing over and over again and expecting different results.
              Unknown
    Compute the new value, then check that you are moving the existing value at least a tick. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum

  3. A TSL only moves in the direction of the trade. Your code can go either direction.

  4.    if(OrderType()==OP_SELL){
          StopLoss=iHigh(NULL,0,1);
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)