i need this indicator be a historical one

akram801

Trader
May 28, 2011
10
0
17
hi guys ...


i need this indicator be a historical one
to be able to make a backtest , the file is attached
MQL4:
//+------------------------------------------------------------------+
//|                                                     AAA_Emad.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        [url]http://www.metaquotes.net[/url] |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
 
#property indicator_chart_window
extern string name1="EMAD - LEVELS";
extern string name2="By: Eng. Emad";
extern int corner=1;
extern int day=7;
extern double alpha=0.382;
extern color upper1=Red;
extern color upper2=Blue;
extern color upper3=Red;
extern color upper4=Lime;
extern color upper5=Aqua;
extern color upper6=Aqua;
//--------------------------
extern color lower1=Yellow;
extern color lower2=Blue;
extern color lower3=Yellow;
extern color lower4=Lime;
extern color lower5=Aqua;
extern color lower6=Aqua;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   DrawLogo();
     IndicatorShortName("Eng. Emad Gann || Programmed By Mercury_man");
 
//---- indicators
Print(Open[0]," , ",Open[1]," , ",Open[2]," , ",Open[3]," , ",Open[4]," , ",Open[5]," , ",Open[6]);
   for (int x=1;x<=day-1; x++)
   {
   double p=  iOpen(Symbol(),PERIOD_D1,x-1);
 
 
   double ns=MathLog(iOpen(Symbol(),PERIOD_D1,x-1)/iOpen(Symbol(),PERIOD_D1,x));
 
   double sqns=ns*ns;
 
double ave1=ave1+ns;
double ave2=ave2+sqns;
   }
   ave1=ave1/(day);
   ave2=ave2/(day);
   double RChAv=(ave2-(ave1*ave1));
   double dailyChAv=MathSqrt(RChAv)*100;
   double yearlyChAv=MathSqrt(365)*dailyChAv;
   double daiyPipCh=iOpen(Symbol(),PERIOD_D1,0)*dailyChAv/100;
 
 
//----
double AAA1=NormalizeDouble(iOpen(Symbol(),PERIOD_D1,0)-alpha*daiyPipCh,Digits);
       ObjectCreate("AAA1",OBJ_HLINE,0,1,AAA1);
       ObjectSet("AAA1", OBJPROP_COLOR, lower1);
       ObjectSet("AAA1", OBJPROP_WIDTH, 1);
       ObjectSet("AAA1",OBJPROP_STYLE,1);
//---------
double AAA2=NormalizeDouble(iOpen(Symbol(),PERIOD_D1,0)+alpha*daiyPipCh,Digits);
       ObjectCreate("AAA2",OBJ_HLINE,0,1,AAA2);
       ObjectSet("AAA2", OBJPROP_COLOR, upper1);
       ObjectSet("AAA2", OBJPROP_WIDTH, 1);
       ObjectSet("AAA2",OBJPROP_STYLE,1);
//---------
double AAA3=NormalizeDouble(iOpen(Symbol(),PERIOD_D1,0)+daiyPipCh,Digits);
       ObjectCreate("AAA3",OBJ_HLINE,0,1,AAA3);
       ObjectSet("AAA3", OBJPROP_COLOR, upper2);
       ObjectSet("AAA3", OBJPROP_WIDTH, 2);
       ObjectSet("AAA3",OBJPROP_STYLE,0);
//---------
 
double AAA4=NormalizeDouble(AAA3+(AAA3-AAA2)/2,Digits);
       ObjectCreate("AAA4",OBJ_HLINE,0,1,AAA4);
       ObjectSet("AAA4", OBJPROP_COLOR, upper3);
       ObjectSet("AAA4", OBJPROP_WIDTH, 2);
       ObjectSet("AAA4",OBJPROP_STYLE,0);
//---------
 
double AAA5=NormalizeDouble(AAA2+(AAA3-AAA2)/2,Digits);
       ObjectCreate("AAA5",OBJ_HLINE,0,1,AAA5);
       ObjectSet("AAA5", OBJPROP_COLOR, upper4);
       ObjectSet("AAA5", OBJPROP_WIDTH, 2);
       ObjectSet("AAA5",OBJPROP_STYLE,0);
//---------
 
double AAA6=NormalizeDouble(AAA4+(AAA2-AAA1),Digits);
       ObjectCreate("AAA6",OBJ_HLINE,0,1,AAA6);
       ObjectSet("AAA6", OBJPROP_COLOR, upper5);
       ObjectSet("AAA6", OBJPROP_WIDTH, 2);
       ObjectSet("AAA6",OBJPROP_STYLE,0);
//---------
 
double AAA7=NormalizeDouble(AAA6+(AAA2-AAA1),Digits);
       ObjectCreate("AAA7",OBJ_HLINE,0,1,AAA7);
       ObjectSet("AAA7", OBJPROP_COLOR, upper6);
       ObjectSet("AAA7", OBJPROP_WIDTH, 2);
       ObjectSet("AAA7",OBJPROP_STYLE,0);
//---------
double AAA8=NormalizeDouble(iOpen(Symbol(),PERIOD_D1,0)-daiyPipCh,Digits);
       ObjectCreate("AAA8",OBJ_HLINE,0,1,AAA8);
       ObjectSet("AAA8", OBJPROP_COLOR, lower3);
       ObjectSet("AAA8", OBJPROP_WIDTH, 2);
       ObjectSet("AAA8",OBJPROP_STYLE,0);
//---------
double AAA9=NormalizeDouble(AAA8-(AAA1-AAA8)/2,Digits);
       ObjectCreate("AAA9",OBJ_HLINE,0,1,AAA9);
       ObjectSet("AAA9", OBJPROP_COLOR, lower4);
       ObjectSet("AAA9", OBJPROP_WIDTH, 2);
       ObjectSet("AAA9",OBJPROP_STYLE,0);
//----------------
double AAA10=NormalizeDouble(AAA8+(AAA1-AAA8)/2,Digits);
       ObjectCreate("AAA10",OBJ_HLINE,0,1,AAA10);
       ObjectSet("AAA10", OBJPROP_COLOR, lower2);
       ObjectSet("AAA10", OBJPROP_WIDTH, 2);
       ObjectSet("AAA10",OBJPROP_STYLE,0);
//----------------
double AAA11=NormalizeDouble(AAA9-(AAA2-AAA1),Digits);
       ObjectCreate("AAA11",OBJ_HLINE,0,1,AAA11);
       ObjectSet("AAA11", OBJPROP_COLOR, lower5);
       ObjectSet("AAA11", OBJPROP_WIDTH, 2);
       ObjectSet("AAA11",OBJPROP_STYLE,0);
 
//----------------
double AAA12=NormalizeDouble(AAA11-(AAA2-AAA1),Digits);
       ObjectCreate("AAA12",OBJ_HLINE,0,1,AAA12);
       ObjectSet("AAA12", OBJPROP_COLOR, lower6);
       ObjectSet("AAA12", OBJPROP_WIDTH, 2);
       ObjectSet("AAA12",OBJPROP_STYLE,0);
 
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
void DrawLogo() {
   string l_name_0 = "L_1";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, corner);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 10);
   }
   ObjectSetText(l_name_0, name1, 22, "Arial", White);
   l_name_0 =  "L_2";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, corner);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 40);
   }
   ObjectSetText(l_name_0, name2, 14, "Arial", Gold);
   l_name_0 =  "L_3";
   if (ObjectFind(l_name_0) == -1) {
      ObjectCreate(l_name_0, OBJ_LABEL, 0, 0, 0);
      ObjectSet(l_name_0, OBJPROP_CORNER, corner);
      ObjectSet(l_name_0, OBJPROP_XDISTANCE, 10);
      ObjectSet(l_name_0, OBJPROP_YDISTANCE, 44);
   }
   ObjectSetText(l_name_0, "________
 

Attachments

Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
16,038
817
144
Odessa
www.earnforex.com
Oh, now I see. It is based on chart objects rather than on indicator buffers.

I am not sure if converting it to buffers would yield any useful result. It will switch to lines similar to MAs rather than horizontal lines.
 

hayseed

Master Trader
Jul 27, 2010
555
157
109
usa
not really clear on want your trying to do, so this might not apply.....

your lines are being created in the init() function, which is usually a one time shot..... if you move all code associated with their creation to a new function, say like void Draw() and call it in the start() function, the lines should readjust on each new daily bar......

objectdelete or objectdeleteall will also be required.....

and again, not sure of your full goal so the above might not help......h
 

hayseed

Master Trader
Jul 27, 2010
555
157
109
usa
language barriers

scroll the chart back

//----
hey enivid..... it's funny how words and concepts some times don't translate well across languages..... very often it will take me longer to figure out just what they are saying than it takes to code it.....

the word backtest had me thinkin he wanted to scroll forward using the strategy tester.... or to create an ea out of it capable of placing trades......

//----

to manually scroll backwards i most often use a slider 'object'....

to automatically scroll backwards in increments, i just use a timer.....

and of course the date functions or shift would allow for chosing a particular single day out of thousands.......

in the pictures below one has the current lines drawn, original code, and the other has lines from days earlier, modified code......

//----

haven't mentioned it before, but nice site you have here......h

//----

MQL4:
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
 
   ObjectsDeleteAll();
   Draw();
 
   //-----   for better control use offline chart and force incoming tick
   q = q+1;
 
   ObjectsDeleteAll();
   Draw();
//----
   return(0);
  }

//---

MQL4:
   double daiyPipCh=iOpen(Symbol(),PERIOD_D1,q)*dailyChAv/100;


//----
 

Attachments

Last edited by a moderator: