Questiong about for-loop

 

I'm looking to place an order once the stochastic %K is below 20, the slow ma is over the fast ma, then check for an additional condition for the stochastic. If this occurs I want the for loop to look back "i." number of bars back to see if an additional condition occurs within that range. Can someone explain what my code is actually doing vs. what I want it to do?

void Check_for_Trade()
  {
   extern int i, FastMA,SlowMA,Signal,Percent_K,Percent_D,Slowing,i_count;
   double main0=iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_WEIGHTED,MODE_MAIN,i);
   double main1=iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_WEIGHTED,MODE_MAIN,i+1);
   double signal0=iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
   double signal1=iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
//--
   double fast= iMA(NULL,0,FastMA,0,0,0,0);//candle that just closed
   double slow=iMA(NULL,0,SlowMA,0,0,0,0);//candle that just closed
//--
   double K_Line0=iStochastic(NULL,0,Percent_K,Percent_D,Slowing,3,0,MODE_MAIN,0); //current k-line
   double D_Line0=iStochastic(NULL,0,Percent_K,Percent_D,Slowing,3,0,MODE_SIGNAL,0); //current d-line
//--
   double K_Line1=iStochastic(NULL,0,Percent_K,Percent_D,Slowing,3,0,MODE_MAIN,1); //previous k-line
   double D_Line1=iStochastic(NULL,0,Percent_K,Percent_D,Slowing,3,0,MODE_SIGNAL,1); //previous d-line
//--RULE
//BUY
//if stochastic is below 20 && K>D && MACD <0 && MACD1>MACD0 && MACD1>signal1 && MACD0<signal >>buy
   if(K_Line1<20 && fast<slow)//BUY when <20
     {
      if(K_Line1<D_Line1 && K_Line0>D_Line0 && K_Line0 <20)
         for(i=i_count; i>=0; i--)
           {
            if(main0<0 && main1<main0 && main1<signal1 && main0>signal0)
            OrderSend(NULL,OP_BUY,1.0,Ask,5,0,0,0,0,0,0);
           }
     }
   } 
 
Anyone?
 
  1. Don't ping posts.
  2. Why do you have a loop when nothing inside it is changing? are you trying to open i_count orders?
  3. What is the value of i, when you read your macds?
Reason: