Using OrderSend to short a pair:

 
OrderSend (
                      _Symbol,                     //Pair to use
                      OP_SELL,                     //buy or sell operator
                      0.15,                        // how much
                      Ask,                         // price to pay 
                      3,                           // slippage ??
                      Bid-350*_Point,              // Stop Loss
                      Bid+350*_Point,              // Take Prof
                      NULL,                        // use if you want to ID the trade
                      0,                           // Magic Number
                      0,                           // Expiration, 0 for no expiration
                      Green
                    );  

I am using this same code to execute longs, using the OP_BUY command.

I have treid to use variations of this but no method will execute a short using the back-test feature. Can anyone see what may be amiss with this code?

 
wcrowder:

I am using this same code to execute longs, using the OP_BUY command.

I have treid to use variations of this but no method will execute a short using the back-test feature. Can anyone see what may be amiss with this code?

You sell at Bid

Stop loss must be above the entry price

Take profit below.

 

Keith,


THank you for that. I will try this once I am able. I think you nailed it though.I appreciate the reply!

 
wcrowder: I am using this same code to execute longs, using the OP_BUY command.
OrderSend (
                      _Symbol,                     //Pair to use
                      OP_SELL,                     //buy or sell operator
                      0.15,                        // how much
                      Ask,                         // price to pay 
                      3,                           // slippage ??
                      Bid-350*_Point,              // Stop Loss
                      Bid+350*_Point,              // Take Prof
In additions to Keith's answer (SL/TP are reversed): 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 is 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.)
 
wcrowder:

I am using this same code to execute longs, using the OP_BUY command.

I have treid to use variations of this but no method will execute a short using the back-test feature. Can anyone see what may be amiss with this code?



//The TakeProfit and StopLoss are in PIPS...
double SL=StopLoss*10*Point; double TP=TakeProfit* 10*Point;
//To BUY, use:
if(Buy_Condition_Met){ int buy=OrderSend(Symbol(), OP_BUY,Lots_to_trade,Ask,Slippage,Bid-SL,Bid+TP, NULL,0,0,clrGreen); }
//To SELL, use:
if(Sell_Condition_Met){ int buy=OrderSend(Symbol(), OP_SELL,Lots_to_trade,Bid,Slippage,Ask+SL,Ask-TP, NULL,0,0,clrRed); }
 
Busingye Tusasirwe:

Are you sure? I thought they were points. I use a 5 digit broker.


**I see you are using a function to redefine it into PIPs.***


Thank you for your input!