Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"C" language question... I think

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

    "C" language question... I think

    Sorry,

    This may be my lack of knowledge showing but I don't even know how to frame such a question to google or even ask in a "C" language forum elsewhere. I am trying to record basic OHLC info during every single retracement, only to capture the last high or low prior to a change in an basic indicator. However, I don't think I am passing the correct information or the correct information in the correct way. Please advise.

    Code:
    //Condition 1
    if (BarsInProgress != 0)
    RTHID = +1;
    RTHHID = +1;
    
    // Set 1
    if (((Close[1] > Open[1])     // If bar 1 is an up bar and bar 0 is a down bar
    && (Close[0] < Open[0])       // and close of bar 1 is higher than the variable which recorded the last close...
    && RTHC < Close[1]))
    {
    RTHC = Close[1];                      // Record new higher close            
    RTHH = High[HighestBar(High, 2)];     // Record highest high out of bar 1 and bar 2
    RTHID = 1;                             // Set index of up bar
    RTHHID = HighestBar(High, 2);        // Set index of which bar had the highest high


    If I add this to see what the script is doing:

    Code:
    Draw.ArrowDown(this, "S" + CurrentBar, true, RTHHID, RTHH + (4 * TickSize), Brushes.Yellow);​ // Then draw an arrow down 4 ticks above the high of the highest bar​
    It actually works at drawing an arrow over the highest bar between every simultaneous up and down bar. However, when I try to pass the index value of the bar that had the highest high (ie RTHHID) to a new variable in the following code, it appears to run the "HighestBar(High, 2)" script rather than give what I thought would be the returned index value​ of "HighestBar(High, 2)" recorded 5 or 10 bars ago in the variable "RTHHID".



    For instance, if I add:

    Code:
    if ((Slope(SMA1, 2, 1) > 0)     // If Slope changes from up to down
    && (Slope(SMA1, 1, 0) < 0))
    {
    //
    SHH1 = RTHH;     // Pass the previous Rtracement Highest to the new variable
    SHBarID1 = RTHHID;     // Pass index value of RTHHID into the new variable;
    
    }​
    Then, if I test it with the darw arrow function again with the newly created variables:


    Code:
    Draw.ArrowDown(this, "S" + CurrentBar, true, SHBarID1, SHH1+ (4 * TickSize), Brushes.Yellow);​ // Then draw an arrow down 4 ticks above the high of the highest bar​​
    It does not put the arrows in the same place but actually appears to run the "HighestBar(High, 2)" and places the arrow at the high of the current and previous bar at the slope change, even though the index of RTHHID should be 5 or 10 bars ago.



    Is there a way that RTHHID can be set to record the index of "HighestBar(High, 2)" that it can be passed to another variable later as the int index value of "HighestBar(High, 2)" from a previous condition that will not just be the script "HighestBar(High, 2)" being passed into the new variable.?

    Thank you,

    Sam
    Last edited by smcllr; 09-25-2022, 10:36 PM.

    #2
    Hi Sam, thanks for posting. It sounds like your variables are being updated on every bar, or at times when you are not expecting them to update. You can debug this by printing out your RTHHID variable. Setting this variable to RTHHID = HighestBar(High, 2); will probably change on every bar, but SHBarID1 = RTHHID; sets one value to another, so what I assume is happening is that your RTHHID variable is being set to HighestBar on every bar.

    Kind regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X