In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
sl = OrderOpenPrice()-(StopLoss*pips);
- We have no idea what StopLoss, TakeProfit, and pips are (value and type.)
- You buy at the Ask and sell at the Bid.
- Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
- Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice
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.)
Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.
Thanks but I found the problem it was the functions Lowprice() Highprice() the code only gives me the location of the highest or lowest candle hence.
incorrect parameters to use as an entry price and creating an invalid stoploss message. The correct code is to locate that candle from the
iHigh or iLow then return the indexed value, hence the entry price to place the pending order. please see below for anyone that needs it.
//+------------------------------------------------------------------+ //| Highest candle price | //+------------------------------------------------------------------+ double HighPrice() { double Highprice =0; //--- calculating the highest value on the 10 consequtive bars in the range //--- from the 1st to the 19th index inclusive on the current chart int val_index=iHighest(NULL,0,MODE_HIGH,10,0); if(val_index!=-1) Highprice=High[val_index]; else PrintFormat("Error in iLowest. Error code=%d",GetLastError()); return(Highprice); } //+------------------------------------------------------------------+ //| Lowest candle price | //+------------------------------------------------------------------+ double LowPrice() { double Lowprice =0; //--- calculating the lowest value on the 10 consequtive bars in the range //--- from the 1st to the 10th index inclusive on the current chart int val_index=iLowest(NULL,0,MODE_LOW,10,0); if(val_index!=-1) Lowprice=Low[val_index]; else PrintFormat("Error in iLowest. Error code=%d",GetLastError()); return(Lowprice);
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
Hi Fellow Coders,
Could you please help me fix this basic code. Trying to set pending orders based on some simple indicators but I want the price to be placed as a BUYSTOP 3 pips higher than the highest of 5 candles back. and same for the lowest but I keep getting the error "invalid stops" Can't see the problem please help.
Here are the Highprice and Lowprice functions
Thanks in advance