-
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using 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 close to 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 spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).
-
- JayCee13: I am not sure why it was store at first, then went back to 0 in next candle
double BuyPrice = 0; if ( (StochMain2 > 20) && (StochMain1 < 20) ) { BuyPrice = iClose(NULL, PERIOD_M15, 1); Print ("In If condition, Buy Price is: ", BuyPrice); } Print ("After if condition, Buy Price is: ", BuyPrice);
Since you are not using strict, the default for automatic variables is zero. The first time you set the variable. The next time you don't, so you got zero.
-
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using 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 close to 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 spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).
-
-
Since you are not using strict, the default for automatic variables is zero. The first time you set the variable. The next time you don't, so you got zero.
Hi William Roede, it was very kind of you when your help was more than I asked.
About issue number 2, I am not sure if I could correct it. Could you kindly show me how to correct the code/ logic please? or kindly point me to the correct way/ material for the issue.
Sorry for my silliness.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone, I am new to MQL4 programming and try to learn and build some simple EA with nearly 0 programming background. Any help or suggestion will be appreciated very much.
Please kindly help a look at the below for the code and screenshots:
Recently, I have some problem when trying to store the close price value of the last candle if the condition is true, I am not sure why it was store at first, then went back to 0 in next candle (Screenshot attached, I use Print Function to find out)
Please kindly help me if there is something wrong in my code or the logic in my if condition.
Once again, thank you very much for your time!