Ordersend 4107 & 130 errors while using ATR as sl / tp

 

Ok so im pretty new to this and my question might seem elementary, but boils down to I keep getting 130 and 4107 errors when trying to place an order using the ATR as sl / tp.  

So I thought using the (Bid +/- ATR) as sl/tp was a valid method, however it has only executed a trade exactly 1 time for me (GBP/USD if it matters) out of many many attempts.   Could it be something with my brokerage account (Oanda) or maybe something with how my ordersend() function looks like?

My ordersend function:

OrderSend (symb[m], OP_SELL, 0.01, Ask-3, 3, (Bid+(1.0*ATRM15)), (Bid-(1.5*ATRM15)), "TEST-EMAbotV2",MagicNumberM15,0)

I dont even know if its related but i have also tried as a stop NormalizeDouble((Bid+ATRM15),Digits) and got not love either.  But for all I know ATR might not even be the problem; its just from what I understand that 130/4107 errors are for sl/tp issues.

Really appreciate any help or even just being pointed in the right direction, you dont have to walk me through it or anything.  Driving me nuts. Thanks!!!!

 
OrderSend (symb[m], OP_SELL, 0.01, Ask-3, 3, (Bid+(1.0*ATRM15)), (Bid-(1.5*ATRM15)), "TEST-EMAbotV2",MagicNumberM15,0)

You are trying to place an order for symb[m] which one can assume is not the chart symbol.

If you are not using the chart symbol, you cannot use Ask or Bid as they relate to the chart symbol.

Sells must be placed at the symbol bid price.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 

Thanks for getting back to me !  Oh ok, i'll post there in the future.  Just fyi, symb[] is an array with all the Chart symbol names (GBPUSD,USDCAD,etc); should've been more clear when I posted (unless you understood that and i missed something). and double ATRM15 = iATR(symb[m],PERIOD_M15,50,1)


*Edit - think I understand what youre saying now.  Even though my symb[m] cycles through all the symbols, Bid and Ask only work on the specific chart the EA is activated on.  So I guess my question should be is it possible to get Bid and Ask to work with symbols other than the current chart (or if theres some work around to accomplish this).   For context im just trying to use a single EA to scan like 40 currency pairs for a specific setup.   Thanks again, this was the direction I was hoping for, will look into this.

 
Chris:

 should be is it possible to get Bid and Ask to work with symbols other than the current chart (or if theres some work around to accomplish this).

Use SymbolInfoDouble()

 
OrderSend (symb[m], OP_SELL, 0.01, Ask-3, 3, (Bid+(1.0*ATRM15)), (Bid-(1.5*ATRM15)), "TEST-EMAbotV2",MagicNumberM15,0)
  1. Ask/Bid are only the current chart's symbol.
  2. Do you mean -3 or -3 ticks.
  3. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. 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?

    2. 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

    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.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

 
Chris:

Ok so im pretty new to this and my question might seem elementary, but boils down to I keep getting 130 and 4107 errors when trying to place an order using the ATR as sl / tp.  

So I thought using the (Bid +/- ATR) as sl/tp was a valid method, however it has only executed a trade exactly 1 time for me (GBP/USD if it matters) out of many many attempts.   Could it be something with my brokerage account (Oanda) or maybe something with how my ordersend() function looks like?

My ordersend function:

OrderSend (symb[m], OP_SELL, 0.01, Ask-3, 3, (Bid+(1.0*ATRM15)), (Bid-(1.5*ATRM15)), "TEST-EMAbotV2",MagicNumberM15,0)

I dont even know if its related but i have also tried as a stop NormalizeDouble((Bid+ATRM15),Digits) and got not love either.  But for all I know ATR might not even be the problem; its just from what I understand that 130/4107 errors are for sl/tp issues.

Really appreciate any help or even just being pointed in the right direction, you dont have to walk me through it or anything.  Driving me nuts. Thanks!!!!

 OrderSend (symb[m], OP_SELL, 0.01, MarketInfo(symb[m],MODE_ASK), 3,  
   (MarketInfo(symb[m],MODE_BID)+(1.0*ATRM15*MarketInfo(symb[m],MODE_DIGITS))),
   (MarketInfo(symb[m],MODE_BID)-(1.0*ATRM15*MarketInfo(symb[m],MODE_DIGITS))),
    "TEST-EMAbotV2",MagicNumberM15,0); 
 

Mehmet Bastem:

OrderSend (symb[m], OP_SELL, 0.01, MarketInfo(symb[m],MODE_ASK), 3,  
   (MarketInfo(symb[m],MODE_BID)+(1.0*ATRM15*MarketInfo(symb[m],MODE_DIGITS))),
   (MarketInfo(symb[m],MODE_BID)-(1.0*ATRM15*MarketInfo(symb[m],MODE_DIGITS))),
    "TEST-EMAbotV2",MagicNumberM15,0); 


As already stated, Sells must be at bid, not ask.

Reason: