CONVERSION INDICADOR MT4

Forums ProRealTime foro Español Soporte ProBuilder CONVERSION INDICADOR MT4

Viewing 2 posts - 1 through 2 (of 2 total)
  • #233922
    Fr7

    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 paste

    int 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.

    #234009

    MT4 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.

     

Viewing 2 posts - 1 through 2 (of 2 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login