You should share your code for help.
for (int i=0;i<=ObjectsTotal()-1;i++) { if (stopPos==false && sumSpread<maxSpread) {a=0;} if (ObjectType(ObjectName(i))==OBJ_TREND) { double lp=ObjectGetValueByShift(ObjectName(i),0); double lp1=ObjectGetValueByShift(ObjectName(i),1); double lineBiddist=MathAbs(NormalizeDouble(Bid-lp,Digits)); for (int j=0;j<ArraySize(oneTimePos);j++) { if (oneTimePos[j]==ObjectName(i)) { a=1; break; } } for (int j=0;j<ArraySize(candleDistancePos);j++) { int dist=iBars(Symbol(),0)-candleDistanceNum[j]; if (candleDistancePos[j]==ObjectName(i) && dist<StrToDouble(StringSubstr(ObjectDescription(ObjectName(i)),4))) { a=1; break; } } if (High[0]>=lp && Low[0]<=lp) { if(StringSubstr(ObjectDescription(ObjectName(i)),0,1)=="1" && a==0 ) { ord=OrderSend(Symbol(),OP_BUY,lot,Ask,maxSlippage,Ask-(sl*Point),Ask+(tp*Point)); trades++; totalLots+=lot; if (StringSubstr(ObjectDescription(ObjectName(i)),2,1)=="1" && a==0) { ArrayResize(oneTimePos,ArraySize(oneTimePos)+1); oneTimePos[ArraySize(oneTimePos)-1]=ObjectName(i); Print(oneTimePos[ArraySize(oneTimePos)-1]); Print(a); } if (StringSubstr(ObjectDescription(ObjectName(i)),2,1)=="2" && a==0) { ArrayResize(candleDistancePos,ArraySize(candleDistancePos)+1); candleDistancePos[ArraySize(candleDistancePos)-1]=ObjectName(i); ArrayResize(candleDistanceNum,ArraySize(candleDistanceNum)+1); candleDistanceNum[ArraySize(candleDistanceNum)-1]=iBars(Symbol(),0); } } } }
Please edit your posts and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023)
Please edit your posts and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023)
ord=OrderSend(Symbol(),OP_BUY,lot,Ask,maxSlippage,Ask-(sl*Point),Ask+(tp*Point));
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by 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 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 spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
my code work correctly in live market
but in backtest it opens too much positions at the same time
what is the problem?