I can't get ideea where I'm wrong - Fibonacci tool follower

 
Hi, could someone give a hand of help?

I;m trying code a EA for MT4 .

The EA checks if the Fibonacci Retracements tool exists on the open chart of the trading instrument. If it exists, the EA reads the price value corresponding to Level 0 and the price value corresponding to Level 1 in the Fibo. It stores these values. The value of Level 1 is permanent and does not change.

If the price value corresponding to Level 0 increases, then automatically adjusts the fibo tool accordingly with the price.

If the value of Level 0 decreases, it holds the fibo tool at the highest price recorded before the fall, in which case the fibo ratios will not change.

I use the code:
<


/>



#property copyright "Mesterica"

#property link      "mql5.com"

#property version   "1.00"

double Level0 = 0;

double Level1 = 0;

double highestPrice = 0;

int OnInit()

{

    // Check if the Fibonacci Retracements tool exists on the chart

    if (ObjectFind("Fibo") < 0)

    {

        Print("Fibonacci Retracements tool not found on chart.");

        return INIT_FAILED;

    }

    return INIT_SUCCEEDED;

}

void OnTick()

{

    // Get the price values corresponding to Level 0 and Level 1 in the Fibo

    Level0 = ObjectGetValueByShift("Fibo", 0, OBJPROP_PRICE1);

    Level1 = ObjectGetValueByShift("Fibo", 0, OBJPROP_PRICE2);

    // Store the highest price if Level 0 decreases

    if (Level0 < highestPrice)

    {

        highestPrice = Level0;

    }

    else if (Level0 > highestPrice)

    {

        // Update the fibo tool if the price value corresponding to Level 0 increases

        ObjectMove("Fibo", 0, TimeCurrent(), highestPrice, Level1);

    }

}



But after compiling I receive these errors: https://prnt.sc/oT4ikDLzzYbE


Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
1.png  40 kb
 
Mesterica:
Hi, could someone give a hand of help?

edit your post and use the code button to insert your code properly  </> or Alt-S  

don't use links to the errors put them in your post or attach them

 
Mesterica:
Hi, could someone give a hand of help?

I;m trying code a EA for MT4 .

The EA checks if the Fibonacci Retracements tool exists on the open chart of the trading instrument. If it exists, the EA reads the price value corresponding to Level 0 and the price value corresponding to Level 1 in the Fibo. It stores these values. The value of Level 1 is permanent and does not change.

If the price value corresponding to Level 0 increases, then automatically adjusts the fibo tool accordingly with the price.

If the value of Level 0 decreases, it holds the fibo tool at the highest price recorded before the fall, in which case the fibo ratios will not change.

I use the code:
<


/>




But after compiling I receive these errors: https://prnt.sc/oT4ikDLzzYbE


Hello . 

You don't need to use GetValueByShift for fibonacci as the lines are horizontal and dont change 

Here is an example that reads all the fibo lines on the chart , their price and their ratio .

Specific to your issue , to get the prices use these :

  double onePrice=ObjectGetDouble(ChartID(),sparam,OBJPROP_PRICE,0);//get   100% retracement price
  double zeroPrice=ObjectGetDouble(ChartID(),sparam,OBJPROP_PRICE,1);//get 0% retracement price

Then the fibo offers the ratio of each level which can help you project the price of any level the user has active 

int total_levels=(int)ObjectGetInteger(ChartID(),sparam,OBJPROP_LEVELS);
  double onePrice=ObjectGetDouble(ChartID(),sparam,OBJPROP_PRICE,0);//get   100% retracement price
  double zeroPrice=ObjectGetDouble(ChartID(),sparam,OBJPROP_PRICE,1);//get 0% retracement price
  double range=onePrice-zeroPrice;
  for(int i=0;i<total_levels;i++)
     {
     double value=ObjectGetDouble(ChartID(),sparam,OBJPROP_LEVELVALUE,i);//ratio
     double price=zeroPrice+range*value;
     }

The example in full code for testing :

fibonacci object line values   

#property copyright "Read the discussion"
#property link      "https://www.mql5.com/en/forum/441057"
#property strict

int OnInit()
  {
//--- create timer
  // EventSetTimer(60);
  ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true);
//---
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
  }

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
  if(id==CHARTEVENT_OBJECT_CREATE){
  if(ObjectGetInteger(ChartID(),sparam,OBJPROP_TYPE)==OBJ_FIBO){
  int total_levels=(int)ObjectGetInteger(ChartID(),sparam,OBJPROP_LEVELS);
  Print("Fibo spotted , "+IntegerToString(total_levels)+" levels");
  double onePrice=ObjectGetDouble(ChartID(),sparam,OBJPROP_PRICE,0);//get   100% retracement price
  double zeroPrice=ObjectGetDouble(ChartID(),sparam,OBJPROP_PRICE,1);//get 0% retracement price
  double range=onePrice-zeroPrice;
  for(int i=0;i<total_levels;i++)
     {
     double value=ObjectGetDouble(ChartID(),sparam,OBJPROP_LEVELVALUE,i);
     double price=zeroPrice+range*value;
     Print("Level["+IntegerToString(i)+"] :: "+DoubleToString(value,2)+" :: "+DoubleToString(price,_Digits));
     }
  }}
  }
//+------------------------------------------------------------------+