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.
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.
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
- 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?
- 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 - 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); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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?