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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    41 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X