Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how do I look forward to check where price goes after I get a signal

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    how do I look forward to check where price goes after I get a signal

    I have an indicator that draws a vertical line on a chart when it meets my conditions for a good trade. You can see a couple examples in the attached image. I also plot my TP target and SL target.

    What I would like to do is look "forward" to see if the TP or SL is reached first to close the trade.

    I tried a for loop, starting at the next bar and going to the right looking for the closing bar. I limited it so it wouldn't run off the right edge of the chart.

    but when it got to the first bar on the right it stopped.

    is there any way to look forward to bars on the right of the chart?

    if not, I will have to look back from every bar to see if it closes an open trade, which would require a lot more code and processing power



    HTML Code:
    [PHP][/PHP]{
    DrawVerticalLine("Signal",Brushes.White,1);
    SLTarget[0] = Close[0] - 2 * ATR14[0];
    TPTarget[0] = Close[0] + 3 * ATR14[0];
    
    for(int i = CurrentBar + 1; i < ChartBars.Count; i++)
    {
    if(High[i] > TPTarget[0])
    {
    int TPBar = i;
    Print(CurrentBar + " " + ChartBars.Count);
    break;
    }
    }
    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

    #2
    Hello cre8able,

    To the script there is no "forward" or future, it processes each bar in order until it reaches realtime. You couldn't loop forward past the current bar because nothing exists yet past that point.

    What you are asking for could be achieved by using a variable. You could set a bool variable to true when the condition is true, then other conditions in the future could check if that bool is true or not.


    Please let me know if I may be of additional assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    590 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    342 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    555 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X