Please help to convert this mq4 indicator to cAlgo

Created at 15 Jul 2013, 18:41
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
FO

forexner12

Joined 06.04.2013

Please help to convert this mq4 indicator to cAlgo
15 Jul 2013, 18:41


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

//|                                                   SweetSpots.mq4 |

//|                                                                  |

//|                                                                  |

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

 

 

#property indicator_chart_window

 

/* Introduction:

 

   This indicator shows lines at sweet spots (50 and 100 

   pips levels). It is recommended to turn off the grid.

   

   Enjoy!

 

   Markus

*/

 

extern int NumLinesAboveBelow= 100;

extern int SweetSpotMainLevels= 100;

extern color LineColorMain= Gold;

extern int LineStyleMain= STYLE_SOLID;

extern bool ShowSubLevels= true;

extern int sublevels= 250;

extern color LineColorSub= Gold;

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==0) {

         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);

   }

}

      


@forexner12
Replies

adaled
16 Jul 2013, 17:39

you can try this 2calgo.com

/forum/indicator-support/1223


@adaled

forexner12
17 Jul 2013, 05:22

I have tried but not succesful 


@forexner12

adaled
18 Jul 2013, 12:27

I think it's similar to round numbers. /algos/indicators/show/263


@adaled

algotrader
31 Jul 2013, 18:39

RE:
forexner12 said:

I have tried but not succesful 

Now your indicator is supported by 2calgo.com. Please try to convert it one more time.


@algotrader

forexner12
01 Aug 2013, 15:18

thanks its working fine now


@forexner12

druster
01 Aug 2013, 18:57

RE:
adaled said:

you can try this 2calgo.com

/forum/indicator-support/1223

Hi, I converted code from MQ4 for cAlgo, and where to have paste new code ?

Thank you in advance!


@druster

algotrader
01 Aug 2013, 19:06

RE: RE:
druster said:
adaled said:

you can try this 2calgo.com

/forum/indicator-support/1223

Hi, I converted code from MQ4 for cAlgo, and where to have paste new code ?

Thank you in advance!

  1. Open cAlgo platform
  2. Go to Indicators tab
  3. Press New button
  4. Give a name for your indicator
  5. Paste Converted code to the code editor
  6. Press Build button

Now you can find your indicator in cTrader: Indicators->Custom.

You can also look at an instruction for custom indicators from ctdn: http://help.spotware.com/calgo/custom-indicators


@algotrader

druster
01 Aug 2013, 19:18

Thank you ! 


@druster

fcarabat
22 May 2022, 21:25

RE: RE:

algotrader said:

forexner12 said:

I have tried but not succesful 

Now your indicator is supported by 2calgo.com. Please try to convert it one more time.

 

I know this is a super old post, but i'm trying to convert the same sweetspots indicator with this page you mentioned, but it gives me back an error.  not sure what i'm doing wrong, i just copy and pasted the code.  any help would be greatly appreciated.


@fcarabat

amusleh
23 May 2022, 09:00

RE: RE: RE:

fcarabat said:

algotrader said:

forexner12 said:

I have tried but not succesful 

Now your indicator is supported by 2calgo.com. Please try to convert it one more time.

 

I know this is a super old post, but i'm trying to convert the same sweetspots indicator with this page you mentioned, but it gives me back an error.  not sure what i'm doing wrong, i just copy and pasted the code.  any help would be greatly appreciated.

Hi,

You can post a job request on our jobs page or contact one of our consultant partners.


@amusleh