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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    71 views
    0 likes
    Last Post PaulMohn  
    Working...
    X