Download MetaTrader 5

Coding question-Please help

To add comments, please log in or register
John McClark
553
John McClark  

Hello, I have this indcator that draws psy levels. now it draws like 1.11150, 1.11100, 1.110500 ..... I would like to make the differnece 10x bigger so it would be 1.11000, 1.11500, 1.1200 etc.

Please tell me what needs to be change in my code and what setting can control it...

thanks in advance 

 


extern int NumLinesAboveBelow= 100;

extern int SweetSpotMainLevels= 100;

extern color LineColorMain= DimGray;

extern int LineStyleMain= STYLE_SOLID;

extern bool ShowSubLevels= true;

extern int sublevels= 50;

extern color LineColorSub= 2500134;

extern int LineStyleSub= STYLE_DOT;




//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

{

   return(0);

}


int deinit()

{

   int obj_total= ObjectsTotal();

   

   for (int i= obj_total; i>=0; i--) {

      string name= ObjectName(i);

    

      if (StringSubstr(name,0,11)=="[SweetSpot]") 

         ObjectDelete(name);

   }

   

   return(0);

}

  

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

{

   static datetime timelastupdate= 0;

   static datetime lasttimeframe= 0;

   

    

   // no need to update these buggers too often   

   if (CurTime()-timelastupdate < 600 && Period()==lasttimeframe)

      return (0);

   

   deinit();  // delete all previous lines

      

   int i, ssp1, style, ssp, thickness; //sublevels= 50;

   double ds1;

   color linecolor;

   

   if (!ShowSubLevels)

      sublevels*= 2;

   

   ssp1= Bid / Point;

   ssp1= ssp1 - ssp1%sublevels;


   for (i= -NumLinesAboveBelow; i<NumLinesAboveBelow; i++) {

   

      ssp= ssp1+(i*sublevels); 

      

      if (ssp%SweetSpotMainLevels==2) {

         style= LineStyleMain;

         linecolor= LineColorMain;

      }

      else {

         style= LineStyleSub;

         linecolor= LineColorSub;

      }

      

      thickness= 1;

      

      if (ssp%(SweetSpotMainLevels*10)==0) {

         thickness= 2;      

      }


      if (ssp%(SweetSpotMainLevels*100)==0) {

         thickness= 3;      

      }

      

      ds1= ssp*Point;

      SetLevel(DoubleToStr(ds1,Digits), ds1,  linecolor, style, thickness, Time[10]);

   }


   return(0);

}



//+------------------------------------------------------------------+

//| Helper                                                           |

//+------------------------------------------------------------------+

void SetLevel(string text, double level, color col1, int linestyle, int thickness, datetime startofday)

{

   int digits= Digits;

   string linename= "[SweetSpot] " + text + " Line",

          pricelabel; 


   // create or move the horizontal line   

   if (ObjectFind(linename) != 0) {

      ObjectCreate(linename, OBJ_HLINE, 0, 0, level);

      ObjectSet(linename, OBJPROP_STYLE, linestyle);

      ObjectSet(linename, OBJPROP_COLOR, col1);

      ObjectSet(linename, OBJPROP_WIDTH, thickness);

      

      ObjectSet(linename, OBJPROP_BACK, True);

   }

   else {

      ObjectMove(linename, 0, Time[0], level);

   }

}

       

Tim Sustar
519
Tim Sustar  

Try using the code I personally use.... 

extern int LinesAboveBelow= 10;

extern color LineColorMain= LightGray;

extern color LineColorSub= Gray;


double dPt;


//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

{

   dPt = Point;

   if(Digits==3||Digits==5){

      dPt=dPt*10;

   } 

   return(0);

}


int deinit()

{

   int obj_total= ObjectsTotal();

   

   for (int i= obj_total; i>=0; i--) {

      string name= ObjectName(i);

    

      if (StringSubstr(name,0,11)=="[SweetSpot]") 

         ObjectDelete(name);

   }

   

   return(0);

}

  

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

{

   static datetime timelastupdate= 0;

   static datetime lasttimeframe= 0;

   

    

   // no need to update these buggers too often   

   if (CurTime()-timelastupdate < 600 && Period()==lasttimeframe)

      return (0);

      

   int i, ssp1, style, ssp;

   double ds1;

   color linecolor;

   

   ssp1= Bid / dPt;

   ssp1= ssp1 - ssp1%50;


   for (i= -LinesAboveBelow; i<LinesAboveBelow; i++) {

      ssp= ssp1+(i*50); 

      

      if (ssp%100==0) {

         style= STYLE_SOLID;

         linecolor= LineColorMain;

      }

      else {

         style= STYLE_DOT;

         linecolor= LineColorSub;

      }

      

      ds1= ssp*dPt;

      SetLevel(DoubleToStr(ds1,Digits), ds1,  linecolor, style, Time[10]);

   }


   return(0);

}



//+------------------------------------------------------------------+

//| Helper                                                           |

//+------------------------------------------------------------------+

void SetLevel(string text, double level, color col1, int linestyle, datetime startofday)

{

   int digits= Digits;

   string linename= "[SweetSpot] " + text + " Line",

          pricelabel; 


   // create or move the horizontal line   

   if (ObjectFind(linename) != 0) {

      ObjectCreate(linename, OBJ_HLINE, 0, 0, level);

      ObjectSet(linename, OBJPROP_STYLE, linestyle);

      ObjectSet(linename, OBJPROP_COLOR, col1);

      ObjectSet(linename, OBJPROP_WIDTH, 0);

   }

   else {

      ObjectMove(linename, 0, Time[0], level);

   }

}

       

To add comments, please log in or register