OrderSend Error 130 - tester - page 3

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

The issue is:


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:


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

You are doing your best to confuse yourself and me.

return exits a function and may or may not send a value back to where the function was called from.

OnTick is a function that is called by the inner workings of MT4 when a new tick is detected.

Any return within OnTick will return control to the MT4 system that will then wait for a new tick.

It will NOT recall any function that was previously called in OnTick 

 

Using functions can be really useful, but is there really any good reason to use a function to detect a new bar?

Then you present the function

//+------------------------------------------------------------------+   
//| 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);
   }

What the hell is low?

what is  IsNewBar_Shift ?

 It means nothing to us as we do not have full information

 
Maybe something along the lines of:

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

      CheckHistory(); // check history to see if last trade stopped out - if so it resets bias to "None"

      if(  IsNewCandle() )  
         {

         if( Bar1Time > HistoryBarTime )
            {
            CheckForMaTrade(); // Checks long or short bias and results in pending orders if applicable
            }
             
             
         if( HistoryBarTime > Bar1Time )
            {
            IsNewCandle(); // checks if there is a new bar.
            }
            
         } 
...
2014.09.23 12:08:40.733	2003.06.03 14:00  TF - V2.3.4 - USDCAD,H1: Bar1Time - 2003.06.03 13:00:00 > HistoryBarTime - 1970.01.01 00:00:00
I'm going wrong with how "HistorybarTime" is being stored...
 
GumRai:

Using functions can be really useful, but is there really any good reason to use a function to detect a new bar?

Then you present the function

What the hell is low?

what is  IsNewBar_Shift ?

 It means nothing to us as we do not have full information

 

 

 

Yea I am still working on understanding what everyone means by making it more useful (in terms of the naming of variables)? I appreciate this being a little ambiguous! I use "low" because it corresponds to moving averages and basically makes sure that everything is working in unison on the right time-frame. low = 60, middle = 240 and high = 1440. Some pairs use different time-frames. Could look at it as smallest TF, middle TF, highest TF... As everything happens (trigger bar and entry wise) on the lowest time frame, it all needs to work in unison so it global declared.

You are right though, I should make it easier to understand! What I am trying to do is above^ but I cannot get it working.
 
DomGilberto:
Getting error 130 on OrderSend now and again... I am back-testing within FXCM. I don't understand why as I am trying to use FREEZE_LEVEL as I thought that sometimes my stops and targets can be too close to the current price to send the BUY and SELLSTOPS? 

Really appreciate any help or thoughts....
I did too . . .  and I found out why I was,  might be the same for you . .  https://www.mql5.com/en/forum/134846
 

Interesting thank you! That is really helpful, thanks RaptorUK! Was going insane.

I was actually also getting Error 130 due to the fact that my entry price was stored to remain static through-out 1 setup (trade) but not forgetting the entry price under certain rules for the following one after. Instead it would store this same entry price for the next trade and try to enter when price was above or at the BuyStop... Little hard to explain but I think I have it sorted now. 

 With what you have discovered though, do you think it is appropriate to do exactly what you have said in that link on all my pending orders to be on the safe side: (assuming of course, as you've said, that its a 5 digit broker which mine is: FXCM)?

SellTicketOrder1 = OrderSend(Symbol(),OP_SELLSTOP,LotSize_Sell,Stored_SellPrice,3,
                               SellStopPrice - Point,stp1,NULL,MagicNumber1,0,Red); // - Point ?

...

SellTicketOrder1 = OrderSend(Symbol(),OP_SELLSTOP,LotSize_Sell,Stored_SellPrice,3,
                                      SellStopPrice ,stp1,NULL,MagicNumber1,0,Red);
 
DomGilberto:

Interesting thank you! That is really helpful, thanks RaptorUK! Was going insane.

I was actually also getting Error 130 due to the fact that my entry price was stored to remain static through-out 1 setup (trade) but not forgetting the entry price under certain rules for the following one after. Instead it would store this same entry price for the next trade and try to enter when price was above or at the BuyStop... Little hard to explain but I think I have it sorted now. 

 With what you have discovered though, do you think it is appropriate to do exactly what you have said in that link on all my pending orders to be on the safe side: (assuming of course, as you've said, that its a 5 digit broker which mine is: FXCM)?

 

It's the only way I could eliminate the error 130s I was getting,  not tried it recently though.  If everything is correct according to the requirements for placing trades then I don't see another way around the issue . . . I'm pretty sure it's a bug but didn't get round to reporting it to the service desk . . .  they didn't handle MT4 issues at the time.
Reason: