Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy coss below Ray

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

    Strategy coss below Ray

    Hello, i want code in my strategy that if the price crossBelow a Ray then my longposition should be closed.

    i can draw the Ray but i know not the code to close the position if the price crosses down the ray .
    myRay = Draw.Ray(this, Close[0].ToString() + @" Ray_1", false, 6, (Low[0] - 0.1) , 0, Low[0], Brushes.Red, DashStyleHelper.Solid, 2);

    if ( (CrossBelow(Close, myRay, 0)))
    {

    ExitLong(Convert.ToInt32(DefaultQuantity), "", ""); // exit longposition
    }
    The code in red is wrong because i dont know the righr code for this action .

    #2
    Hello aktrader,

    Thank you for your note.

    You are checking if the price crossed myRay, however I see no such variable or object defined.

    I would suggest defining myRay as a variable, for example,

    double myRay = 50.50;

    That would be the static price of 50.50, since you are using a ray, it would be more complicated as their is a slope between point 1 and point 2, on each bar the price level changes. For example, I might use slope to find the slope value of the ray, which would be the change between point 1 and 2. Then say the current bar is half way between the point of 1 and 2, say 5 bars, you would add the slope*5 to point 1, and assign this value to myRay. If you wanted to project slope into the future past point 2, you would add 1 slope value per each bar past point 2.

    Please see,




    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    66 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    141 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    76 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    47 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    51 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X