fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    Draw A candlestick

    Questions & Answers
    3
    4
    1157
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sharbati
      sharbati @miro1360 last edited by

      @miro1360 Hello, how can this code be executed? I am a beginner, please help

      1 Reply Last reply Reply Quote 0
      • U
        uchiha last edited by

        Hello

        I want to draw candlesticks which start and end at market session Opens (Sydney, Tokyo, London and New-york)

        For this I have started with drawing a rectangle, problem is no matter how I try the rectangle does not even draw.

        Sydney: The rectangle should be 00H to 03H (baseline/width), the height will change according to price, fill color will depend on the Open - Price relationship.

        Any pointers?

        1 Reply Last reply Reply Quote 0
        • M
          miro1360 last edited by

          try this way:

          //code inspired from "Ęčě Čăîđü Â. aka KimIV"
          //code inspired from "http://www.kimiv.ru"
          //this created by miro1360@azet.sk
          
          #property copyright ""
          #property link             "http://www.forexfactory.com/showthread.php?p=8844325"
          #property description      "idea from vasily"
          #property description      "coded by miro1360"
          #property description      "code inspired from KimIV"
          
          #property indicator_chart_window
          
          
          extern int    NumberOfDays = 100;    
              
          extern string PacificBegin    = "23:00";   
          extern string PacificEnd      = "23:00";   
          //extern color  PacificColor    = clrGoldenrod; 
          extern color  PacificColorBodyUp    = clrDodgerBlue;
          extern color  PacificColorBodyDn    = clrTomato;
          extern color  PacificColorWickUp    = clrAquamarine;
          extern color  PacificColorWickDn    = clrBisque;
          
          extern string AsiaBegin     = "01:00";   
          extern string AsiaEnd       = "09:00";   
          //extern color  AsiaColor     = clrTan;        
          extern color  AsiaColorBodyUp    = clrDodgerBlue;
          extern color  AsiaColorBodyDn    = clrTomato;
          extern color  AsiaColorWickUp   = clrAquamarine;
          extern color  AsiaColorWickDn    = clrBisque;
          
          extern string EuropeBegin     = "09:00";   
          extern string EuropeEnd       = "14:00";   
          //extern color  EuropeColor     = clrPaleGreen; 
          extern color  EuropeColorBodyUp    = clrDodgerBlue;
          extern color  EuropeColorBodyDn    = clrTomato;
          extern color  EuropeColorWickUp   = clrAquamarine;
          extern color  EuropeColorWickDn    = clrBisque;
          
          extern string AmericaBegin     = "14:00";   
          extern string AmericaEnd       = "23:00";   
          //extern color  AmericaColor     = clrLightSalmon; 
          extern color  AmericaColorBodyUp    = clrDodgerBlue;
          extern color  AmericaColorBodyDn    = clrTomato;
          extern color  AmericaColorWickUp   = clrAquamarine;
          extern color  AmericaColorWickDn    = clrBisque;
          
          
          //+------------------------------------------------------------------+
          //| Custom indicator initialization function                         |
          //+------------------------------------------------------------------+
          void init() {
            DeleteObjects();
            for (int i=0; i<NumberOfDays; i++) {
          //    CreateObjects("Pa"+i, PacificColor);
          //    CreateObjects("As"+i, AsiaColor);
          //    CreateObjects("Eu"+i, EuropeColor);
          //    CreateObjects("Am"+i, AmericaColor);
          
              CreateObjects("PaBody"+i, PacificColorBodyUp);
              CreateObjects("PaWickBull"+i, PacificColorWickUp);
              CreateObjects("PaWickBear"+i, PacificColorWickUp);
          
              CreateObjects("AsBody"+i, AsiaColorBodyUp);
              CreateObjects("AsWickBull"+i, AsiaColorWickUp);
              CreateObjects("AsWickBear"+i, AsiaColorWickUp);
              
              CreateObjects("EuBody"+i, EuropeColorBodyUp);
              CreateObjects("EuWickBull"+i, EuropeColorWickUp);
              CreateObjects("EuWickBear"+i, EuropeColorWickUp);
          
              CreateObjects("AmBody"+i, AmericaColorBodyUp);
              CreateObjects("AmWickBull"+i, AmericaColorWickUp);
              CreateObjects("AmWickBear"+i, AmericaColorWickUp);
              
            }
            Comment("");
          }
          
          //+------------------------------------------------------------------+
          //| Custor indicator deinitialization function                       |
          //+------------------------------------------------------------------+
          void deinit() {
            DeleteObjects();
            Comment("");
          }
          
          void CreateObjects(string no, color cl) {
            ObjectCreate(no, OBJ_RECTANGLE, 0, 0,0, 0,0);
            ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet(no, OBJPROP_COLOR, cl);
            ObjectSet(no, OBJPROP_BACK, True);
          }
          
          void DeleteObjects() {
            for (int i=0; i<NumberOfDays; i++) {
          //    ObjectDelete("Pa"+i);
          //    ObjectDelete("As"+i);
          //    ObjectDelete("Eu"+i);
          //    ObjectDelete("Am"+i);
          
              ObjectDelete("PaBody"+i);
              ObjectDelete("PaWickBull"+i);
              ObjectDelete("PaWickBear"+i);
             
              ObjectDelete("AsBody"+i);
              ObjectDelete("AsWickBull"+i);
              ObjectDelete("AsWickBear"+i);
          
              ObjectDelete("EuBody"+i);
              ObjectDelete("EuWickBull"+i);
              ObjectDelete("EuWickBear"+i);
              
              ObjectDelete("AmBody"+i);
              ObjectDelete("AmWickBull"+i);
              ObjectDelete("AmWickBear"+i);
            }
          }
          
          //+------------------------------------------------------------------+
          //| Custom indicator iteration function                              |
          //+------------------------------------------------------------------+
          void start() {
            datetime dt=CurTime();
          
            for (int i=0; i<NumberOfDays; i++) {
          //    DrawObjects(dt, "Pa"+i, PacificBegin, PacificEnd);
          //    DrawObjects(dt, "As"+i, AsiaBegin, AsiaEnd);
          //    DrawObjects(dt, "Eu"+i, EuropeBegin, EuropeEnd);
          //    DrawObjects(dt, "Am"+i, AmericaBegin, AmericaEnd);
          
              DrawObjectsBody(dt, "PaBody"+i, PacificBegin, PacificEnd, PacificColorBodyUp, PacificColorBodyDn);
              DrawObjectsWick(dt, "PaWickBull"+i, "PaWickBear"+1, PacificBegin, PacificEnd, PacificColorWickUp, PacificColorWickDn);
          
              DrawObjectsBody(dt, "AsBody"+i, AsiaBegin, AsiaEnd, AsiaColorBodyUp, AsiaColorBodyDn);
              DrawObjectsWick(dt, "AsWickBull"+i, "AsWickBear"+i, AsiaBegin, AsiaEnd, AsiaColorWickUp, AsiaColorWickDn);
              
              DrawObjectsBody(dt, "EuBody"+i, EuropeBegin, EuropeEnd, EuropeColorBodyUp, EuropeColorBodyDn);
              DrawObjectsWick(dt, "EuWickBull"+i, "EuWickBear"+i, EuropeBegin, EuropeEnd, EuropeColorWickUp, EuropeColorWickDn);
              
              DrawObjectsBody(dt, "AmBody"+i, AmericaBegin, AmericaEnd, AmericaColorBodyUp, AmericaColorBodyDn);
              DrawObjectsWick(dt, "AmWickBull"+i, "AmWickBear"+i, AmericaBegin, AmericaEnd, AmericaColorWickUp, AmericaColorWickDn);
          
              dt=decDateTradeDay(dt);
              while (TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
            }
          }
          
          void DrawObjectsBody(datetime dt, string no, string tb, string te, color bodyUpClr, color bodyDnClr) {
            datetime t1, t2;
            double   p1, p2, p11, p12;
            int      b1, b2;
          
            t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
            t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
            b1=iBarShift(NULL, 0, t1);
            b2=iBarShift(NULL, 0, t2);
            p1=Open&#91;b1&#93;;
            p2=Close&#91;b2&#93;;
            p11=Close&#91;b1&#93;;
            p12=Open&#91;b2&#93;;
            
            if (p1<p12) {
              ObjectSet(no, OBJPROP_TIME1, t1);
              ObjectSet(no, OBJPROP_PRICE1, p1);
              ObjectSet(no, OBJPROP_TIME2, t2);
              ObjectSet(no, OBJPROP_PRICE2, p12);
              ObjectSet(no, OBJPROP_COLOR, bodyUpClr);
            }
            else {
              ObjectSet(no, OBJPROP_TIME1, t1);
              ObjectSet(no, OBJPROP_PRICE1, p1);
              ObjectSet(no, OBJPROP_TIME2, t2);
              ObjectSet(no, OBJPROP_PRICE2, p12);
              ObjectSet(no, OBJPROP_COLOR, bodyDnClr);
            }
          }
          
          void DrawObjectsWick(datetime dt, string no, string no2, string tb, string te, color wickUpClr, color wickDnClr) {
            datetime t1, t2;
            double   p1, p2, p11, p12;
            double   wH1, wL1;
            int      b1, b2;
          
            t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
            t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
            b1=iBarShift(NULL, 0, t1);
            b2=iBarShift(NULL, 0, t2);
            p1=Open&#91;b1&#93;;
            p2=Close&#91;b2&#93;;
            p11=Close&#91;b1&#93;;
            p12=Open&#91;b2&#93;;
            wH1=High&#91;iHighest(NULL, 0, MODE_HIGH, b1-b2+1, b2)&#93;;
            wL1=Low&#91;iLowest(NULL, 0, MODE_LOW, b1-b2+1, b2)&#93;;
            
            if (p1<p12) {
              ObjectSet(no, OBJPROP_TIME1, t1);
              ObjectSet(no, OBJPROP_PRICE1, p12);
              ObjectSet(no, OBJPROP_TIME2, t2);
              ObjectSet(no, OBJPROP_PRICE2, wH1);
              ObjectSet(no, OBJPROP_COLOR, wickUpClr);
              
              ObjectSet(no2, OBJPROP_TIME1, t1);
              ObjectSet(no2, OBJPROP_PRICE1, p1);
              ObjectSet(no2, OBJPROP_TIME2, t2);
              ObjectSet(no2, OBJPROP_PRICE2, wL1);
              ObjectSet(no2, OBJPROP_COLOR, wickUpClr); 
            }
            
            else {
              ObjectSet(no, OBJPROP_TIME1, t1);
              ObjectSet(no, OBJPROP_PRICE1, p1);
              ObjectSet(no, OBJPROP_TIME2, t2);
              ObjectSet(no, OBJPROP_PRICE2, wH1);
              ObjectSet(no, OBJPROP_COLOR, wickDnClr);
          
              ObjectSet(no2, OBJPROP_TIME1, t1);
              ObjectSet(no2, OBJPROP_PRICE1, p12);
              ObjectSet(no2, OBJPROP_TIME2, t2);
              ObjectSet(no2, OBJPROP_PRICE2, wL1);
              ObjectSet(no2, OBJPROP_COLOR, wickDnClr);
            }
          }
          
          /*
          void DrawObjects(datetime dt, string no, string tb, string te) {
            datetime t1, t2;
            double   p1, p2;
            int      b1, b2;
          
            t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
            t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
            b1=iBarShift(NULL, 0, t1);
            b2=iBarShift(NULL, 0, t2);
            p1=High&#91;iHighest(NULL, 0, MODE_HIGH, b1-b2, b2)&#93;;
            p2=Low&#91;iLowest(NULL, 0, MODE_LOW , b1-b2, b2)&#93;;
            ObjectSet(no, OBJPROP_TIME1 , t1);
            ObjectSet(no, OBJPROP_PRICE1, p1);
            ObjectSet(no, OBJPROP_TIME2 , t2);
            ObjectSet(no, OBJPROP_PRICE2, p2);
          }
          */
          
          datetime decDateTradeDay (datetime dt) {
            int ty=TimeYear(dt);
            int tm=TimeMonth(dt);
            int td=TimeDay(dt);
            int th=TimeHour(dt);
            int ti=TimeMinute(dt);
          
            td--;
            if (td==0) {
              tm--;
              if (tm==0) {
                ty--;
                tm=12;
              }
              if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
              if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;
              if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
            }
            return(StrToTime(ty+"&#46;"+tm+"&#46;"+td+" "+th+"&#58;"+ti));
          }
          //+------------------------------------------------------------------+
          
          

          ......
          i-Sessions_Candles_1.01.mq4

          Between trading and gambling is a very small gap, be careful.

          sharbati 1 Reply Last reply Reply Quote 0
          • U
            uchiha last edited by

            Oh this is just wonderful.

            Could you modify it to draw the wicks as lines at the point where the highest and lowest price occurs (see picture) the Red lines

            Thanks a bunch

            ......
            lj.JPG

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post

            Online Users

            S
            O
            K
            M
            M
            C

            14
            Online

            146.7k
            Users

            22.4k
            Topics

            122.6k
            Posts

            Powered by NodeBB Forums | Contributors