I really neeed help in this urgent Case !!!!!!

 

Dear's,

Kindly i need your help me on the below as it's open oppsite trade for one trade exsit,but while i test it it some time calculate take profie (Open Order Price-20 point) and this right and sometimes (Open Order Price-2000 point) calculate and this wrong


Please Heeeeelp

extern int MAGICMA = 222222222222;
extern int Opp = 0;

void start()
  {
int Ticket03;
int TradeMin = 1;

if(Digits==3 || Digits==5) Dig=10;
if(Digits==2 || Digits==4) Dig=1;

if(OrderSelect(SELECT_BY_POS,MODE_TRADES)==true)
   {
    if(
       MathFloor(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE)) <= -20)
    {
     int Trade = MathFloor( OrderProfit()/ (OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)));
     
     if(TradeMin > Trade)
     { 
      TradeMin = Trade;
      
      if(Opp-2 >= TradeMin && OrdersTotal()== 1)
      {
       Opp = TradeMin;
       
       if(OrderType() == OP_BUY && IsTradeAllowed() == true)
       {
        Ticket03 = OrderSend(OrderSymbol(),OP_SELL,OrderLots(),Bid,0,0.0,0.0,"EA",481162,0,Red);
        
        if(Ticket03 > 0)
        {
         if(OrderSelect(Ticket03,SELECT_BY_TICKET)==true)
         {
          TP = OrderOpenPrice()-(TakeProfit*Dig)*Point;
          SL = OrderOpenPrice()+(StopLoss*Dig)*Point;
        
          OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0,Red);
          Print("OrderSend Success for Symbol : ",OrderSymbol()," Opposite");
          Print("Loss Points : ",Opp);
          return(0);
         }
        }
        else
        {
         Print("OrderSend failed with error : #",GetLastError());
         return(0);
        }
       }
       if(OrderType() == OP_SELL && IsTradeAllowed() == true)
       {
        Ticket03 = OrderSend(OrderSymbol(),OP_BUY,OrderLots(),Ask,0,0.0,0.0,"EA",481162,0,Green);
        
        if(Ticket03 > 0)
        {
         if(OrderSelect(Ticket03,SELECT_BY_TICKET)==true)
         {
          TP = OrderOpenPrice()+(TakeProfit*Dig)*Point;
          SL = OrderOpenPrice()-(StopLoss*Dig)*Point;
        
          OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0,Green);
          Print("OrderSend Success for Symbol : ",OrderSymbol()," Opposite");
          Print("Loss Points : ",Opp);
          return(0);
         }
        }
        else
        {
         Print("OrderSend failed with error : #",GetLastError());
         return(0);
        }
       }
      }
      return(0);
     }
     return(0);
    }
    else
    {
     Opp = 0;
     //Print("Loss : ",Opp);
     return(0);
    }
   }
 

This is wrong, you are missing a parameter . . .

if(OrderSelect(SELECT_BY_POS,MODE_TRADES)==true)  // <----  which order are you selecting ?

OrderSelect

you are missing the index parameter.

 

Thanks RaptorUK for your response


The First Order, I mean the Original order which i open Opposite order for it


RaptorUK:

This is wrong, you are missing a parameter . . .

OrderSelect

you are missing the index parameter.

 

TP, SL, TakeProfit, StopLoss and Dig are not defined... so you must have more code than you posted.

You will need to add Print ("TakeProfit: ",TakeProfit); just before and just after you modify it.

sn

 
serpentsnoir:

TP, SL, TakeProfit, StopLoss and Dig are not defined... so you must have more code than you posted.

You will need to add Print ("TakeProfit: ",TakeProfit); just before and just after you modify it.

sn


Thanks serpentsnoir for your response


I already define it but this is a part which include the error only and i try to print Takeprofite and Stoploss and get what i post it it my topic (Sometimes 20 and Sometimes 2000)

 
Without knowing how your variables TakeProfit and StopLoss are given values it is impossible to give an answer.
 

Just add in the first the below two lines


extern double TakeProfit = 20;
extern double StopLoss = 0;

 

So your TP is . . .

TP = OrderOpenPrice()-(TakeProfit*Dig)*Point;

or     

TP = OrderOpenPrice()+(TakeProfit*Dig)*Point;

both based on TakeProfit which you claim is set at 20.

From the code you have shown TP will be either OrderOpenPrice() +/- 20 * Point or OrderOpenPrice() +/- 200 * Point . . . NOT OrderOpenPrice() +- 2000 * Point

If your testing shows that TakeProfit*Dig = 2000 (please show a copy/paste from the Journal to show this) then you have not shown the code that makes this happen.