Error Code "0"? - page 2

 
DomGilberto:
Oh sorry - I am no longer getting any error what so ever. I am getting just buy orders going through and no sell orders...

It's in relation to my previous thread regarding MA cross overs - I still don't get it! But I don't want to wind anyone up and beat a dead horse whilst people are giving me the answer (although I dont understand the answer lol)! Cheers RaptorUK for your help!

Can't speak for anyone else,  I'm not getting wound up . . . 

If you are getting no errors and no sell order placed then  OpenOrdersThisPair(Symbol())  does not equal 0 ,   what type is that function ?  is it an int or a double ?  or maybe a bool ?

 
//+----------------------------------------------------------------------------------------------------------------------------------------+  
//| Check to see if any order open on this currency pair                                                                                   |
//+----------------------------------------------------------------------------------------------------------------------------------------+   

int OpenOrdersThisPair(string pair)
{
   int total=0;
      for(int i=OrdersTotal()-1; i >= 0; i--)
         {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==pair) total++;
         }
         return (total);
} 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

   double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
   if (ticksize == 0.00001 || ticksize == 0.001) // if you set this to 0 it WONT throw an order out straight away.
   pips = ticksize*10;
   else pips = ticksize;  
   

   return(0);
  }
I actually cannot understand what the issue is. I've written the MA if statements as many ways my limited knowledge is telling me (clearly limited as it wont work on the short side...)

I think it's because the orders are not simply being placed on where the cross of the moving averages take place, but at a different point.
 
//+----------------------------------------------------------------------------------------------------------------------------------------+   
//| Function that checks for an MA Cross                                                                                                   |
//+----------------------------------------------------------------------------------------------------------------------------------------+   
  

void CheckForMaTradeLong()
{
   
   TriggerBarTime = Time[1];
   
   for (int i=0; i < Bars; i++)
   {
   double i1  = iMA(NULL,60,3,0,1,0,i); 
   double i2  = iMA(NULL,60,5,0,1,0,i);
   double i3  = iMA(NULL,60,8,0,1,0,i);
   double i4  = iMA(NULL,60,10,0,1,0,i);  
   double i5  = iMA(NULL,60,12,0,1,0,i);
   double i6  = iMA(NULL,60,15,0,1,0,i);  
   double i7  = iMA(NULL,60,30,0,1,0,i);
   double i8  = iMA(NULL,60,35,0,1,0,i);
   double i9  = iMA(NULL,60,40,0,1,0,i);
   double i10 = iMA(NULL,60,45,0,1,0,i);
   double i11 = iMA(NULL,60,50,0,1,0,i);
   double i12 = iMA(NULL,60,60,0,1,0,i); 
   double ema21 = iMA(NULL,60,21,0,1,0,i);   

   double TriggerBarTime = (i1>i2 && i2>i3 && i3>i4 && i4>i5 && i5>i6 && i6>i7 && i7>i8 && i8>i9 && i9>i10 && i10>i11 && i11>i12); // this needs to just tell me where all the MA's fan up and nothing more...
   if(i1 > i12)
   if (TriggerBarTime == true)
       if(Low[1]<ema21 && i12<Close[1]) OrderEntry(0);
         if(Close[1]<i12) DeleteOrder(0);   
   
   break;
   }
   return(i-1);
   }

I know this is the problem! I know I have asked before regarding this on a different topic, but I'd really appreciate the answer to this question (and yes, I know the code is sloppy, I've just spent a lot of time chopping, compiling and running strategy to see first hand how they're communicating with one another. Not to mention the unnecessary way I've written it too... but ignoring that...)

Q.1) With regards to the  "double triggerbartime" line and the > than section.... All I am wanting to understand is how I tell this function to find out when all the moving averages are greater than the previous compared moving average, and then forget about making sure they remain in the right order... instead from that point all I need to make sure is, is having PRICE CLOSE remain above the "i12" (60 EMA) - if it does, then it can follow ahead with the other IF statements and throw out a long order via "OrderEntry(0)" - If it doesn't, then it needs to then look at the long (i1>i2 && i2>i3...) line and wait for this to be true again before considering the next lines...

I know the answer is staring right at me, just becoming a little frustrating and would really appreciate this one bit of nugget.... Thanks!

 

 
  1. Your Post
    double TriggerBarTime = (i1>i2  && i2>i3   && i3>i4 && i4>i5 && 
                             i5>i6  && i6>i7   && i7>i8 && i8>i9 && 
                             i9>i10 && i10>i11 && i11>i12);
       if (TriggerBarTime == true)
    What data type should TrgggerBarTime be?
    double TriggerBarTime = boolean;
       if (double == true)

  2. Why are you looking at old bars for TriggerBarTime AND the last bar for orderEntry?
  3. Fix your indenting
    Your post
       if(i1 > i12)
       if (TriggerBarTime == true)
           if(Low[1]<ema21 && i12<Close[1]) OrderEntry(0);
             if(Close[1]<i12) DeleteOrder(0);   
    Properly indented. Is this really what you meant?
    if(i1 > i12 && TriggerBarTime && Low[1]<ema21 && i12<Close[1]){
        OrderEntry(0);
    }
    if(Close[1]<i12){
        DeleteOrder(0);
    }
    
 
//TriggerBarTime works in conjunction with:

   int iTBT= iBarShift(NULL,60, TriggerBarTime, true),
        iHH= iHighest(NULL,60, MODE_HIGH, iTBT + 1, 0); 
            double buyPrice = High[iHH]+PadAmount*pips;

//I then use this "buyPrice" in conjunction with OrderSend for where the price of the entry order is...

I am wanting to know where all the MA's are fanned out, but they DO NOT need to be true ALL the time... I just want that to be true before anything else... On the basis this is true, all that needs to happen from this price is that NO bars close beneath the 60 EMA (for a long) to remain valid for any long position to be pushed out...

I am using TriggerBarTime to find the highest point from where all the moving averages stacked up in the right order and the bar that then proceeds in touching the 21 EMA...

So although you've straightened out the indenting for me, that pretty much does what I had written before (unless I am missing something?) Probs my fault I didnt explain it properly. 

 

(ah yeah - I know it should be bool that was a mistake - I was simply playing around and forgot to switch them back.) 

 
double TriggerBarTime = (i1>i2 .. 
it is true or false 0 or 1 nothing else
 int iTBT= iBarShift(NULL,60, TriggerBarTime, true),
Third argument to iBarShift must be a datetime. iBarShift(0) or (1) will ALWAYS be Bars-1.
 
datetime          TriggerBarTime;
I have this in the global section...

I dont understand your previous post? ^

Is it possible to suggest how I write the If line relative to my post above yours?
 
DomGilberto: I have this in the global section...
AND you have hidden it with the local declaration.
 
Sorry, but that again, just makes no sense to me... 
 
DomGilberto: Sorry, but that again, just makes no sense to me... 
int myVariable = 0;
int start(){
  double myVariable = 1;
  Print(myVariable); // Outputs 1.0
  myVariable++;
  myFunction(myVariable);
}
void myFunction(double v){
  Print(myVariable," ",v); // Outputs 0 2.0
}
Reason: