CONVERSION INDICADOR MT4
Forums › ProRealTime foro Español › Soporte ProBuilder › CONVERSION INDICADOR MT4
- This topic has 1 reply, 2 voices, and was last updated 5 months ago by Iván.
-
-
06/16/2024 at 11:33 AM #233922
Solicito, si es posible, convertir el indicador de MT4 de formación automática de triángulos ascendentes y descendentes con una flecha respectiva como señal de compra y venta una vez formado el triángulo, adjunto código:
//==================================================================
// [MT4 123TRIANGLES] \¦/
//
//_____________________________o0o___(_)___o0o______________________
//
#property copyright “”
#property indicator_chart_window////////////////////////////////
#property indicator_buffers 4
input bool ShowSemafors = false,
ShowTriangles = true,
FillUp = false,
ShowMarks = true;extern bool AlertsMessageTr = false;
extern bool AlertsSoundTr = false;
extern string AlertsSoundTrSoundFile = “alert2.wav”;
extern bool AlertsEmailTr = false;extern bool AlertsMessage = false;
extern bool AlertsSound = false;
extern string AlertsSoundSoundFile = “alert2.wav”;
extern bool AlertsEmail = false;input double Period1 = 13,
Period3 = 36;
input int Width1 = 5,
Width3 = 3,
BarsCount = 987,
DATA1 = 0;input color BuyTriangle = clrDeepSkyBlue,
SellTriangle = clrDeepPink,
BuyMark = clrAqua,
SellMark = clrMagenta,
tColor = clrDimGray;
//button template start1; copy and paste
extern string button_note1 = “——————————“;
extern int btn_Subwindow = 0;
extern ENUM_BASE_CORNER btn_corner = CORNER_LEFT_UPPER;
extern string btn_text = “Triangle”;
extern string btn_Font = “Arial”;
extern int btn_FontSize = 10;
extern color btn_text_ON_color = clrWhite;
extern color btn_text_OFF_color = clrRed;
extern color btn_background_color = clrDimGray;
extern color btn_border_color = clrBlack;
extern int button_x = 80;
extern int button_y = 13;
extern int btn_Width = 60;
extern int btn_Height = 20;
extern string button_note2 = “——————————“;bool show_data = true;
bool recalc = true;
string indicatorFileName, IndicatorName, IndicatorObjPrefix, buttonId;
//button template end1; copy and pasteint Dev=1,Stp=1,SYM1=108,SYM3=108,Type,key,keyTr,DATA2; input string copy=”1″;
double Level1UP[],Level1DN[],Level3UP[],Level3DN[]; string symbol=Symbol();
//+——————————————————————————————————————+
//button template start2; copy and paste
string GenerateIndicatorName(const string target)
{
string name = target;
int try = 2;
while (WindowFind(name) != -1)
{
name = target + ” #” + IntegerToString(try++);
}
return name;
}
//+——————————————————————————————————————+
int OnInit()
{
IndicatorName = GenerateIndicatorName(btn_text);
IndicatorObjPrefix = “__” + IndicatorName + “__”;
IndicatorShortName(IndicatorName);
IndicatorDigits(Digits);double val;
if (GlobalVariableGet(IndicatorName + “_visibility”, val))
show_data = val != 0;ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, 1);
buttonId = IndicatorObjPrefix + “123Triangles”; //don’t forget to change name here
createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);
ObjectSetInteger(ChartID(), buttonId, OBJPROP_YDISTANCE, button_y);
ObjectSetInteger(ChartID(), buttonId, OBJPROP_XDISTANCE, button_x);// put init() here
init2();
return(INIT_SUCCEEDED);
}
//+——————————————————————————————————————+
int init2(){
int Buf=-1; key=0; keyTr=0; if(ShowSemafors)Type=DRAW_ARROW; else Type=DRAW_NONE;
Buf+=1;SetIndexBuffer(Buf,Level1UP);SetIndexStyle(Buf,Type,EMPTY,Width1,clrGray); SetIndexArrow(Buf,SYM1);
Buf+=1;SetIndexBuffer(Buf,Level1DN);SetIndexStyle(Buf,Type,EMPTY,Width1,clrGray); SetIndexArrow(Buf,SYM1);
Buf+=1;SetIndexBuffer(Buf,Level3UP);SetIndexStyle(Buf,Type,EMPTY,Width3,clrOrange);SetIndexArrow(Buf,SYM3);
Buf+=1;SetIndexBuffer(Buf,Level3DN);SetIndexStyle(Buf,Type,EMPTY,Width3,clrOrange);SetIndexArrow(Buf,SYM3);
if(DATA1==0)DATA2=10000; else DATA2=DATA1; return(0);
}
//+——————————————————————————————————————+
void OnDeinit(const int reason) {
ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
ChartCleaner();
}
//+——————————————————————+
//don’t change anything here
void createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
{
ObjectDelete (ChartID(),buttonID);
ObjectCreate (ChartID(),buttonID,OBJ_BUTTON,0,0,0);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);
ObjectSetString (ChartID(),buttonID,OBJPROP_FONT,font);
ObjectSetString (ChartID(),buttonID,OBJPROP_TEXT,buttonText);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,0);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_CORNER,btn_corner);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_HIDDEN,1);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_XDISTANCE,9999);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_YDISTANCE,9999);
}
//+——————————————————————+
void handleButtonClicks()
{
if (ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE))
{
ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false);
show_data = !show_data;
GlobalVariableSet(IndicatorName + “_visibility”, show_data ? 1.0 : 0.0);
recalc = true;
start();
}
}
//+——————————————————————————————————————+
void OnChartEvent(const int id, //don’t change anything here
const long &lparam,
const double &dparam,
const string &sparam)
{
handleButtonClicks();
}
//button template end2; copy and paste
//+——————————————————————————————————————+
int start()
{
handleButtonClicks();
recalc = false;if (show_data)
{
ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_ON_color);
init2();
start2();
}
else
{
ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_OFF_color);
ChartCleaner();}
return(0);
}
//+——————————————————————————————————————+
int start2(){
string AlertMessage;
if(Period1>0)CountZZ(Level1UP,Level1DN,Period1,Dev,Stp);
if(Period3>0)CountZZ(Level3UP,Level3DN,Period3,Dev,Stp);
//+——————————————————————————————————————+
//Alert1
if((AlertsMessage || AlertsEmail ||AlertsSound )&& key!=Time[0]){
AlertMessage=” “+DoubleToStr(Close[0],Digits);
if(Level3UP[0]!=0) doAlert(0,AlertsSoundSoundFile,AlertMessage +” going Up”);
if(Level3DN[0]!=0)doAlert(0,AlertsSoundSoundFile,AlertMessage + ” going Down”);
}key=Time[0];
if(!ShowTriangles) ChartCleaner(); if(ShowTriangles) Triangels(); return(0);}
//+——————————————————————————————————————+
double Triangels(){
string AlertMessage;
bool up; double OpenPrice,semafor3d,semafor3u,semafor1d,semafor1u,upper,lower,price1,price2,
price3,semafor3dn,semafor3up; int zz,lev1,time1,time2,time3; if(keyTr!=Time[0]){ChartCleaner();
double spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;for(zz=BarsCount;zz>=1;zz–){price1=0;price2=0;price3=0;
semafor3d=0; semafor3u=0; semafor3d=Level3UP[zz]; semafor3u=Level3DN[zz]; time1=Time[zz];
//+——————————————————————————————————————+
if(semafor3d>0){price1=semafor3d; up=false; OpenPrice=0; upper=0;
for(lev1=zz-1;lev1>=1;lev1–){
semafor3dn=Level3UP[lev1]; semafor3up=Level3DN[lev1];
if(semafor3up>0 || semafor3dn>0) break; if(!up){semafor1u=Level1DN[lev1]; if(semafor1u>0) upper=semafor1u;
if(upper>0&&upper>=semafor3d){price2=upper; time2=Time[lev1]; up=true;}} else {lower=Level1UP[lev1+1];
if(lower>0&&lower>=semafor3d){time3=Time[lev1+1]; price3=lower;}}
if(price1>0&&price2>0&&price3>0){
OpenPrice=10;
//Alert2
if(lev1==1 && (AlertsMessageTr || AlertsEmailTr || AlertsSoundTr)){
AlertMessage=” Buy!!! “+ DoubleToString(price2+2*2*Point+spread,Digits);
doAlert(0,AlertsSoundTrSoundFile,AlertMessage);
}break;
}
}
if(OpenPrice>0 && price2-price1<DATA2*Point){
DrawTriangle(copy+”123h”+zz,time1,price1,time2,price2,time3,price3,BuyTriangle);
DrawArrow(copy+”123b”+lev1,time3+Period()*60,price3-2*Point,BuyMark);}}
//+——————————————————————————————————————+
if(semafor3u>0){price1=semafor3u; up=false; OpenPrice=0; lower=0; upper=0;
for(lev1=zz-1;lev1>=1;lev1–){
semafor3dn=Level3UP[lev1]; semafor3up=Level3DN[lev1];
if(semafor3up>0 || semafor3dn>0) break; if(!up){semafor1d=Level1UP[lev1]; if(semafor1d>0) lower=semafor1d;
if(lower>0&&lower<=semafor3u){price2=lower; time2=Time[lev1]; up=true;}} else {upper=Level1DN[lev1+1];
if(upper>0&&upper<=semafor3u){time3=Time[lev1+1]; price3=upper;}}if(price1>0&&price2>0&&price3>0){OpenPrice=10;
//Alert3
if(lev1==1 && (AlertsMessageTr || AlertsEmailTr || AlertsSoundTr)){
AlertMessage=” Sell!!! “+ DoubleToString(price2-2*Point,Digits);
doAlert(0,AlertsSoundTrSoundFile,AlertMessage);
}
break;
}
}
if(OpenPrice>0 && price1-price2<DATA2*Point){
DrawTriangle(copy+”123s”+zz,time1,price1,time2,price2,time3,price3,SellTriangle);
DrawArrow(copy+”123_X”+lev1,time3+Period()*60,price3-2*Point,SellMark);}}} keyTr=Time[0];} return(0);}
//+——————————————————————————————————————+
void DrawArrow(string name,int time,double price,color ops_color){if(!ShowMarks) return;
ObjectCreate(name,OBJ_ARROW,0,time,price,0,0,0,0);
ObjectSet(name,OBJPROP_WIDTH,2);
ObjectSet(name,OBJPROP_COLOR,ops_color);
ObjectSet(name,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);}
//+——————————————————————————————————————+
void DrawTriangle(string name2,int time1,double price1,int time2,double price2,int time3,double price3,color ops_color){
ObjectCreate(name2,OBJ_TRIANGLE,0,time1,price1,time2,price2,time3,price3);
ObjectSet(name2,OBJPROP_WIDTH,3);
ObjectSet(name2,OBJPROP_BACK,FillUp);
ObjectSet(name2,OBJPROP_COLOR,ops_color);}
//+——————————————————————————————————————+
int CountZZ(double& ExtMapBuffer[],double& ExtMapBuffer2[],int ExtDepth,int ExtDeviation,int ExtBackstep){
int shift, back,lasthighpos,lastlowpos, limit; double val,res,curlow,curhigh,lasthigh,lastlow;
limit=Bars-ExtDepth; if(limit>BarsCount) limit=BarsCount; for(shift=limit; shift>=0; shift–){
val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
if(val==lastlow) val=00; else {lastlow=val; if((Low[shift]-val)>(ExtDeviation*Point)) val=00;
else {for(back=1; back<=ExtBackstep; back++){res=ExtMapBuffer[shift+back];
if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=00;}}} ExtMapBuffer[shift]=val;
//+——————————————————————————————————————+
val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];
if(val==lasthigh) val=00; else {lasthigh=val; if((val-High[shift])>(ExtDeviation*Point)) val=00;
else {for(back=1; back<=ExtBackstep; back++){res=ExtMapBuffer2[shift+back];
if((res!=0)&&(res<val))ExtMapBuffer2[shift+back]=00;}}} ExtMapBuffer2[shift]=val;}
lasthigh=-1; lasthighpos=-1; lastlow=-1; lastlowpos=-1; for(shift=limit;shift>=0;shift–){
curlow=ExtMapBuffer[shift]; curhigh=ExtMapBuffer2[shift]; if((curlow==0)&&(curhigh==0)) continue;
//+——————————————————————————————————————+
if(curhigh!=0){if(lasthigh>0){if(lasthigh<curhigh)ExtMapBuffer2[lasthighpos]=0;else ExtMapBuffer2[shift]=0;}
if(lasthigh<curhigh || lasthigh<0){lasthigh=curhigh; lasthighpos=shift;}lastlow=-1;}
if(curlow!=0){if(lastlow>0){if(lastlow>curlow)ExtMapBuffer[lastlowpos]=0; else ExtMapBuffer[shift]=0;}
if((curlow<lastlow)||(lastlow<0)){lastlow=curlow; lastlowpos=shift;} lasthigh=-1;}}
for(shift=limit;shift>=0;shift–){if(shift>=limit)ExtMapBuffer[shift]=00;
else {res=ExtMapBuffer2[shift]; if(res!=00)ExtMapBuffer2[shift]=res;}} return(0);}
//+——————————————————————————————————————+
void ChartCleaner() {for(int a=0;a<Bars;a++){ObjectDelete(copy+”123h”+a);ObjectDelete(copy+”123b”+a);
ObjectDelete(copy+”123s”+a);ObjectDelete(copy+”123_X”+a); GetLastError();}}
//+——————————————————————————————————————+
string sTfTable[] = {“M1″,”M5″,”M15″,”M30″,”H1″,”H4″,”D1″,”W1″,”MN”};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i–)
if (tf==iTfTable[i]) return(sTfTable[i]);
return(“”);
}
//+——————————————————————————————————————+
void doAlert(int forBar,string sounFile, string doWhat)
{
static string previousAlert=”nothing”;
static datetime previousTime;
string message;if (previousAlert != doWhat || previousTime != Time[forBar]) {
previousAlert = doWhat;
previousTime = Time[forBar];//
//
//
//
//message = timeFrameToString(Period())+” “+Symbol()+” at “+TimeToStr(TimeLocal(),TIME_SECONDS)+doWhat;
if (AlertsMessage) Alert(message);
if (AlertsEmail) SendMail(StringConcatenate(Symbol(),”!!!-MT4 123TRIANGLES v1.2 “),message);
if (AlertsSound) PlaySound(sounFile);
}
}
//+——————————————————————————————————————+A ver si Iván el moderador lo puede traducir.
Muchas gracias.06/17/2024 at 3:44 PM #234009MT4 no es mi fuerte… Estaría bien que compartieras alguna captura de pantalla para hacerme a la idea de cómo es el indicador…
Bueno, le he pedido a ChatGpt que me explique lo que hace el indicador y a partir de ahí he programado yo este. Espero que haga lo que buscas.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114Period3=36lowestlow3=lowest[Period3](low)highesthigh3=highest[Period3](high)if low=lowestlow3 then$level3DN[t3+1]=Low$level3DNx[t3+1]=barindext3=t3+1endifif high=highesthigh3 then$level3UP[z3+1]=high$level3UPx[z3+1]=barindexz3=z3+1endifPeriod1=13lowestlow1=lowest[Period1](low)highesthigh1=highest[Period1](high)if low=lowestlow1 then$level1DN[t1+1]=Low$level1DNx[t1+1]=barindext1=t1+1endifif high=highesthigh1 then$level1UP[z1+1]=high$level1UPx[z1+1]=barindexz1=z1+1endif//-------------------------------------------------//if islastbarupdate then//----triangulo ascendentefor i=t3 downto 0 doxx1=0yy1=0xx2=0yy2=0xx3=0yy3=0semafor1d=0semafor1u=0for j=t1 downto 0 doif $level3DNx[i]<$level1DNx[j] and $level3DNx[i]>=$level1DNx[max(0,j-1)] and $level3DN[i] < $level1DN[j] thensemafor1d=1xx2=$level1DNx[j]yy2=$level1DN[j]breakelsesemafor1d=0endifnextfor k=t1 downto 0 doif $level3DNx[i]<$level1UPx[k] and $level3DNx[i]>=$level1UPx[max(0,k-1)] and $level3UP[i]<$level1UP[k] thensemafor1u=1xx1=$level3DNx[i]yy1=$level3DN[i]xx3=$level1UPx[k]yy3=$level1UP[k]breakelsesemafor1u=0endifnextif semafor1d and semafor1u and xx3<xx2 and yy3>yy2 and yy1<>0 thendrawtriangle(xx1,yy1,xx2,yy2,xx3,yy3)coloured("purple")style(line,2)drawpoint(xx2,yy2,2)coloured("black")drawpoint(xx3,yy3,2)coloured("red")drawpoint(xx1,yy1,3)coloured("green")drawsegment(xx3,yy3,xx3+abs(xx2-xx3)+5,yy3)coloured("red")style(dottedline)endifnext//----triangulo descendentefor i=z3 downto 0 dox1=0y1=0x2=0y2=0x3=0y3=0semafor1d=0semafor1u=0for j=z1 downto 0 doif $level3UPx[i]<$level1UPx[j] and $level3UPx[i]>=$level1UPx[max(0,j-1)] and $level3UP[i]> $level1UP[j] thensemafor1d=1x2=$level1UPx[j]y2=$level1UP[j]breakelsesemafor1d=0endifnextfor k=t1 downto 0 doif $level3UPx[i]<$level1DNx[k] and $level3UPx[i]>=$level1DNx[max(0,k-1)] and $level3UP[i]>$level1DN[k] thensemafor1u=1x1=$level3UPx[i]y1=$level3UP[i]x3=$level1DNx[k]y3=$level1DN[k]breakelsesemafor1u=0endifnextif semafor1d and semafor1u and x3<x2 and y3 < y2 and y1<>0 thendrawtriangle(x1,y1,x2,y2,x3,y3)coloured("blue")style(line,2)drawpoint(x2,y2,2)coloured("black")drawpoint(x3,y3,2)coloured("red")drawpoint(x1,y1,3)coloured("blue")drawsegment(x3,y3,x3+abs(x2-x3)+5,y3)coloured("blue")style(dottedline)endifnextendifreturn -
AuthorPosts
Find exclusive trading pro-tools on