Tâche terminée
Temps d'exécution 7 minutes
Commentaires du client
Very professional, immediately he solved my problem !! Recommended!!!!
Commentaires de l'employé
Great Customer.
Spécifications
Hi guys, I need your help. I wrote this code, which calculates the distance between points of a given number of candles. On the chart you will see a label that can be moved and gives the number of points away. I do not quite do update this value. Can you help me? I need mq4.
Thanks for everything, Massimo.
//--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 0 #property indicator_label1 "Buy" #property indicator_type2 DRAW_ARROW #property indicator_width2 1 #property indicator_color2 0 #property indicator_label2 "Buy" //--- indicator buffers double Buffer1[]; double Buffer2[]; extern int Numero_Candele=12; bool input Linea_SupRes=true; double Somma; double myPoint; //initialized in OnInit //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void myAlert(string type,string message) { if(type=="print") Print(message); else if(type=="error") { Print(type+" | Sup_ResMax @ "+Symbol()+","+Period()+" | "+message); } else if(type=="order") { } else if(type=="modify") { } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void DrawLine(string objname,double price,int count,int start_index) //creates or modifies existing object if necessary { if((price<0) && ObjectFind(objname)>=0) { ObjectDelete(objname); } else if(ObjectFind(objname)>=0 && ObjectType(objname)==OBJ_TREND) { ObjectSet(objname,OBJPROP_TIME1,Time[start_index]); ObjectSet(objname,OBJPROP_PRICE1,price); ObjectSet(objname,OBJPROP_TIME2,Time[start_index+count-1]); ObjectSet(objname,OBJPROP_PRICE2,price); } else { ObjectCreate(objname,OBJ_TREND,0,Time[start_index],price,Time[start_index+count-1],price); ObjectSet(objname,OBJPROP_RAY,false); ObjectSet(objname,OBJPROP_COLOR,clrYellow); ObjectSet(objname,OBJPROP_STYLE,STYLE_SOLID); ObjectSet(objname,OBJPROP_WIDTH,1); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double Support(int time_interval,bool fixed_tod,int hh,int mm,bool draw,int shift) { int start_index=shift; int count=time_interval/60/Period(); if(fixed_tod) { datetime start_time; if(shift==0) start_time=TimeCurrent(); else start_time=Time[shift-1]; datetime dt=StringToTime(StringConcatenate(TimeToString(start_time,TIME_DATE)," ",hh,":",mm)); //closest time hh:mm if(dt>start_time) dt-=86400; //go 24 hours back int dt_index = iBarShift(NULL, 0, dt, true); datetime dt2 = dt; while(dt_index<0 && dt>Time[Bars-1-count]) //bar not found => look a few days back { dt-=86400; //go 24 hours back dt_index=iBarShift(NULL,0,dt,true); } if(dt_index<0) //still not found => find nearest bar dt_index=iBarShift(NULL,0,dt2,false); start_index=dt_index+1; //bar after S/R opens at dt } double ret=Low[iLowest(NULL,0,MODE_LOW,count,start_index)]; if(Linea_SupRes) DrawLine("Support",ret,count,start_index); return(ret); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double Resistance(int time_interval,bool fixed_tod,int hh,int mm,bool draw,int shift) { int start_index=shift; int count=time_interval/60/Period(); if(fixed_tod) { datetime start_time; if(shift==0) start_time=TimeCurrent(); else start_time=Time[shift-1]; datetime dt=StringToTime(StringConcatenate(TimeToString(start_time,TIME_DATE)," ",hh,":",mm)); //closest time hh:mm if(dt>start_time) dt-=86400; //go 24 hours back int dt_index = iBarShift(NULL, 0, dt, true); datetime dt2 = dt; while(dt_index<0 && dt>Time[Bars-1-count]) //bar not found => look a few days back { dt-=86400; //go 24 hours back dt_index=iBarShift(NULL,0,dt,true); } if(dt_index<0) //still not found => find nearest bar dt_index=iBarShift(NULL,0,dt2,false); start_index=dt_index+1; //bar after S/R opens at dt } double ret=High[iHighest(NULL,0,MODE_HIGH,count,start_index)]; if(Linea_SupRes) DrawLine("Resistance",ret,count,start_index); return(ret); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { int limit=rates_total-prev_calculated; //--- counting from 0 to rates_total ArraySetAsSeries(Buffer1,true); ArraySetAsSeries(Buffer2,true); //--- initial zero if(prev_calculated<1) { ArrayInitialize(Buffer1,0); ArrayInitialize(Buffer2,0); } else limit++; //--- main loop for(int i=limit-1; i>=0; i--) { if(i>=MathMin(5000-1,rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation Somma=(Resistance(Numero_Candele*PeriodSeconds(),false,00,00,true,i)-Support(Numero_Candele*PeriodSeconds(),false,00,00,true,i))*100000; //Indicator Buffer 1 if(Close[i]>Support(Numero_Candele*PeriodSeconds(),false,00,00,true,i) //Candlestick Close > Support ) { Buffer1[i]=0; //Set indicator value at Candlestick Low } //Indicator Buffer 2 if(Close[i]<Resistance(Numero_Candele*PeriodSeconds(),false,00,00,true,i) //Candlestick Close < Resistance ) { Buffer2[i]=0; //Set indicator value at Candlestick Low } } return(rates_total); } //+------------------------------------------------------------------+ //|Inizio costruzione LABEL | //+------------------------------------------------------------------+ #property script_show_inputs //--- input parameters of the script string InpName="Label"; // Label name int InpX=150; // X-axis distance int InpY=100; // Y-axis distance string InpFont="Arial"; input string Impostazione_label=""; // Font input int ImpFontSize=10; // Font size input color ImpColore=clrYellow; // Color double InpAngle=0.0; // Slope angle in degrees ENUM_ANCHOR_POINT InpAnchor=ANCHOR_CENTER; // Anchor type input bool Imp_Avanti_Dietro=false; // Background object input bool ImpSelezione=true; // Highlight to move bool InpHidden=true; // Hidden in the object list long InpZOrder=0; // Priority for mouse click //+------------------------------------------------------------------+ //| Create a text label | //+------------------------------------------------------------------+ bool LabelCreate(const long chart_ID=0, // chart's ID const string name="Label", // label name const int sub_window=0, // subwindow index const int x=0, // X coordinate const int y=0, // Y coordinate const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring const string text="Label", // text const string font="Arial", // font const int font_size=10, // font size const color clr=clrRed, // color const double angle=0.0, // text slope const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type const bool back=false, // in the background const bool selection=false, // highlight to move const bool hidden=true, // hidden in the object list const long z_order=0) // priority for mouse click { //--- reset the error value ResetLastError(); //--- create a text label if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0)) { Print(__FUNCTION__, ": failed to create text label! Error code = ",GetLastError()); return(false); } //--- set label coordinates ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); //--- set the text ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); //--- set text font ObjectSetString(chart_ID,name,OBJPROP_FONT,font); //--- set font size ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); //--- set the slope angle of the text ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); //--- set anchor type ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); //--- set color ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mode of moving the label by mouse ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- successful execution return(true); } //+------------------------------------------------------------------+ //| Move the text label | //+------------------------------------------------------------------+ bool LabelMove(const long chart_ID=0, // chart's ID const string name="Label", // label name const int x=0, // X coordinate const int y=0 ) // Y coordinate { //--- reset the error value ResetLastError(); //--- move the text label if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x)) { Print(__FUNCTION__, ": failed to move X coordinate of the label! Error code = ",GetLastError()); return(false); } if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y)) { Print(__FUNCTION__, ": failed to move Y coordinate of the label! Error code = ",GetLastError()); return(false); } //--- successful execution return(true); } //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { double Distanza_Canale=(Resistance(Numero_Candele*PeriodSeconds(),false,00,00,true,0)-Support(Numero_Candele*PeriodSeconds(),false,00,00,true,0))*100000; //--- store the label's coordinates in the local variables int x=InpX; int y=InpY; //--- chart window size long x_distance; long y_distance; //--- set window size if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance)) { Print("Failed to get the chart width! Error code = ",GetLastError()); return; } if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance)) { Print("Failed to get the chart height! Error code = ",GetLastError()); return; } //--- check correctness of the input parameters if(InpX<0 || InpX>x_distance-1 || InpY<0 || InpY>y_distance-1) { Print("Error! Incorrect values of input parameters!"); return; } //--- prepare initial text for the label string text; text="Larghezza canale= "+Distanza_Canale+" decimi"; //--- create a text label on the chart if(!LabelCreate(0,InpName,0,InpX,InpY,CORNER_LEFT_UPPER,text,InpFont,ImpFontSize, ImpColore,InpAngle,InpAnchor,Imp_Avanti_Dietro,ImpSelezione,InpHidden,InpZOrder)) { return; } //--- redraw the chart ChartRedraw(); } //+------------------------------------------------------------------+ int deinit() { ObjectsDeleteAll(); Comment(""); // Cancella tutti gli objects creati return(0); } //+------------------------------------------------------------------+
Répondu
1
Évaluation
Projets
205
41%
Arbitrage
17
29%
/
71%
En retard
45
22%
Gratuit
Informations sur le projet
Budget
10 - 30 USD
Délais
de 2 à 5 jour(s)