HELP!! ordersend not working

 

the following code is not opening any orders. I have put alerts in certain segments (in bold) so I know the flow of the program is working...can anyone pick up what I am doing wrong pls? gracias.


int start()
{
int Magic=0;


CurrentSignal = check_entry_condition();


if (CurrentSignal=="BUY")
{
Alert("buy order");
int buyticket = OrderSend(Symbol(),OP_BUY,0.2,Ask,3,0,0,WindowExpertName(),MagicNumber,0,Green);

}

if (CurrentSignal=="SELL")
{
Alert("sell order");
int sellticket = OrderSend(Symbol(),OP_SELL,0.2, Bid,3,0,0,WindowExpertName(),MagicNumber,0,Red);

}

return(0);

}//End Main function


// this procedure will check if all of the 3 conditions are met for a buy signal or a sell signal. it will return nothing if all 3 conditions are not met.
string check_entry_condition()
{
string mySignal;
bool BuyCondition1=false, BuyCondition2=false, BuyCondition3=false;
bool SellCondition1=false, SellCondition2=false, SellCondition3=false;

SMA=moving_avg(SlowMovingAvg,0);
MMA=moving_avg(MidMovingAvg,0);
FMA=moving_avg(FastMovingAvg,0);

//Don't test the conditions if there are already two open positions out there
if (open_positions() < 3)
{
if ((FMA > MMA) && (MMA > SMA)) BuyCondition1=true;
if (iSAR(NULL,TimeFrame,PSARStep,PSARMaximum,0)<Close[0]) BuyCondition2=true;
if ((iAO(NULL, 0, 0) > iAO(NULL, 0, 1))) BuyCondition3=true;


if ((FMA < MMA) && (MMA < SMA)) SellCondition1=true;
if (iSAR(NULL,TimeFrame,PSARStep,PSARMaximum,0)>Close[0]) SellCondition2=true;
if ((iAO(NULL, 0, 0) < iAO(NULL, 0, 1))) SellCondition3=true;


if ((BuyCondition1) && (BuyCondition2) && (BuyCondition3)) mySignal = "BUY";


else if ((SellCondition1) && (SellCondition2) && (SellCondition3)) mySignal = "SELL";

Alert ("signal ", mySignal);

}
return(mySignal);
}

 

you should post your code in CODE tag :)

but seems like you make a fault with your stoploss... should be like this:

buy order (made the sl 30 here, 3 seems little short)

int buyticket = OrderSend(Symbol(),OP_BUY,0.2,Ask,Ask-30,0,0,WindowExpertName(),MagicNumber,0,Green);

sell order

int sellticket = OrderSend(Symbol(),OP_SELL,0.2, Bid,Bid+30,0,0,WindowExpertName(),MagicNumber,0,Red);
Also, you might could have that in the journal, if it fails to place the order, with the error number :) good luck

I don't know right now if the WindowsExpertName() is possible the way you have it now, but you could also try it without it. just replace it with NULL

 
So this code was bugging me. I thought I'd clean it up a little:
datetime Now = 0;
int Magic = 0;
double SMA, MMA, FMA, iSARsignal, iAOcurrent, iAOprevious;

int start()
{
   if( Now != Time[0] )
   {
      Now = Time[0];
      iAOprevious = iAO( NULL, 0, 1 );
   }
   
   iAOcurrent = iAO( NULL, 0, 0 );
   iSARsignal = iSAR( NULL, TimeFrame, PSARStep, PSARMaximum, 0 );
   SMA = moving_avg( SlowMovingAvg, 0 ); //I assume moving_avg is defined somewhere
   MMA = moving_avg( MidMovingAvg, 0 );
   FMA = moving_avg( FastMovingAvg, 0 );

   if( open_positions() < 3 )
   {
      if ( BuySignal() )
      { 
         Alert( "buy order" );
         int buyticket = OrderSend( Symbol(), OP_BUY, 0.2, Ask, 30, 0, 0, WindowExpertName(), Magic, 0, Green );
      }
      else if( SellSignal() ) 
      {
         Alert("sell order");
         int sellticket = OrderSend( Symbol(), OP_SELL, 0.2, Bid, 30, 0, 0, WindowExpertName(), Magic, 0, Red );
      }
   }
   return( 0 );

}//End Start function

bool BuySignal()
{
   return( FMA > MMA && MMA > SMA && iSARsignal < Close[0] && iAOcurrent > iAOprevious );
}

bool SellSignal()
{
   return( FMA < MMA && MMA < SMA && iSARsignal > Close[0] && iAOcurrent < iAOprevious );
}
What errors are you seeing in the journal when you call OrderSend?
 
  1. on 5 digit brokers you must adjust TP, SL and slippage
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  2. On ecn brokers, you must open the order and then set tp, sl.
  3. OP_BUY,0.2,Ask,Ask-30,0,
    Ask is something like 1.4567 (EURUSD) so ask-30. is negative
    l(), OP_BUY, 0.2, Ask, 30, 0,
    A stop loss 30 is above the ask of 1.4567. A SL can be no closer than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point from the market. Usually 3 pips (5digit broker 30 points) or 0.00030. Therefor an invalid stop.
Reason: