Please check these code correct or not?

1
hi, master mladen, please check these codes correct or not?
i put this indicator as my entry and exit function, i still learn codes, so i made these codes according this indicator, but not sure if it is correct.

Code: Select all

//+------------------------------------------------------------------+
//|                                                          CHO.mq4 |
//|                      Copyright ?2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DarkBlue
//---- input parameters
extern int       SlowPeriod=10;
extern int       FastPeriod=3;
extern int       TypeSmooth=0;// 0 - SMA, 1 - EMA
//---- buffers
double CHO[];
double AD[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   string name,smoothString;
   if (TypeSmooth<0 || TypeSmooth>1) TypeSmooth=0;
   if (TypeSmooth==0) smoothString="SMA"; else smoothString="EMA";
   name="Chaikin Oscillator("+SlowPeriod+","+FastPeriod+","+smoothString+")";

   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CHO);
   SetIndexLabel(0,name);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(1,AD);
   SetIndexEmptyValue(1,0.0);
   IndicatorShortName(name);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit,i;
//----
   if (counted_bars<0) return(-1);

   if (counted_bars==0) 
      {
      limit=Bars-1;
      for (i=limit;i>=0;i--)
        {
         AD[i]=iAD(NULL,0,i);
        }
      for(i=limit-SlowPeriod;i>=0;i--)
        {
         CHO[i]=iMAOnArray(AD,0,FastPeriod,0,TypeSmooth,i)-iMAOnArray(AD,0,SlowPeriod,0,TypeSmooth,i);
        }
      }

   if (counted_bars>0) 
     {
      limit=Bars-counted_bars;
      for (i=limit;i>=0;i--)
        {
         AD[i]=iAD(NULL,0,i);
        }
      for(i=limit;i>=0;i--)
        {
         CHO[i]=iMAOnArray(AD,0,FastPeriod,0,TypeSmooth,i)-iMAOnArray(AD,0,SlowPeriod,0,TypeSmooth,i);
        }
      }            
//----
   return(0);
  }
//+------------------------------------------------------------------+

below is my codes for this entry

Code: Select all

double up4 = iCustom(Symbol(),PERIOD_CURRENT,ind2_name, SlowPeriod, FastPeriod,TypeSmooth,0,1, CC );  
 double down4 = iCustom(Symbol(),PERIOD_CURRENT,ind2_name, SlowPeriod, FastPeriod,TypeSmooth,0,1, CC ); 
 
  
//////////////////////////
 //signal buy
 if(up!=0 && up2!=0 && up3==0 && up4>0  ) return(1);
   

 if(down!=0 && down2!=0 && down3!=0 &&  down4<0  ) return(-1);


 return(0);
 }


Re: Please check these code correct or not?

3
A working version of the "finger trap". But one thing confuses me. It is necessary to use a very large margin so that m0.4 and m09 coincide. Because of this, the calculation speed decreases. :lolno: But the m09 is much faster than the m0.4. :razz:
The screenshot shows m0.4 and m09 with a period of 2. And a multiplier of 0 (Bs[i2]*Bs[i2]* 0 ). If multiplied by 3, the lines will match.
These users thanked the author andrei-1 for the post (total 2):
Chickenspicy, SijjiN

Re: Please check these code correct or not?

4
andrei-1 wrote: Sat Oct 01, 2022 8:22 am A working version of the "finger trap". But one thing confuses me. It is necessary to use a very large margin so that m0.4 and m09 coincide. Because of this, the calculation speed decreases. :lolno: But the m09 is much faster than the m0.4. :razz:
The screenshot shows m0.4 and m09 with a period of 2. And a multiplier of 0 (Bs[i2]*Bs[i2]* 0 ). If multiplied by 3, the lines will match.
Image
there will be always solutions ...
quite simple with proper support resistance lines... :)
:idea:
"There is NO GOD higher than TRUTH" - Mahatma Gandhi


Who is online

Users browsing this forum: No registered users and 17 guests