OIL SendOrder problem

 

Hallo please help me...

 

I have a problem with SendOrder on OIL. How do I defined SL and TP ? For the definition price I use NormalizeDouble. My EA work in backtest O.K., but on real trade type error price SL a TP. 

 

For example:

double slb=NormalizeDouble(Ask-SL*Point,Digits);

double sls=NormalizeDouble(Bid+SL*Point,Digits);

double tpb=NormalizeDouble(Ask+TP*Point,Digits);

double tps=NormalizeDouble(Bid-TP*Point,Digits);

OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,0,BuyMagicNumber,0,Blue);

 

Many thanks... I am helpless.... 

 
david007:

Hallo please help me...

 

I have a problem with SendOrder on OIL. How do I defined SL and TP ? For the definition price I use NormalizeDouble. My EA work in backtest O.K., but on real trade type error price SL a TP. 

 

For example:

double slb=NormalizeDouble(Ask-SL*Point,Digits);

double sls=NormalizeDouble(Bid+SL*Point,Digits);

double tpb=NormalizeDouble(Ask+TP*Point,Digits);

double tps=NormalizeDouble(Bid-TP*Point,Digits);

OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,0,BuyMagicNumber,0,Blue);

 

Many thanks... I am helpless.... 

 

 

When posting code, please use the SRC button to insert code.

Most ECN's do not allow you to set your Takeprofit or Stoploss when you initially send your order.

So to get around this, you need to first place your order with 0 for Tp and Sl, then go back and modify your order.  Hope this helps. 

EDIT: Thank you Raptor for noticing a few typos in my code when trying to help someone else. fixed now.

int ticket;
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,NULL,BuyMagicNumber,0,Blue);
  if(ticket>=0)//OrderSend was a success
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
             {
               Print("LONG order opened : ",OrderOpenPrice());
               OrderModify(ticket,OrderOpenPrice(),slb,tpb,0,CLR_NONE); //Add in your Takeprofit and Stoploss here
             }
            else Print("Error opening BUY order : ",GetLastError(), " with lot size ",Lots); 
            return(0);
          }
 
asham:

Most ECN's do not allow you to set your Takeprofit or Stoploss when you initially send your order.

So to get around this, you need to first place your order with 0 for Tp and Sl, then go back and modify your order.  Hope this helps.

Your code is broken,  you have an extra  )  brace, and an int parameter between Slippage and the MagicNumber which should be a string. . . also check your return values and report errors, don't you wan't to know if your OrderModify() failed and why it failed and what the variables were that might have made it fail ?

 What are Function return values ? How do I use them ?

 
david007:

Hallo please help me...

 

I have a problem with SendOrder on OIL. How do I defined SL and TP ? For the definition price I use NormalizeDouble. My EA work in backtest O.K., but on real trade type error price SL a TP. 

<CODE DELETED>

Please read some other posts before posting . . .

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button. 

 
asham:

When posting code, please use the SRC button to insert code.

Most ECN's do not allow you to set your Takeprofit or Stoploss when you initially send your order.

So to get around this, you need to first place your order with 0 for Tp and Sl, then go back and modify your order.  Hope this helps. 

EDIT: Thank you Raptor for noticing a few typos in my code when trying to help someone else. fixed now.


Many thanks !!!! Its O.K. !!
Reason: