Anyone know why ordersend won't work ?

To add comments, please log in or register
torexvir
261
torexvir  
void start()
{
   int    i=0 ,nCountedBars;        //i=0 added instead of just i, in order to get rid of warning when under an EA template
   bool   bFound;
   double dCurrent;
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted    
   if(nCountedBars<=2)
      i=Bars-nCountedBars-3;
   if(nCountedBars>2)
     {
      nCountedBars--;
      i=Bars-nCountedBars-1;
     }      
          
//----Up and Down Fractals
while(i>=3)
     {
      //----Fractals up
      bFound=false;
      dCurrent=High[i];
      
        if(dCurrent>High[i+1]  && dCurrent>High[i-1])
        {
         bFound=true;
         high=1;       
         //ExtUpFractalsBuffer[i]=dCurrent;  //Hidden the buffer as it is an EA
         OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Ask-150*Point,Ask+500*Point,"BUY ORDER",0,0,clrGreen);  // Shouldn't a buy order be placed when fractal forms
        }


//-----Another way i tried wording it still no trade executed


 if(high!=0)
        {
        OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Ask-150*Point,Ask+500*Point,"BUYORDER",0,0,clrGreen);
        Print("Buy Order Placed");  
        Print(high);     
        }
}

The above code is a snippet from the fractals indicator and i merely want it to open an order when the fractal forms.

It is compiled as an EA and no errors show. However when the fractal forms no order is sent. Live trading is turned on etc.

Its on EURUSD so its essentially a 15 pip stop and 50 pip target.

I have tried a variety of ways to word it and still nothing and i need to sit and wait fro a fractal to form to check if it works each time.


Anybody got any thoughts it would be much appreciated ?

Thanks :)

William Roeder
20210
William Roeder  
  1.      OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Ask-150*Point,Ask+500*Point,"BUY ORDER",0,0,clrGreen);
    
    You would know why, if you Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  2. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 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.)

  3.    int    i=0
            if(dCurrent>High[i+1]  && dCurrent>High[i-1])
    The future is unknowable. Use strict and you would have known why.

  4. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
torexvir
261
torexvir  
whroeder1:
  1. You would know why, if you Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  2. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 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.)

  3. The future is unknowable. Use strict and you would have known why.

  4. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
void start()
{
   int    i ,nCountedBars;        
   bool   bFound;
   double dCurrent;
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted    
   if(nCountedBars<=2)
      i=Bars-nCountedBars-3;
   if(nCountedBars>2)
     {
      nCountedBars--;
      i=Bars-nCountedBars-1;
     }      
          
//----Up and Down Fractals
while(i>=3)
     {
      //----Fractals up
      bFound=false;
      dCurrent=High[i];
      
        if(Close[i+1]<Close[i+2] && Close[i+2]>Close[i+3])
        
        {
         bFound=true;
         high=1;       
         //ExtUpFractalsBuffer[i]=dCurrent;  //Hidden the buffer as it is an EA
         TicketHigh=OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Bid-150*Point,Bid+500*Point,"BUY ORDER",0,0,clrGreen);  // Shouldn't a buy order be placed when fractal forms
        }

 if(TicketHigh <0)
       {
       Print("Order send failed, error # ", GetLastError());
       }
       else
         Print("TicketHigh placed succesfully");


//-----Another way i tried wording it still no trade executed


 if(high!=0)
        {
        TicketHigh=OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Bid-150*Point,Bid+500*Point,"BUYORDER",0,0,clrGreen);
        Print("Buy Order Placed");  
        Print(high);     
        }

 if(TicketHigh <0)
       {
       Print("Order send failed, error # ", GetLastError());
       }
       else
         Print("TicketHigh placed succesfully");
}

Didn't even spot the ASK and BID part whoops changed it. #property strict was already being used on the EA. Changed the [i-1] section to just simply compare the last three candles once the most recent is closed. 

So the indicator can use [i-1] to "see the future" but you can't use that on an EA.

However even with changes still no change at all. NO orders or messages being printed etc.

hmmm anymore ideas?

Oh wait its the IndicatorCounted() function isn't it which is messing up i.

Perhaps it would be easier to just build a plain EA and call the fractals indicator using ICustom with buy and sell orders in it 


EDIT:

Got it working with iCustom. Thanks for the pointers 

To add comments, please log in or register