day fibo

 
/*+------------------------------------------------------------------+
 |                                                        1DayFibo   |
 |                                                  Copyright © 2011 |
 |                                              basisforex@gmail.com |
 +-------------------------------------------------------------------*/
#property copyright "Copyright © 2011, basisforex@gmail.com"
#property link      "basisforex@gmail.com"
//----------------------------------------
#property  indicator_chart_window
//---
extern color UpperFiboColor = Aqua;
extern color LowerFiboColor = Aqua;
//---
double HiPrice, LoPrice, CloPrice, Range;
datetime StartTime;
//+------------------------------------------------------------------+
int init()
 {
   return(0);
 }
//+------------------------------------------------------------------+
int deinit()
 {
   ObjectDelete("FiboUp");
   ObjectDelete("FiboDn");
   return(0);
 }
//+------------------------------------------------------------------+
int DrawFibo()
 {
        if(ObjectFind("FiboUp") == -1) ObjectCreate("FiboUp",OBJ_FIBO,0,StartTime,CloPrice+Range,StartTime,CloPrice);
        else
         {
                ObjectSet("FiboUp",OBJPROP_TIME2, StartTime);
                ObjectSet("FiboUp",OBJPROP_TIME1, StartTime);
                ObjectSet("FiboUp",OBJPROP_PRICE1,CloPrice + Range);
                ObjectSet("FiboUp",OBJPROP_PRICE2,CloPrice);
         }
   ObjectSet("FiboUp",OBJPROP_LEVELCOLOR,UpperFiboColor);
   ObjectSet("FiboUp",OBJPROP_FIBOLEVELS,12);
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+0, 0.000);     ObjectSetFiboDescription("FiboUp",0, "(0.0%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+1, 0.236);     ObjectSetFiboDescription("FiboUp",1, "(23.6%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+2, 0.382);     ObjectSetFiboDescription("FiboUp",2, "(38.2%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+3, 0.500);     ObjectSetFiboDescription("FiboUp",3, "(50.0%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+4, 0.618);     ObjectSetFiboDescription("FiboUp",4, "(61.8%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+5, 0.820);     ObjectSetFiboDescription("FiboUp",5, "(82.0%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+6, 1.000);     ObjectSetFiboDescription("FiboUp",6, "(100.0%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+7, 1.382);     ObjectSetFiboDescription("FiboUp",7, "(138.2%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+8, 1.618);     ObjectSetFiboDescription("FiboUp",8, "(161.8%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+9, 2.236);     ObjectSetFiboDescription("FiboUp",9, "(223.6%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+10,3.000);     ObjectSetFiboDescription("FiboUp",10,"(300.0%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+11,5.000);     ObjectSetFiboDescription("FiboUp",11,"(500.0%) -  %$"); 
   ObjectSet("FiboUp",OBJPROP_RAY,true);
   ObjectSet("FiboUp",OBJPROP_BACK,true);

        if(ObjectFind("FiboDn") == -1) ObjectCreate("FiboDn",OBJ_FIBO,0,StartTime,CloPrice-Range,StartTime,CloPrice);
        else
         {
                ObjectSet("FiboDn",OBJPROP_TIME2, StartTime);
                ObjectSet("FiboDn",OBJPROP_TIME1, StartTime);
                ObjectSet("FiboDn",OBJPROP_PRICE1,CloPrice - Range);
                ObjectSet("FiboDn",OBJPROP_PRICE2,CloPrice);
         }
   ObjectSet("FiboDn",OBJPROP_LEVELCOLOR,LowerFiboColor); 
   ObjectSet("FiboDn",OBJPROP_FIBOLEVELS,12);
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+0, 0.000);     ObjectSetFiboDescription("FiboDn",0, "(0.0%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+1, 0.236);     ObjectSetFiboDescription("FiboDn",1, "(-23.6%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+2, 0.382);     ObjectSetFiboDescription("FiboDn",2, "(-38.2%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+3, 0.500);     ObjectSetFiboDescription("FiboDn",3, "(-50.0%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+4, 0.618);     ObjectSetFiboDescription("FiboDn",4, "(-61.8%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+5, 0.820);     ObjectSetFiboDescription("FiboDn",5, "(-82.0%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+6, 1.000);     ObjectSetFiboDescription("FiboDn",6, "(-100.0%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+7, 1.382);     ObjectSetFiboDescription("FiboDn",7, "(-138.2%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+8, 1.618);     ObjectSetFiboDescription("FiboDn",8, "(-161.8%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+9, 2.236);     ObjectSetFiboDescription("FiboDn",9, "(-223.6%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+10,3.000);     ObjectSetFiboDescription("FiboDn",10,"(-300.0%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+11,5.000);     ObjectSetFiboDescription("FiboDn",11,"(-500.0%) -  %$"); 
   ObjectSet("FiboDn",OBJPROP_RAY,true);
   ObjectSet("FiboDn",OBJPROP_BACK,true);
 }
//+------------------------------------------------------------------+
int start()
 {
        int shift       = iBarShift(NULL,PERIOD_D1,Time[0]) + 1;        // yesterday
        HiPrice         = iHigh(NULL,PERIOD_D1,shift);
        LoPrice         = iLow(NULL,PERIOD_D1,shift);
        CloPrice    = iClose(NULL,PERIOD_D1,shift);
        StartTime       = iTime(NULL,PERIOD_D1,shift - 1);

        if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
        {//Add fridays high and low
                HiPrice = MathMax(HiPrice,iHigh(NULL,PERIOD_D1,shift+1));
                LoPrice = MathMin(LoPrice,iLow(NULL,PERIOD_D1,shift+1));
                CloPrice = iClose(NULL,PERIOD_D1,shift+1);
        }

        Range = HiPrice-LoPrice;

        DrawFibo();

        return(0);
 }
//+------------------------------------------------------------------+


hello everyone,,,

can you help me about your indicator?
First of all, thank you for making this indicator.
In this indicator, it only shows a single day. it does not show the past days. can you do it if possible? for example, I want to see the last 1 year, it does not work.
 
Baris Kesgin:

hello everyone,,,

can you help me about your indicator?
First of all, thank you for making this indicator.
In this indicator, it only shows a single day. it does not show the past days. can you do it if possible? for example, I want to see the last 1 year, it does not work.

this code is written to draw the fibo for the last day only

you can use a loop to go through the previous candles for drawing previous fibos

and use unique names for each fibos, so they will not be deleted by same object names

 

You should be in the MT4 section with MT4 code

this indicator is MT5 and it will draw fibo lines on all days without the fib object:

https://www.mql5.com/en/forum/473494

Indicators: PTB
Indicators: PTB
  • 2024.09.22
  • Automated-Trading
  • www.mql5.com
Articles, Library comments: Indicators: PTB