kindly help, how to add buy or sell text on mt5 indicator when stochastic cross each other,
unless you are going show your coded attempt how can anyone help you
alternatively use the Frelance service
unless you are going show your coded attempt how can anyone help you
alternatively use the Frelance service
//+------------------------------------------------------------------+ //| Indicator: stock-arrow.mq5 | //+------------------------------------------------------------------+ #property copyright " stock-arrow " #property version "1.00" #property description "" //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 5 #property indicator_color1 0xFFAA00 #property indicator_label1 "Buy" #property indicator_type2 DRAW_ARROW #property indicator_width2 5 #property indicator_color2 0x0000FF #property indicator_label2 "Sell" //--- indicator buffers double Buffer1[]; double Buffer2[]; datetime time_alert; //used when sending alert bool Send_Email = false; bool Audible_Alerts = false; bool Push_Notifications = false; double myPoint; //initialized in OnInit int Stochastic_handle; double Stochastic_Main[]; double Stochastic_Signal[]; double Low[]; double High[]; void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } else if(type == "order") { } else if(type == "modify") { } else if(type == "indicator") { Print(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); if(Audible_Alerts) Alert(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); if(Send_Email) SendMail("stock-arrow", type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); if(Push_Notifications) SendNotification(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, Buffer1); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(0, PLOT_ARROW, 233); SetIndexBuffer(1, Buffer2); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(1, PLOT_ARROW, 234); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } Stochastic_handle = iStochastic(NULL, PERIOD_CURRENT, 14, 3, 3, MODE_SMA, STO_LOWHIGH); if(Stochastic_handle < 0) { Print("The creation of iStochastic has failed: Stochastic_handle=", INVALID_HANDLE); Print("Runtime error = ", GetLastError()); return(INIT_FAILED); } 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, EMPTY_VALUE); ArrayInitialize(Buffer2, EMPTY_VALUE); } else limit++; datetime Time[]; if(BarsCalculated(Stochastic_handle) <= 0) return(0); if(CopyBuffer(Stochastic_handle, MAIN_LINE, 0, rates_total, Stochastic_Main) <= 0) return(rates_total); ArraySetAsSeries(Stochastic_Main, true); if(BarsCalculated(Stochastic_handle) <= 0) return(0); if(CopyBuffer(Stochastic_handle, SIGNAL_LINE, 0, rates_total, Stochastic_Signal) <= 0) return(rates_total); ArraySetAsSeries(Stochastic_Signal, true); if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total); ArraySetAsSeries(Low, true); if(CopyHigh(Symbol(), PERIOD_CURRENT, 0, rates_total, High) <= 0) return(rates_total); ArraySetAsSeries(High, true); if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total); ArraySetAsSeries(Time, true); //--- 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 //Indicator Buffer 1 if(Stochastic_Main[i] > Stochastic_Signal[i] && Stochastic_Main[i+1] < Stochastic_Signal[i+1] //Stochastic Oscillator crosses above Stochastic Oscillator ) { Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar } else { Buffer1[i] = EMPTY_VALUE; } //Indicator Buffer 2 if(Stochastic_Main[i] < Stochastic_Signal[i] && Stochastic_Main[i+1] > Stochastic_Signal[i+1] //Stochastic Oscillator crosses below Stochastic Oscillator ) { Buffer2[i] = High[i]; //Set indicator value at Candlestick High if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar } else { Buffer2[i] = EMPTY_VALUE; } } return(rates_total); } //+------------------------------------------------------------------+
An indicator - that is what you have - cannot(!) trade, only EAs can trade.
So you have to create an EA that loads your indicator with iCustom() and trades whenever a signal appears.
In the CodeBase are quite a lot examples that are trading based on signals of one or more indicators.
An indicator - that is what you have - cannot(!) trade, only EAs can trade.
So you have to create an EA that loads your indicator with iCustom() and trades whenever a signal appears.
In the CodeBase are quite a lot examples that are trading based on signals of one or more indicators.
add these somewhere in your code . i snatched them from an mt4 project but they should work
//a text void create_text(string name,string text,double price,datetime time, ENUM_ANCHOR_POINT anchor,int fontsize,color col, bool selectable,bool back){ ObjectCreate(ChartID(),name,OBJ_TEXT,0,time,price); ObjectSetInteger(ChartID(),name,OBJPROP_COLOR,col); ObjectSetInteger(ChartID(),name,OBJPROP_FONTSIZE,fontsize); ObjectSetInteger(ChartID(),name,OBJPROP_ANCHOR,anchor); ObjectSetString(ChartID(),name,OBJPROP_TEXT,text); ObjectSetInteger(ChartID(),name,OBJPROP_SELECTABLE,selectable); ObjectSetInteger(ChartID(),name,OBJPROP_BACK,back); } void update_text(string name,string text,double price,datetime time){ ObjectSetInteger(ChartID(),name,OBJPROP_TIME,time); ObjectSetDouble(ChartID(),name,OBJPROP_PRICE,price); ObjectSetString(ChartID(),name,OBJPROP_TEXT,text); }
You will need an object tag to be able to clear the chart of all objects so above OnInit add :
string SystemTag="MySignalo_";
and in OnInit , at the top add :
ObjectsDeleteAll(ChartID(),SystemTag);
now all the previous objects -from previous runs have been ventilated - but , you need to keep count of your objects otherwise they will all have the same name and nothing will be created
so , above Oninit again , below SystemTag add :
int totalObjects=0;
and inside OnInit add :
totalObjects=0;
Now you have the foundation in .
You consider , where is the arrow appearing ?
When you find it you do the following :
- Increase the count of your objects , right ?
- Create a name for your new object , right ?
- Create a text for your new object , right ?
- and call the text function .
So for a the buy it would look like this :
//increase objects totalObjects++; //create name for text object string nameo=SystemTag+IntegerToString(totalObjects);//right ? your system tag and the textualizatiation of the object counter //the text of your object string texto="<< New Buy Signal"; //the call to the function create_text(nameo,texto,Low[i],Time[i],ANCHOR_LEFT,12,clrRoyalBlue,false,false); //and the redrawing of the chart ChartRedraw();
For this i will assume you have wrapped the Low[i] High[i] Time[i] and they return something otherwise , if your code is still in the copy from mt4 stage let us know.
Cheers :)
add these somewhere in your code . i snatched them from an mt4 project but they should work
You will need an object tag to be able to clear the chart of all objects so above OnInit add :
and in OnInit , at the top add :
now all the previous objects -from previous runs have been ventilated - but , you need to keep count of your objects otherwise they will all have the same name and nothing will be created
so , above Oninit again , below SystemTag add :
and inside OnInit add :
Now you have the foundation in .
You consider , where is the arrow appearing ?
When you find it you do the following :
- Increase the count of your objects , right ?
- Create a name for your new object , right ?
- Create a text for your new object , right ?
- and call the text function .
So for a the buy it would look like this :
For this i will assume you have wrapped the Low[i] High[i] Time[i] and they return something otherwise , if your code is still in the copy from mt4 stage let us know.
Cheers :)
bro iam new on coding , please add necessary code in my project which i submit above then put it here
With pleasure .
Think about it a bit though ,as a coder while i edit it , where would the text entry code be logically for the buy ? Open the chart and look at the signals if it helps :)
With pleasure .
Think about it a bit though ,as a coder while i edit it , where would the text entry code be logically for the buy ? Open the chart and look at the signals if it helps :)
it will be very helpful for me if you solve my problem, make sure iam new in this sector, money doesn't matter, may god help you bro, if you have enough time please solve my problem , i will pray for you and your success.
Oh
Here you go buddy . Happy sales , thanks for the blessings . ☕ ☕
//+------------------------------------------------------------------+ //| Indicator: stock-arrow.mq5 | //+------------------------------------------------------------------+ #property copyright "2052 , William was right Ltd" #property version "1.00" #property description "" //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 5 #property indicator_color1 0xFFAA00 #property indicator_label1 "Buy" #property indicator_type2 DRAW_ARROW #property indicator_width2 5 #property indicator_color2 0x0000FF #property indicator_label2 "Sell" //--- indicator buffers double Buffer1[]; double Buffer2[]; datetime time_alert; //used when sending alert bool Send_Email = false; bool Audible_Alerts = false; bool Push_Notifications = false; double myPoint; //initialized in OnInit int Stochastic_handle; double Stochastic_Main[]; double Stochastic_Signal[]; double Low[]; double High[]; void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } else if(type == "order") { } else if(type == "modify") { } else if(type == "indicator") { Print(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); if(Audible_Alerts) Alert(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); if(Send_Email) SendMail("stock-arrow", type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); if(Push_Notifications) SendNotification(type+" | stock-arrow @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ string SystemTag="MySignalo_"; int totalObjects=0; int OnInit() { ObjectsDeleteAll(ChartID(),SystemTag); totalObjects=0; SetIndexBuffer(0, Buffer1); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(0, PLOT_ARROW, 233); SetIndexBuffer(1, Buffer2); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(1, PLOT_ARROW, 234); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } Stochastic_handle = iStochastic(NULL, PERIOD_CURRENT, 14, 3, 3, MODE_SMA, STO_LOWHIGH); if(Stochastic_handle < 0) { Print("The creation of iStochastic has failed: Stochastic_handle=", INVALID_HANDLE); Print("Runtime error = ", GetLastError()); return(INIT_FAILED); } 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, EMPTY_VALUE); ArrayInitialize(Buffer2, EMPTY_VALUE); } else limit++; datetime Time[]; if(BarsCalculated(Stochastic_handle) <= 0) return(0); if(CopyBuffer(Stochastic_handle, MAIN_LINE, 0, rates_total, Stochastic_Main) <= 0) return(rates_total); ArraySetAsSeries(Stochastic_Main, true); if(BarsCalculated(Stochastic_handle) <= 0) return(0); if(CopyBuffer(Stochastic_handle, SIGNAL_LINE, 0, rates_total, Stochastic_Signal) <= 0) return(rates_total); ArraySetAsSeries(Stochastic_Signal, true); if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total); ArraySetAsSeries(Low, true); if(CopyHigh(Symbol(), PERIOD_CURRENT, 0, rates_total, High) <= 0) return(rates_total); ArraySetAsSeries(High, true); if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total); ArraySetAsSeries(Time, true); //--- 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 //Indicator Buffer 1 if(Stochastic_Main[i] > Stochastic_Signal[i] && Stochastic_Main[i+1] < Stochastic_Signal[i+1] //Stochastic Oscillator crosses above Stochastic Oscillator ) { Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low //>> it was here bro , the low gave you no hints ? xD xD //increase objects totalObjects++; //create name for text object string nameo=SystemTag+IntegerToString(totalObjects);//right ? your system tag and the textualizatiation of the object counter //the text of your object string texto="<< New Buy Signal"; //the call to the function create_text(nameo,texto,Low[i],Time[i],ANCHOR_LEFT,12,clrRoyalBlue,false,false); //and the redrawing of the chart ChartRedraw(); if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar } else { Buffer1[i] = EMPTY_VALUE; } //Indicator Buffer 2 if(Stochastic_Main[i] < Stochastic_Signal[i] && Stochastic_Main[i+1] > Stochastic_Signal[i+1] //Stochastic Oscillator crosses below Stochastic Oscillator ) { Buffer2[i] = High[i]; //Set indicator value at Candlestick High //increase objects totalObjects++; //create name for text object string nameo=SystemTag+IntegerToString(totalObjects);//right ? your system tag and the textualizatiation of the object counter //the text of your object string texto="<< New Sell Signal"; //the call to the function create_text(nameo,texto,High[i],Time[i],ANCHOR_LEFT,12,clrRoyalBlue,false,false); //and the redrawing of the chart ChartRedraw(); if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar } else { Buffer2[i] = EMPTY_VALUE; } } return(rates_total); } //+------------------------------------------------------------------+ //a text void create_text(string name,string text,double price,datetime time, ENUM_ANCHOR_POINT anchor,int fontsize,color col, bool selectable,bool back){ ObjectCreate(ChartID(),name,OBJ_TEXT,0,time,price); ObjectSetInteger(ChartID(),name,OBJPROP_COLOR,col); ObjectSetInteger(ChartID(),name,OBJPROP_FONTSIZE,fontsize); ObjectSetInteger(ChartID(),name,OBJPROP_ANCHOR,anchor); ObjectSetString(ChartID(),name,OBJPROP_TEXT,text); ObjectSetInteger(ChartID(),name,OBJPROP_SELECTABLE,selectable); ObjectSetInteger(ChartID(),name,OBJPROP_BACK,back); } void update_text(string name,string text,double price,datetime time){ ObjectSetInteger(ChartID(),name,OBJPROP_TIME,time); ObjectSetDouble(ChartID(),name,OBJPROP_PRICE,price); ObjectSetString(ChartID(),name,OBJPROP_TEXT,text); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use