Draw Future Vertical Line

 

Hello,

I would like to draw a vertical line in the future , but I have problem because on some TF it' working fine but in other TF not.

Also I see that changing the Symbol my conversion does not work .


I attach my code. Can somebody help me ?


 
Fabio Butto:

Hello,

I would like to draw a vertical line in the future , but I have problem because on some TF it' working fine but in other TF not.

Also I see that changing the Symbol my conversion does not work .


I attach my code. Can somebody help me ?


Make sure that the time and price data you're using for your calculations ( High , Low , iClose , etc.) are correctly referenced and are consistent across different time frames and symbols. Any discrepancies in data may lead to incorrect positioning of your vertical lines. You're using a ConversionSeconds variable to adjust for different time frames, but the calculations seem to be based on time alone. Ensure that this factor adequately reflects the differences in time frames. For example, a 1-hour time frame may need a different conversion factor than a 5-minute time frame. Verify that the conditions under which you're drawing the vertical lines ( if (FutureBar >= iTime(NULL, 0, BarShiftHighest)) ) are correctly evaluated across different time frames and symbols. Ensure that the logic used to determine when to draw the line is consistent and appropriate. Ensure that your code properly handles changes in symbols. If your calculations or drawing logic rely on specific data from the current symbol, make sure it's updated accordingly when the symbol changes. You're using Comment() function calls to output debugging information. Utilize this to check the values of variables and conditions at different points in your code to identify any discrepancies or errors.

// Define global variables
double HighPrice;
double LowPrice;
int BarShiftHighest;
int BarShiftLowest;
int ConversionSeconds;
bool LinesDrawn = false;

// Define colors
color BuyVertColor = Lime;
color TrendLineUpColor = Lime;

// Initialization function
int init() {
    return(0);
}

// Deinitialization function
int deinit() {
    ObjectsDeleteAll(-1);
    return(0);
}

// Main iteration function
int start() {
    // Clear previously drawn objects if lines were not drawn yet
    if (!LinesDrawn) {
        ObjectsDeleteAll(-1);
    }

    // Find the highest and lowest prices within the chart
    BarShiftHighest = iHighest(NULL, 0, MODE_HIGH, Bars, 0);
    BarShiftLowest = iLowest(NULL, 0, MODE_LOW, Bars, 0);
    HighPrice = High[BarShiftHighest];
    LowPrice = Low[BarShiftLowest];

    // Calculate the conversion seconds based on the timeframe
    if (Period() == PERIOD_M5) {
        ConversionSeconds = 300;
    } else if (Period() == PERIOD_M15) {
        ConversionSeconds = 900;
    } else if (Period() == PERIOD_M30) {
        ConversionSeconds = 1800;
    } else if (Period() == PERIOD_H1) {
        ConversionSeconds = 3600;
    }

    // Calculate coordinates for drawing the lines
    datetime x1 = Time[BarShiftHighest];
    double y1 = HighPrice;
    datetime x2 = Time[BarShiftLowest];
    double y2 = LowPrice;

    // Draw vertical line
    if (!LinesDrawn) {
        ObjectCreate("VertLine", OBJ_VLINE, 0, x2, LowPrice, x2, HighPrice);
        ObjectSet("VertLine", OBJPROP_COLOR, BuyVertColor);
        ObjectSet("VertLine", OBJPROP_WIDTH, 2);
    }

    // Draw trend line
    if (!LinesDrawn) {
        ObjectCreate("TrendLineUp", OBJ_TREND, 0, x1, y1, x2, y2);
        ObjectSet("TrendLineUp", OBJPROP_COLOR, TrendLineUpColor);
        ObjectSet("TrendLineUp", OBJPROP_WIDTH, 2);
    }

    // Set the flag indicating that lines have been drawn
    LinesDrawn = true;

    return(0);
}
I've adjusted the logic for calculating coordinates to ensure that it's based on the highest and lowest prices within the chart, rather than a specific window. The conversion seconds are calculated based on the timeframe, ensuring consistency across different timeframes. Lines are drawn only if they haven't been drawn before, preventing duplicates, so you can check if you can manage with it this way.
 
Nardus Van Staden #:

Make sure that the time and price data you're using for your calculations ( High , Low , iClose , etc.) are correctly referenced and are consistent across different time frames and symbols. Any discrepancies in data may lead to incorrect positioning of your vertical lines. You're using a ConversionSeconds variable to adjust for different time frames, but the calculations seem to be based on time alone. Ensure that this factor adequately reflects the differences in time frames. For example, a 1-hour time frame may need a different conversion factor than a 5-minute time frame. Verify that the conditions under which you're drawing the vertical lines ( if (FutureBar >= iTime(NULL, 0, BarShiftHighest)) ) are correctly evaluated across different time frames and symbols. Ensure that the logic used to determine when to draw the line is consistent and appropriate. Ensure that your code properly handles changes in symbols. If your calculations or drawing logic rely on specific data from the current symbol, make sure it's updated accordingly when the symbol changes. You're using Comment() function calls to output debugging information. Utilize this to check the values of variables and conditions at different points in your code to identify any discrepancies or errors.

I've adjusted the logic for calculating coordinates to ensure that it's based on the highest and lowest prices within the chart, rather than a specific window. The conversion seconds are calculated based on the timeframe, ensuring consistency across different timeframes. Lines are drawn only if they haven't been drawn before, preventing duplicates, so you can check if you can manage with it this way.

Hello Nardus,

first of all I want to thank you for your suggestions.

Your code is straightforward but It does not fulfill what I want :-(

As you see in my drawing I want to draw a vertical line in the future at cross of the trend line with the highest of the range (the 100 of fibo line).

See the calculation of the trend line equation (polar coordinate) and the intersection with the highest of the range.


Can you help me ? 

 
Fabio Butto:

Hello,

I would like to draw a vertical line in the future , but I have problem because on some TF it' working fine but in other TF not.

Also I see that changing the Symbol my conversion does not work .


I attach my code. Can somebody help me ?


Can somebody help me ?

 
Fabio Butto #:

Hello Nardus,

first of all I want to thank you for your suggestions.

Your code is straightforward but It does not fulfill what I want :-(

As you see in my drawing I want to draw a vertical line in the future at cross of the trend line with the highest of the range (the 100 of fibo line).

See the calculation of the trend line equation (polar coordinate) and the intersection with the highest of the range.


Can you help me ? 

Well there are 2 options, either you can code it yourself so it will match your needs using the Fibo, or you can go to the freelance section, create a job there and ask a dev to code it for you. The above example is a way for you to see the logic, and maybe change a few paprams to suit your needs. use it as a template if you will. You can always add, remove or change certain functions. I do not believe there is a dev on here that will do the whole code for free. We can give you some guidelines and thats about it.

 
Nardus Van Staden #:
The above example is a way for you to see the logic, and maybe change a few paprams to suit your needs

You generated your example using chatgpt. When you force generated codes on newbies, you are harming them and misleading them. Chatgpt (like any other AI at the moment) generates absolute nonsense for MQL. It can't even be called pseudocode.

 
Fabio Butto #:
As you see in my drawing I want to draw a vertical line in the future at cross of the trend line with the highest of the range (the 100 of fibo line).

Are you sure you need a vertical line located in the future? This is quite problematic due to the fact that some future bars will be missed (weekends for example).

It will be much easier to determine whether the trend line has crossed the fibonacci level on the current bar, rather than on a future bar. On the current bar or on any other formed one.