Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Return values

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

    #16
    I will come back to my first question , hopefully this time i can explain it better:
    I have a calculation in my code that gets me a value , let's say : If cross above then take current price minus 10 and store this value in a variable. Put a buy limit order at this value.
    The first time when is crossed above my code makes the calculation and put's a buy limit at the specified value. (current minus 10).
    On the next bar (or tick) current price is different and my buy limit order has a different value now. ( the new current price minus 10) .
    But i dont want that. I want to make the calculation first time when conditions are met , put my buy order at that value and keep it there with the same value until i say otherwise.

    protected override void OnBarUpdate()
    {
    if(State == State.Historical)
    {
    return;
    }
    //Add your custom strategy logic here.

    if( Position.MarketPosition == MarketPosition.Flat
    && EMA(12)[1] > EMA(26)[1])

    {
    LimitPrice = EMA(26)[0]; // or LimitPrice = Close[0] - 10
    EnterLongLimit(LimitPrice,"long");
    }

    Let's take the code above as an example. When the conditions are met and the code executes for the first time the LimitPrice has a value given by the slow EMA. I want to keep this value , the first value that goes into LimitPrice until i say otherwise (until ema fast is below ema slow let's say).
    I can't figure it out how to do that.

    Comment

    Latest Posts

    Collapse

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