OrderSend Error 130 - tester - page 2

 
It seems if I don't word my questions wisely, I get shot down and disregarded. 

You are not the only one here.


Quite odd when I am completely self-taught with no programming background at all. 

You are not the only one here too.


I think it has something to do with price being too close to the pending order (or within the FREEZE_LEVEL) entry price. 

OMG. It has nothing to do with FREEZE_LEVEL, instead, it is because of other reasons. I guess more homework needs to be taken care of now.


By the way, you still don't cover the basics of how Point works and how you can manipulate it. Do that and you will see what is going on right now.

 
Ok fair enough. Well I think you've made your point.

I don't understand why it is people enjoy spending time just reinforcing what I already know = I am doing something wrong. I have come on here for tips or clues at least...

Anyway, thanks for telling me one tip = it's not the FREEZE_LEVEL...

I've updated the code in my first post. 
 

A = 1.24000

B = 1.24000

Point = 0.00001

( A > B + Point ) is the same as ( 1.24000 > 1.24001) ...

 

DomGilberto, I sometimes have to wonder if you have difficulty following your own code, especially when you have left it alone for a few days.

If this is the case, imagine how difficult it is for others to follow your code.

I will tell you the process that I went through while looking at your code.

 

Problem is with Error 130, so I zoom in on OrderSend

//---Buy---//

        
if (StopLevel > BuyStopPrice + Point ) BuyStopPrice = StopLevel;
if (StopLevel > btp1 + Point ) btp1 = StopLevel; 
      
if( OpenOrdersThisPair(Symbol()) == 0 && LotSize_Buy - minlot > Point / 2. && 
    D1_ATR > Todays_Range + Point )
  { 
  BuyTicketOrder1 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy,Stored_BuyPrice,3,
                                    BuyStopPrice,btp1,NULL,MagicNumber1,0,Green);
  BuyTicketOrder2 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy2,Stored_BuyPrice,3,
                                    BuyStopPrice,btp2,NULL,MagicNumber1,0,Green);
  BuyTicketOrder3 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy3,Stored_BuyPrice,3,
                                    BuyStopPrice,btp3,NULL,MagicNumber1,0,Green);
  BuyTicketOrder4 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy4,Stored_BuyPrice,3,
                                    BuyStopPrice,btp4,NULL,MagicNumber1,0,Green);
  }          

 Now I see that you use a variable called StopLevel, so where is that assigned a value?

I find it 50 lines back,

double StopLevel = ((MarketInfo(Symbol(), MODE_STOPLEVEL) + 
                        MarketInfo(Symbol(), MODE_SPREAD))*pips)+Bid;

 Now I'm struggling to work out what you are trying to do here, especially as I do not see where the variable pips is declared and assigned a value. But I guess that it is Point for a 4 digit broker or Point*10 for a 5 digit broker.

Incidently isn't that the same as

double StopLevel = (MarketInfo(Symbol(), MODE_STOPLEVEL)*pips)+Ask;

 So I have worked out that StopLevel is the maximum that the stop loss can be set at for a Buy order.

it's not used in any code in the 50 lines as far as I can see, so why is it 50 lines back? 

So we will move it closer to where it is being referenced

//---Buy---//

 
double StopLevel = ((MarketInfo(Symbol(), MODE_STOPLEVEL) + 
                     MarketInfo(Symbol(), MODE_SPREAD))*pips)+Bid;
       
if (StopLevel > BuyStopPrice + Point ) BuyStopPrice = StopLevel;
if (StopLevel > btp1 + Point ) btp1 = StopLevel; 
      
if( OpenOrdersThisPair(Symbol()) == 0 && LotSize_Buy - minlot > Point / 2. && 
    D1_ATR > Todays_Range + Point )
  { 
  BuyTicketOrder1 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy,Stored_BuyPrice,3,
                                    BuyStopPrice,btp1,NULL,MagicNumber1,0,Green);
  BuyTicketOrder2 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy2,Stored_BuyPrice,3,
                                    BuyStopPrice,btp2,NULL,MagicNumber1,0,Green);
  BuyTicketOrder3 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy3,Stored_BuyPrice,3,
                                    BuyStopPrice,btp3,NULL,MagicNumber1,0,Green);
  BuyTicketOrder4 = OrderSend(Symbol(),OP_BUYSTOP,LotSize_Buy4,Stored_BuyPrice,3,
                                    BuyStopPrice,btp4,NULL,MagicNumber1,0,Green);
  }          

 

 Then I look at the next line of code

if (StopLevel > BuyStopPrice + Point ) BuyStopPrice = StopLevel;

 and I think "Have I misunderstood?


If StopLevel is 5 pips below current price and the calculated BuyStopPrice is 50 pips below current price, you will change BuyStopPrice to 5 pips below?

If StopLevel is 5 pips below current price and the calculated BuyStopPrice is 2 pips below current price, you will not change BuyStopPrice even though it may be too close?

By now, I have a headache and leave it be. 

 
Thank you kindly for your post. You're absolutely right. I think I get so annoyed sometimes, I don't take a step back and think logically. I apologize too, but I had actually changed the code to what I am trying to do now. I realized (as you've pointed out) that it was a mess!

What I am going to do now is print out everything again, and I'll post it up including the specific code that goes along with it. I will also clean up all the crap i've written in the code too. As you've pointed out, it's ridiculous!

Will post shortly

(p.s. just so I know, is my code easier to see now?)
 
DomGilberto:

A = 1.24000

B = 1.24000

Point = 0.00001

( A > B + Point ) is the same as ( 1.24000 > 1.24001) ...

I think how you use Point is still wrong. LOL XD
 

You think? I'm looking for people to correct me because they know... Just give me some food for thought at least... Not always asking for just the answer. Your doing neither but having a laugh at my lack of knowledge. 

 Remember when you were learning programming? Bet you never asked any stupid questions did you...

Anyway, I've figured out WHY I am getting Error 130. It has NOTHING to do with what you're talking about. It was more to do with the logic else-where and the "Stored_BuyPrice". It's a static double and it essentially remembers the previous trades buy price and under a rare situation it will try to place a trade at that price when the price of the market is AT THAT price and the stop is ABOVE (for buy) the entry price.

I will post up once I have figured it out. 

 
Right, I've 100% figured out what the issue was. I am stuck with this "simple" part. Would be hugely appreciative if anyone can give an input?

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
 {

   if( IsNewCandle() ) // Checks to see if there is a new H1 candle (bool)
      {
       if( CheckHistory()== true ) // If this returns True I want it to wait until the next H1 candle!


...

Basically, if CheckHistory() returns as True, rather than it progress any further, I want it to wait for a brand new H1 candle? What's a simple way of doing this as I feel like I am getting carried away writing overly complex code for it?

To elaborate further: If CheckHistory returns true and the iTime is within the 1 hour period from the "IsNewCandle()" then I DO NOT want it to progress any further until there IsNewCandle()...

Any help would be hugely appreciative!
 
DomGilberto:
Right, I've 100% figured out what the issue was. I am stuck with this "simple" part. Would be hugely appreciative if anyone can give an input?


Basically, if CheckHistory() returns as True, rather than it progress any further, I want it to wait for a brand new H1 candle? What's a simple way of doing this as I feel like I am getting carried away writing overly complex code for it?

To elaborate further: If CheckHistory returns true and the iTime is within the 1 hour period from the "IsNewCandle()" then I DO NOT want it to progress any further until there IsNewCandle()...

Any help would be hugely appreciative!

if( CheckHistory()== true ) // If this returns True I want it to wait until the next H1 candle!

 If you don't want the EA to do anything at all just 

if( CheckHistory()== true ) // If this returns True I want it to wait until the next H1 candle!
return;

 

 

 

DomGilberto:

(p.s. just so I know, is my code easier to see now?)

Your code is easier to read now that it fits the width of my screen.

 
Thanks Gumrai for your response. Glad it is easier to read now.

The issue is:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
 {

   if( IsNewCandle() ) // Checks to see if there is a new H1 candle (bool)
      {
       if( CheckHistory()== true ) // If this returns True I want it to wait until the next H1 candle!
	return;

...

//+------------------------------------------------------------------+   
//| Ensuring its a new candle function                               |
//+------------------------------------------------------------------+   
bool IsNewCandle()
   {
   if(Bar1Time == iTime(NULL, low, IsNewBar_Shift)) //"Time" used to be "Bars" with no brackets 
      return(false);
      
   Bar1Time = iTime(NULL, low, IsNewBar_Shift); //"Time" used to be "Bars" with no brackets 
   return(true);
   }
As you can see here, it will just go back to IsNewCandle() and just confirm that we are still on the same Bar1Time as before and not actually wait. Basically, if "CheckHistory() == True" then on that specific bar "0" I want NO CODE to run what-so-ever and instead WAIT for "IsNewCandle()" to produce a NEW BAR. On top of this, i then want CheckHistory()==True to be avoided else this code will never progress:

//+------------------------------------------------------------------+
//| Check History to see if trade hit stop                           |
//+------------------------------------------------------------------+
bool CheckHistory()
{
 for(int b=OrdersHistoryTotal()-1; b>=0; b--)
   {

    if( !OrderSelect(b,SELECT_BY_POS,MODE_HISTORY))continue;
     {
      if( OrderMagicNumber() == MagicNumber1  )
        if(OrderSymbol() == Symbol())
        {
        RefreshRates();
         
        if( OrderType() == OP_BUY && OrderStopLoss() - OrderClosePrice() > Point / 2. )
            {
            H1_Buy_Touch = "None";return(true);HistoryBarTime = OrderCloseTime();
            } 

        if( OrderType() == OP_SELL &&  OrderClosePrice() - OrderStopLoss() > Point / 2. )
            {
            H1_Sell_Touch = "None";return(true);HistoryBarTime = OrderCloseTime();
            } 
        }
    } 
  }

return(false); 
}

I cannot get this logic down at all... driving me up the wall....
Reason: